mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-06 08:16:43 +00:00
fix(bedrock_httpx.py): handle empty stop string
This commit is contained in:
parent
6e8d2856b0
commit
526b196f83
2 changed files with 41 additions and 0 deletions
|
|
@ -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":
|
||||
|
|
|
|||
|
|
@ -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"}], ""],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue