diff --git a/litellm/llms/prompt_templates/factory.py b/litellm/llms/prompt_templates/factory.py index b23f1031510..abe340e7d10 100644 --- a/litellm/llms/prompt_templates/factory.py +++ b/litellm/llms/prompt_templates/factory.py @@ -604,13 +604,13 @@ def convert_to_anthropic_tool_result(message: dict) -> str: def convert_to_anthropic_tool_invoke(tool_calls: list) -> str: invokes = "" for tool in tool_calls: - if tool["type"] != "function": + if tool.type != "function": continue - tool_name = tool["function"]["name"] + tool_name = tool.function.name parameters = "".join( f"<{param}>{val}\n" - for param, val in json.loads(tool["function"]["arguments"]).items() + for param, val in json.loads(tool.function.arguments).items() ) invokes += ( "\n" diff --git a/litellm/utils.py b/litellm/utils.py index a8c0031812e..57327473d88 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -271,7 +271,10 @@ class Message(OpenAIObject): if tool_calls is not None: self.tool_calls = [] for tool_call in tool_calls: - self.tool_calls.append(ChatCompletionMessageToolCall(**tool_call)) + if isinstance(tool_call, dict): + self.tool_calls.append(ChatCompletionMessageToolCall(**tool_call)) + else: + self.tool_calls.append(tool_call) if logprobs is not None: self._logprobs = logprobs