From 7ca213e92f4257dc192e1ffe9641dfc1c0cefc14 Mon Sep 17 00:00:00 2001 From: Nilanjan De Date: Thu, 18 Apr 2024 15:12:31 +0400 Subject: [PATCH] update factory.py --- litellm/llms/prompt_templates/factory.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/litellm/llms/prompt_templates/factory.py b/litellm/llms/prompt_templates/factory.py index dbe27278e1..bbf87ca49f 100644 --- a/litellm/llms/prompt_templates/factory.py +++ b/litellm/llms/prompt_templates/factory.py @@ -619,10 +619,11 @@ def convert_to_anthropic_tool_invoke_xml(tool_calls: list) -> str: continue tool_function = get_attribute_or_key(tool,"function") - tool_name = tool_function["name"] + tool_name = get_attribute_or_key(tool_function, "name") + tool_arguments = get_attribute_or_key(tool_function, "arguments") parameters = "".join( f"<{param}>{val}\n" - for param, val in json.loads(tool_function["arguments"]).items() + for param, val in json.loads(tool_arguments).items() ) invokes += ( "\n" @@ -707,7 +708,7 @@ def anthropic_messages_pt_xml(messages: list): if assistant_content: new_messages.append({"role": "assistant", "content": assistant_content}) - if new_messages[0]["role"] != "user": + if not new_messages or new_messages[0]["role"] != "user": if litellm.modify_params: new_messages.insert( 0, {"role": "user", "content": [{"type": "text", "text": "."}]}