diff --git a/llama-index-integrations/llms/llama-index-llms-openai/llama_index/llms/openai/utils.py b/llama-index-integrations/llms/llama-index-llms-openai/llama_index/llms/openai/utils.py index 7fde73a16c8dd931521a5d298d4bcea8cca5a828..c36d57a776b592b13e8214f47742fa95c295d752 100644 --- a/llama-index-integrations/llms/llama-index-llms-openai/llama_index/llms/openai/utils.py +++ b/llama-index-integrations/llms/llama-index-llms-openai/llama_index/llms/openai/utils.py @@ -626,10 +626,19 @@ def update_tool_calls( # validations to get passed by mypy assert t.function is not None assert tc_delta.function is not None - assert t.function.arguments is not None - assert t.function.name is not None - assert t.id is not None + # Initialize fields if they're None + # OpenAI(or Compatible)'s streaming API can return partial tool call + # information across multiple chunks where some fields may be None in + # initial chunks and populated in subsequent ones + if t.function.arguments is None: + t.function.arguments = "" + if t.function.name is None: + t.function.name = "" + if t.id is None: + t.id = "" + + # Update with delta values t.function.arguments += tc_delta.function.arguments or "" t.function.name += tc_delta.function.name or "" t.id += tc_delta.id or "" diff --git a/llama-index-integrations/llms/llama-index-llms-openai/pyproject.toml b/llama-index-integrations/llms/llama-index-llms-openai/pyproject.toml index 572492a362bbda80f69768d38288640524d9a0d5..9e42ba647ade53fe60c06b8c8fad66630cc76d88 100644 --- a/llama-index-integrations/llms/llama-index-llms-openai/pyproject.toml +++ b/llama-index-integrations/llms/llama-index-llms-openai/pyproject.toml @@ -29,7 +29,7 @@ exclude = ["**/BUILD"] license = "MIT" name = "llama-index-llms-openai" readme = "README.md" -version = "0.3.21" +version = "0.3.22" [tool.poetry.dependencies] python = ">=3.9,<4.0"