@@ -178,6 +178,18 @@ def __init__(
178178 api_key = api_key if api_key is not None else "not-needed" ,
179179 )
180180
181+ def _chat_completion_kwargs (
182+ self , messages : list [dict [str , Any ]], ** kwargs : Any
183+ ) -> dict [str , Any ]:
184+ create_kwargs : dict [str , Any ] = {
185+ "model" : self .model ,
186+ "messages" : messages ,
187+ self ._tokens_param : kwargs .get ("max_tokens" , self .max_tokens ),
188+ }
189+ if not self ._omit_temperature :
190+ create_kwargs ["temperature" ] = kwargs .get ("temperature" , self .temperature )
191+ return create_kwargs
192+
181193 async def complete (self , prompt : str , ** kwargs ) -> str :
182194 """Send a chat completion request.
183195
@@ -195,13 +207,7 @@ async def complete(self, prompt: str, **kwargs) -> str:
195207 messages .append ({"role" : "system" , "content" : self .system_prompt })
196208 messages .append ({"role" : "user" , "content" : prompt })
197209
198- call_kwargs : dict [str , Any ] = {
199- "model" : self .model ,
200- "messages" : messages ,
201- self ._tokens_param : kwargs .get ("max_tokens" , self .max_tokens ),
202- }
203- if not self ._omit_temperature :
204- call_kwargs ["temperature" ] = kwargs .get ("temperature" , self .temperature )
210+ call_kwargs = self ._chat_completion_kwargs (messages , ** kwargs )
205211 response = await self ._client .chat .completions .create (** call_kwargs )
206212 return response .choices [0 ].message .content or ""
207213
@@ -211,13 +217,7 @@ async def complete_with_tools(
211217 tools : list [dict [str , Any ]],
212218 ** kwargs : Any ,
213219 ) -> LLMResponse :
214- create_kwargs : dict [str , Any ] = {
215- "model" : self .model ,
216- "messages" : messages ,
217- self ._tokens_param : kwargs .get ("max_tokens" , self .max_tokens ),
218- }
219- if not self ._omit_temperature :
220- create_kwargs ["temperature" ] = kwargs .get ("temperature" , self .temperature )
220+ create_kwargs = self ._chat_completion_kwargs (messages , ** kwargs )
221221 openai_tools = _mcp_tools_to_openai (tools )
222222 if openai_tools :
223223 create_kwargs ["tools" ] = openai_tools
0 commit comments