This commit is contained in:
dfedoryshchev 2026-11-04 02:00:36 +00:00 • committed by GitHub
commit fe3fdd2c08
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View file

@ -101,10 +101,10 @@ class AmazonMistralConfig(AmazonInvokeConfig, BaseConfig):
A string with the response of the LLM
"""
if "choices" in completion_response:
if "choices" in completion_response and completion_response["choices"] != []:
outputText = completion_response["choices"][0]["message"]["content"]
model_response.choices[0].finish_reason = completion_response["choices"][0]["finish_reason"]
elif "outputs" in completion_response:
elif "outputs" in completion_response and completion_response["outputs"] != []:
outputText = completion_response["outputs"][0]["text"]
model_response.choices[0].finish_reason = completion_response["outputs"][0]["stop_reason"]
else:

View file

@ -10,6 +10,7 @@ from litellm.llms.custom_httpx.http_handler import HTTPHandler
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
@ -41,6 +42,20 @@ def test_mistral_get_outputText():
assert model_response.choices[0].finish_reason == "finish"
def test_mistral_get_outputText_empty_choices() -> None:
model_response: Final = ModelResponse()
with pytest.raises(BedrockError):
AmazonMistralConfig.get_outputText(completion_response={"choices": []}, model_response=model_response)
def test_mistral_get_outputText_empty_outputs() -> None:
model_response: Final = ModelResponse()
with pytest.raises(BedrockError):
AmazonMistralConfig.get_outputText(completion_response={"outputs": []}, model_response=model_response)
@pytest.mark.respx(assert_all_called=True)
def test_mistral_invoke_outputs_become_message_content(respx_mock: respx.Router) -> None:
route: Final = respx_mock.post(