@@ -138,13 +138,24 @@ def test_stream_preserves_single_pass_tools(client: OpenAI, respx2_mock: MockRou
138138 assert_request_and_parsed_tool (respx2_mock , tool_calls [0 ].function .parsed_arguments )
139139
140140
141- def test_stream_rejects_non_strict_tools (client : OpenAI ) -> None :
142- with pytest .raises (ValueError , match = "Only `strict` function tools can be auto-parsed" ):
143- client .chat .completions .stream (
144- model = "gpt-test" ,
145- messages = [{"role" : "user" , "content" : "weather" }],
146- tools = non_strict_tools (),
147- )
141+ @pytest .mark .respx2 (base_url = base_url )
142+ def test_stream_preserves_non_strict_single_pass_tools (client : OpenAI , respx2_mock : MockRouter ) -> None :
143+ respx2_mock .post ("/chat/completions" ).mock (
144+ return_value = httpx2 .Response (200 , text = STREAM_RESPONSE , headers = {"content-type" : "text/event-stream" })
145+ )
146+
147+ with client .chat .completions .stream (
148+ model = "gpt-test" ,
149+ messages = [{"role" : "user" , "content" : "weather" }],
150+ tools = non_strict_tools (),
151+ ) as stream :
152+ completion = stream .get_final_completion ()
153+
154+ tool_calls = completion .choices [0 ].message .tool_calls
155+ assert tool_calls is not None
156+ body = json .loads (cast ("list[MockRequestCall]" , respx2_mock .calls )[0 ].request .content )
157+ assert body ["tools" ] == list (non_strict_tools ())
158+ assert tool_calls [0 ].function .parsed_arguments is None
148159
149160
150161@pytest .mark .respx2 (base_url = base_url )
0 commit comments