mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
fix(bedrock): guard empty choices in mistral get_outputText
This commit is contained in:
parent
b9b27c2beb
commit
c586769898
2 changed files with 13 additions and 1 deletions
|
|
@ -99,7 +99,7 @@ class AmazonMistralConfig(AmazonInvokeConfig, BaseConfig):
|
|||
A string with the response of the LLM
|
||||
|
||||
"""
|
||||
if "choices" in completion_response:
|
||||
if "choices" in completion_response and len(completion_response["choices"]) > 0:
|
||||
outputText = completion_response["choices"][0]["message"]["content"]
|
||||
model_response.choices[0].finish_reason = completion_response["choices"][0]["finish_reason"]
|
||||
elif "outputs" in completion_response:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import pytest
|
||||
|
||||
from litellm.llms.bedrock.chat.invoke_transformations.amazon_mistral_transformation import (
|
||||
AmazonMistralConfig,
|
||||
)
|
||||
from litellm.llms.bedrock.common_utils import BedrockError
|
||||
from litellm.types.utils import ModelResponse
|
||||
|
||||
|
||||
|
|
@ -30,3 +33,12 @@ def test_mistral_get_outputText():
|
|||
|
||||
assert outputText == "Hi!"
|
||||
assert model_response.choices[0].finish_reason == "finish"
|
||||
|
||||
|
||||
def test_mistral_get_outputText_empty_choices():
|
||||
model_response = ModelResponse()
|
||||
|
||||
with pytest.raises(BedrockError):
|
||||
AmazonMistralConfig.get_outputText(
|
||||
completion_response={"choices": []}, model_response=model_response
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue