@@ -290,30 +290,39 @@ async def _fetch_response(
290290
291291 stream_param : Literal [True ] | Omit = True if stream else omit
292292
293- ret = await self ._get_client ().chat .completions .create (
294- model = self .model ,
295- messages = converted_messages ,
296- tools = tools_param ,
297- temperature = self ._non_null_or_omit (model_settings .temperature ),
298- top_p = self ._non_null_or_omit (model_settings .top_p ),
299- frequency_penalty = self ._non_null_or_omit (model_settings .frequency_penalty ),
300- presence_penalty = self ._non_null_or_omit (model_settings .presence_penalty ),
301- max_tokens = self ._non_null_or_omit (model_settings .max_tokens ),
302- tool_choice = tool_choice ,
303- response_format = response_format ,
304- parallel_tool_calls = parallel_tool_calls ,
305- stream = cast (Any , stream_param ),
306- stream_options = self ._non_null_or_omit (stream_options ),
307- store = self ._non_null_or_omit (store ),
308- reasoning_effort = self ._non_null_or_omit (reasoning_effort ),
309- verbosity = self ._non_null_or_omit (model_settings .verbosity ),
310- top_logprobs = self ._non_null_or_omit (model_settings .top_logprobs ),
311- extra_headers = self ._merge_headers (model_settings ),
312- extra_query = model_settings .extra_query ,
313- extra_body = model_settings .extra_body ,
314- metadata = self ._non_null_or_omit (model_settings .metadata ),
315- ** (model_settings .extra_args or {}),
316- )
293+ request_kwargs : dict [str , Any ] = {
294+ "model" : self .model ,
295+ "messages" : converted_messages ,
296+ "tools" : tools_param ,
297+ "temperature" : self ._non_null_or_omit (model_settings .temperature ),
298+ "top_p" : self ._non_null_or_omit (model_settings .top_p ),
299+ "frequency_penalty" : self ._non_null_or_omit (model_settings .frequency_penalty ),
300+ "presence_penalty" : self ._non_null_or_omit (model_settings .presence_penalty ),
301+ "max_tokens" : self ._non_null_or_omit (model_settings .max_tokens ),
302+ "tool_choice" : tool_choice ,
303+ "response_format" : response_format ,
304+ "parallel_tool_calls" : parallel_tool_calls ,
305+ "stream" : cast (Any , stream_param ),
306+ "stream_options" : self ._non_null_or_omit (stream_options ),
307+ "store" : self ._non_null_or_omit (store ),
308+ "reasoning_effort" : self ._non_null_or_omit (reasoning_effort ),
309+ "verbosity" : self ._non_null_or_omit (model_settings .verbosity ),
310+ "top_logprobs" : self ._non_null_or_omit (model_settings .top_logprobs ),
311+ "extra_headers" : self ._merge_headers (model_settings ),
312+ "extra_query" : model_settings .extra_query ,
313+ "extra_body" : model_settings .extra_body ,
314+ "metadata" : self ._non_null_or_omit (model_settings .metadata ),
315+ }
316+
317+ request_kwargs .update (model_settings .extra_args or {})
318+
319+ sanitized_kwargs = {
320+ key : value
321+ for key , value in request_kwargs .items ()
322+ if not isinstance (value , Omit ) and value is not omit
323+ }
324+
325+ ret = await self ._get_client ().chat .completions .create (** sanitized_kwargs )
317326
318327 if isinstance (ret , ChatCompletion ):
319328 return ret
0 commit comments