From 016c63102b5bd4ef59efae9d8a70091e870cd161 Mon Sep 17 00:00:00 2001 From: Dave DeCaprio Date: Mon, 18 Nov 2024 17:15:26 -0600 Subject: [PATCH 1/2] Fixed #6797 Fireworks AI structured outputs --- .../llms/fireworks_ai/chat/fireworks_ai_transformation.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/litellm/llms/fireworks_ai/chat/fireworks_ai_transformation.py b/litellm/llms/fireworks_ai/chat/fireworks_ai_transformation.py index 4d5b2d6eb3ba..66943430e030 100644 --- a/litellm/llms/fireworks_ai/chat/fireworks_ai_transformation.py +++ b/litellm/llms/fireworks_ai/chat/fireworks_ai_transformation.py @@ -105,6 +105,11 @@ def map_openai_params( else: # pass through the value of tool choice optional_params["tool_choice"] = value + elif param == "response_format" and value.get("type", None) == "json_schema": + optional_params["response_format"] = { + "type": "json_object", + "schema": value['json_schema']['schema'], + } elif param == "max_completion_tokens": optional_params["max_tokens"] = value elif param in supported_openai_params: From 352e3d4e17f105ea33552ef60c6da0e16a99627c Mon Sep 17 00:00:00 2001 From: Dave DeCaprio Date: Tue, 19 Nov 2024 09:23:47 -0600 Subject: [PATCH 2/2] Added test for fireworks.ai response_format --- .../test_fireworks_ai_translation.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/llm_translation/test_fireworks_ai_translation.py b/tests/llm_translation/test_fireworks_ai_translation.py index 00361cd183be..d2ca7f53c56d 100644 --- a/tests/llm_translation/test_fireworks_ai_translation.py +++ b/tests/llm_translation/test_fireworks_ai_translation.py @@ -30,3 +30,41 @@ def test_map_openai_params_tool_choice(): # Test case 4: tool_choice is None result = fireworks.map_openai_params({"tool_choice": None}, {}, "some_model") assert result == {"tool_choice": None} + + +def test_map_response_format(): + response_format = { + 'type': 'json_schema', + 'json_schema': { + 'schema': { + 'properties': { + 'result': { + 'type': 'boolean' + } + }, + 'required': [ + 'result' + ], + 'type': 'object', + }, + 'name': 'BooleanResponse', + 'strict': True + } + } + result = fireworks.map_openai_params({"response_format":response_format}, {}, "some_model") + assert result == { + "response_format" : { + 'type': 'json_object', + 'schema': { + 'properties': { + 'result': { + 'type': 'boolean' + } + }, + 'required': [ + 'result' + ], + 'type': 'object', + }, + } + } \ No newline at end of file