Skip to content

Commit 049915c

Browse files
test: mock fireworks ai test - unstable api
1 parent 55546f4 commit 049915c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/llm_translation/test_fireworks_ai_translation.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,57 @@ def test_multilingual_requests(self):
9393
"""
9494
pass
9595

96+
@pytest.mark.parametrize(
97+
"response_format",
98+
[
99+
{"type": "json_object"},
100+
{"type": "text"},
101+
],
102+
)
103+
@pytest.mark.flaky(retries=6, delay=1)
104+
def test_json_response_format(self, response_format):
105+
"""
106+
Test that the JSON response format is supported by the LLM API
107+
"""
108+
from litellm.utils import supports_response_schema
109+
from openai import OpenAI
110+
from unittest.mock import patch
111+
112+
client = OpenAI()
113+
114+
base_completion_call_args = self.get_base_completion_call_args()
115+
litellm.set_verbose = True
116+
117+
messages = [
118+
{
119+
"role": "system",
120+
"content": "Your output should be a JSON object with no additional properties. ",
121+
},
122+
{
123+
"role": "user",
124+
"content": "Respond with this in json. city=San Francisco, state=CA, weather=sunny, temp=60",
125+
},
126+
]
127+
128+
with patch.object(
129+
client.chat.completions.with_raw_response, "create"
130+
) as mock_post:
131+
response = self.completion_function(
132+
**base_completion_call_args,
133+
messages=messages,
134+
response_format=response_format,
135+
client=client,
136+
)
137+
138+
mock_post.assert_called_once()
139+
if response_format["type"] == "json_object":
140+
assert (
141+
mock_post.call_args.kwargs["response_format"]["type"]
142+
== "json_object"
143+
)
144+
else:
145+
assert mock_post.call_args.kwargs["response_format"]["type"] == "text"
146+
96147

97148
class TestFireworksAIAudioTranscription(BaseLLMAudioTranscriptionTest):
98149
def get_base_audio_transcription_call_args(self) -> dict:

0 commit comments

Comments
 (0)