@@ -334,8 +334,16 @@ class MySignature(dspy.Signature):
334334 adapter = dspy .JSONAdapter ()
335335 messages = adapter .format (MySignature , [], {"document" : document_wrapper })
336336
337- expected_doc1_content = {"type" : "document" , "source" : {"type" : "text" , "media_type" : "text/plain" , "data" : "Hello, world!" }, "citations" : {"enabled" : True }}
338- expected_doc2_content = {"type" : "document" , "source" : {"type" : "text" , "media_type" : "text/plain" , "data" : "Hello, world 2!" }, "citations" : {"enabled" : True }}
337+ expected_doc1_content = {
338+ "type" : "document" ,
339+ "source" : {"type" : "text" , "media_type" : "text/plain" , "data" : "Hello, world!" },
340+ "citations" : {"enabled" : True },
341+ }
342+ expected_doc2_content = {
343+ "type" : "document" ,
344+ "source" : {"type" : "text" , "media_type" : "text/plain" , "data" : "Hello, world 2!" },
345+ "citations" : {"enabled" : True },
346+ }
339347
340348 assert expected_doc1_content in messages [1 ]["content" ]
341349 assert expected_doc2_content in messages [1 ]["content" ]
@@ -643,6 +651,7 @@ class TestSignature(dspy.Signature):
643651 _ , second_call_kwargs = mock_completion .call_args_list [1 ]
644652 assert second_call_kwargs .get ("response_format" ) == {"type" : "json_object" }
645653
654+
646655def test_json_adapter_json_mode_no_structured_outputs ():
647656 class TestSignature (dspy .Signature ):
648657 question : str = dspy .InputField ()
@@ -651,11 +660,15 @@ class TestSignature(dspy.Signature):
651660 dspy .configure (lm = dspy .LM (model = "openai/gpt-4o" , cache = False ), adapter = dspy .JSONAdapter ())
652661 program = dspy .Predict (TestSignature )
653662
654- with mock .patch ("litellm.completion" ) as mock_completion , \
655- mock .patch ("litellm.get_supported_openai_params" ) as mock_get_supported_openai_params , \
656- mock .patch ("litellm.supports_response_schema" ) as mock_supports_response_schema :
663+ with (
664+ mock .patch ("litellm.completion" ) as mock_completion ,
665+ mock .patch ("litellm.get_supported_openai_params" ) as mock_get_supported_openai_params ,
666+ mock .patch ("litellm.supports_response_schema" ) as mock_supports_response_schema ,
667+ ):
657668 # Call a model that allows json but not structured outputs
658- mock_completion .return_value = ModelResponse (choices = [Choices (message = Message (content = "{'answer': 'Test output'}" ))])
669+ mock_completion .return_value = ModelResponse (
670+ choices = [Choices (message = Message (content = "{'answer': 'Test output'}" ))]
671+ )
659672 mock_get_supported_openai_params .return_value = ["response_format" ]
660673 mock_supports_response_schema .return_value = False
661674
@@ -676,11 +689,15 @@ class TestSignature(dspy.Signature):
676689
677690 program = dspy .Predict (TestSignature )
678691
679- with mock .patch ("litellm.acompletion" ) as mock_acompletion , \
680- mock .patch ("litellm.get_supported_openai_params" ) as mock_get_supported_openai_params , \
681- mock .patch ("litellm.supports_response_schema" ) as mock_supports_response_schema :
692+ with (
693+ mock .patch ("litellm.acompletion" ) as mock_acompletion ,
694+ mock .patch ("litellm.get_supported_openai_params" ) as mock_get_supported_openai_params ,
695+ mock .patch ("litellm.supports_response_schema" ) as mock_supports_response_schema ,
696+ ):
682697 # Call a model that allows json but not structured outputs
683- mock_acompletion .return_value = ModelResponse (choices = [Choices (message = Message (content = "{'answer': 'Test output'}" ))])
698+ mock_acompletion .return_value = ModelResponse (
699+ choices = [Choices (message = Message (content = "{'answer': 'Test output'}" ))]
700+ )
684701 mock_get_supported_openai_params .return_value = ["response_format" ]
685702 mock_supports_response_schema .return_value = False
686703
@@ -890,9 +907,7 @@ class TestSignature(dspy.Signature):
890907 "type" : "message" ,
891908 "role" : "assistant" ,
892909 "status" : "completed" ,
893- "content" : [
894- {"type" : "output_text" , "text" : '{"answer": "Washington, D.C."}' , "annotations" : []}
895- ],
910+ "content" : [{"type" : "output_text" , "text" : '{"answer": "Washington, D.C."}' , "annotations" : []}],
896911 },
897912 ),
898913 ],
0 commit comments