From 539025010da4776ac1cf63692bbe7d17967041a6 Mon Sep 17 00:00:00 2001 From: Logan Date: Sun, 15 Dec 2024 16:53:48 -0600 Subject: [PATCH] Do not send blank content to anthropic (#17278) --- .../llama_index/llms/anthropic/utils.py | 5 ++++- .../llms/llama-index-llms-anthropic/pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/llama-index-integrations/llms/llama-index-llms-anthropic/llama_index/llms/anthropic/utils.py b/llama-index-integrations/llms/llama-index-llms-anthropic/llama_index/llms/anthropic/utils.py index 202874c0e3f8f..dd1e906c43243 100644 --- a/llama-index-integrations/llms/llama-index-llms-anthropic/llama_index/llms/anthropic/utils.py +++ b/llama-index-integrations/llms/llama-index-llms-anthropic/llama_index/llms/anthropic/utils.py @@ -166,7 +166,10 @@ def messages_to_anthropic_messages( if "cache_control" in message.additional_kwargs else TextBlockParam(text=block.text, type="text") ) - content.append(content_) + + # avoid empty text blocks + if content_["text"]: + content.append(content_) elif isinstance(block, ImageBlock): # FUTURE: Claude does not support URLs, so we need to always convert to base64 img_bytes = block.resolve_image(as_base64=True).read() diff --git a/llama-index-integrations/llms/llama-index-llms-anthropic/pyproject.toml b/llama-index-integrations/llms/llama-index-llms-anthropic/pyproject.toml index 5ada78ac87def..9756e0e500716 100644 --- a/llama-index-integrations/llms/llama-index-llms-anthropic/pyproject.toml +++ b/llama-index-integrations/llms/llama-index-llms-anthropic/pyproject.toml @@ -27,7 +27,7 @@ exclude = ["**/BUILD"] license = "MIT" name = "llama-index-llms-anthropic" readme = "README.md" -version = "0.6.0" +version = "0.6.1" [tool.poetry.dependencies] python = ">=3.9,<4.0"