mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
Merge pull request #3328 from BerriAI/revert-2780-fix-anthropic-messages-api
Revert "Fix Anthropic Messages Prompt Template function to add a third condition: list of text-content dictionaries"
This commit is contained in:
commit
a76e40df73
2 changed files with 3 additions and 51 deletions
|
@ -748,15 +748,9 @@ def anthropic_messages_pt_xml(messages: list):
|
||||||
assistant_content = []
|
assistant_content = []
|
||||||
## MERGE CONSECUTIVE ASSISTANT CONTENT ##
|
## MERGE CONSECUTIVE ASSISTANT CONTENT ##
|
||||||
while msg_i < len(messages) and messages[msg_i]["role"] == "assistant":
|
while msg_i < len(messages) and messages[msg_i]["role"] == "assistant":
|
||||||
# Handle assistant messages as string, none, or list of text-content dictionaries.
|
assistant_text = (
|
||||||
if isinstance(messages[msg_i].get("content"), list):
|
messages[msg_i].get("content") or ""
|
||||||
assistant_text = ''
|
) # either string or none
|
||||||
for content in messages[msg_i]["content"]:
|
|
||||||
if content.get("type") == "text":
|
|
||||||
assistant_text += content["text"]
|
|
||||||
else:
|
|
||||||
assistant_text = messages[msg_i].get("content") or ""
|
|
||||||
|
|
||||||
if messages[msg_i].get(
|
if messages[msg_i].get(
|
||||||
"tool_calls", []
|
"tool_calls", []
|
||||||
): # support assistant tool invoke convertion
|
): # support assistant tool invoke convertion
|
||||||
|
|
|
@ -230,48 +230,6 @@ def test_completion_claude_3_function_call():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pytest.fail(f"Error occurred: {e}")
|
pytest.fail(f"Error occurred: {e}")
|
||||||
|
|
||||||
def test_completion_claude_3_with_text_content_dictionaries():
|
|
||||||
litellm.set_verbose = True
|
|
||||||
messages = [
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"content": [
|
|
||||||
{
|
|
||||||
"type": "text",
|
|
||||||
"text": "Hello"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "assistant",
|
|
||||||
"content": [
|
|
||||||
{
|
|
||||||
"type": "text",
|
|
||||||
"text": "Hello! How can I assist you today?"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"content": [
|
|
||||||
{
|
|
||||||
"type": "text",
|
|
||||||
"text": "Hello again!"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
try:
|
|
||||||
# test without max tokens
|
|
||||||
response = completion(
|
|
||||||
model="anthropic/claude-3-opus-20240229",
|
|
||||||
messages=messages,
|
|
||||||
)
|
|
||||||
# Add any assertions, here to check response args
|
|
||||||
print(response)
|
|
||||||
except Exception as e:
|
|
||||||
pytest.fail(f"Error occurred: {e}")
|
|
||||||
|
|
||||||
def test_parse_xml_params():
|
def test_parse_xml_params():
|
||||||
from litellm.llms.prompt_templates.factory import parse_xml_params
|
from litellm.llms.prompt_templates.factory import parse_xml_params
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue