From 526b196f837c050df261b4c767dbecccd203f36b Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Tue, 13 Aug 2024 07:30:30 -0700 Subject: [PATCH] fix(bedrock_httpx.py): handle empty stop string --- litellm/llms/bedrock_httpx.py | 2 ++ litellm/tests/test_bedrock_completion.py | 39 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/litellm/llms/bedrock_httpx.py b/litellm/llms/bedrock_httpx.py index 64d57744202..3434371f6ee 100644 --- a/litellm/llms/bedrock_httpx.py +++ b/litellm/llms/bedrock_httpx.py @@ -1394,6 +1394,8 @@ class AmazonConverseConfig: optional_params["stream"] = value if param == "stop": if isinstance(value, str): + if len(value) == 0: # converse raises error for empty strings + continue value = [value] optional_params["stop_sequences"] = value if param == "temperature": diff --git a/litellm/tests/test_bedrock_completion.py b/litellm/tests/test_bedrock_completion.py index 3937cada8bd..5f49bbd2c6c 100644 --- a/litellm/tests/test_bedrock_completion.py +++ b/litellm/tests/test_bedrock_completion.py @@ -636,6 +636,45 @@ def test_bedrock_claude_3(image_url): pytest.fail(f"Error occurred: {e}") +@pytest.mark.parametrize( + "stop", + [""], +) +@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_stop_value(stop, model): + try: + litellm.set_verbose = True + data = { + "max_tokens": 100, + "stream": False, + "temperature": 0.3, + "messages": [ + {"role": "user", "content": "hey, how's it going?"}, + ], + "stop": stop, + } + response: ModelResponse = completion( + model="bedrock/{}".format(model), + **data, + ) # type: ignore + # Add any assertions here to check the response + assert len(response.choices) > 0 + assert len(response.choices[0].message.content) > 0 + + except RateLimitError: + pass + except Exception as e: + pytest.fail(f"Error occurred: {e}") + + @pytest.mark.parametrize( "system", ["You are an AI", [{"type": "text", "text": "You are an AI"}], ""],