diff --git a/litellm/llms/prompt_templates/factory.py b/litellm/llms/prompt_templates/factory.py index d02084d74..b34ddeb7e 100644 --- a/litellm/llms/prompt_templates/factory.py +++ b/litellm/llms/prompt_templates/factory.py @@ -2393,7 +2393,16 @@ def custom_prompt( if role in role_dict and "post_message" in role_dict[role] else "" ) - prompt += pre_message_str + message["content"] + post_message_str + if isinstance(message["content"], str): + prompt += pre_message_str + message["content"] + post_message_str + elif isinstance(message["content"], list): + text_str = "" + for content in message["content"]: + if content.get("text", None) is not None and isinstance( + content["text"], str + ): + text_str += content["text"] + prompt += pre_message_str + text_str + post_message_str if role == "assistant": prompt += eos_token diff --git a/litellm/tests/test_bedrock_completion.py b/litellm/tests/test_bedrock_completion.py index 2d7eb10d4..3ae5af81b 100644 --- a/litellm/tests/test_bedrock_completion.py +++ b/litellm/tests/test_bedrock_completion.py @@ -599,9 +599,19 @@ def test_bedrock_claude_3(image_url): @pytest.mark.parametrize( - "system", ["You are an AI", [{"type": "text", "text": "You are an AI"}]] + "system", + ["You are an AI", [{"type": "text", "text": "You are an AI"}]], ) -def test_bedrock_claude_3_system_prompt(system): +@pytest.mark.parametrize( + "model", + [ + "anthropic.claude-3-sonnet-20240229-v1:0", + "meta.llama3-70b-instruct-v1:0", + "anthropic.claude-v2", + "mistral.mixtral-8x7b-instruct-v0:1", + ], +) +def test_bedrock_system_prompt(system, model): try: litellm.set_verbose = True data = { @@ -614,7 +624,7 @@ def test_bedrock_claude_3_system_prompt(system): ], } response: ModelResponse = completion( - model="bedrock/anthropic.claude-3-sonnet-20240229-v1:0", + model="bedrock/{}".format(model), **data, ) # type: ignore # Add any assertions here to check the response