@@ -139,11 +139,15 @@ def _convert_tools(tools: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
139139 for tool in tools :
140140 if tool .get ("type" ) == "function" :
141141 func = tool ["function" ]
142- converted .append ({
143- "name" : func ["name" ],
144- "description" : func .get ("description" , "" ),
145- "input_schema" : func .get ("parameters" , {"type" : "object" , "properties" : {}}),
146- })
142+ converted .append (
143+ {
144+ "name" : func ["name" ],
145+ "description" : func .get ("description" , "" ),
146+ "input_schema" : func .get (
147+ "parameters" , {"type" : "object" , "properties" : {}}
148+ ),
149+ }
150+ )
147151 elif "name" in tool :
148152 # Already in Anthropic format
149153 converted .append (tool )
@@ -188,13 +192,22 @@ def _call_with_retry(self, func, *args, **kwargs) -> Any:
188192 raise last_error # type: ignore[misc]
189193
190194 def _build_request_kwargs (
191- self , messages : List [Dict [str , Any ]], model : str ,
192- tools : Optional [List [Dict [str , Any ]]], timeout : float , temperature : float ,
195+ self ,
196+ messages : List [Dict [str , Any ]],
197+ model : str ,
198+ tools : Optional [List [Dict [str , Any ]]],
199+ timeout : float ,
200+ temperature : float ,
193201 ) -> Dict [str , Any ]:
194202 """Build the Anthropic Messages API request kwargs."""
195203 system_text , user_messages = self ._extract_system (messages )
196204 converted = self ._convert_messages (user_messages )
197- kwargs : Dict [str , Any ] = {"model" : model , "messages" : converted , "max_tokens" : 4096 , "temperature" : temperature }
205+ kwargs : Dict [str , Any ] = {
206+ "model" : model ,
207+ "messages" : converted ,
208+ "max_tokens" : 4096 ,
209+ "temperature" : temperature ,
210+ }
198211 if system_text :
199212 kwargs ["system" ] = system_text
200213 if tools :
@@ -228,7 +241,12 @@ def _do_create():
228241 response = self ._call_with_retry (_do_create )
229242 result = self ._response_to_ollama_format (response )
230243 usage = response .usage
231- logger .debug ("Claude response: model=%s, input_tokens=%d, output_tokens=%d" , model , usage .input_tokens , usage .output_tokens )
244+ logger .debug (
245+ "Claude response: model=%s, input_tokens=%d, output_tokens=%d" ,
246+ model ,
247+ usage .input_tokens ,
248+ usage .output_tokens ,
249+ )
232250 return result
233251
234252 @staticmethod
@@ -246,12 +264,14 @@ def _response_to_ollama_format(response) -> Dict[str, Any]:
246264 if block .type == "text" :
247265 content_text += block .text
248266 elif block .type == "tool_use" :
249- tool_calls .append ({
250- "function" : {
251- "name" : block .name ,
252- "arguments" : block .input ,
253- },
254- })
267+ tool_calls .append (
268+ {
269+ "function" : {
270+ "name" : block .name ,
271+ "arguments" : block .input ,
272+ },
273+ }
274+ )
255275
256276 result : Dict [str , Any ] = {
257277 "message" : {
@@ -267,9 +287,15 @@ def _response_to_ollama_format(response) -> Dict[str, Any]:
267287
268288 return result
269289
270- def _build_simple_kwargs (self , prompt : str , model : str , timeout : float , temperature : float , think : bool ) -> Dict [str , Any ]:
290+ def _build_simple_kwargs (
291+ self , prompt : str , model : str , timeout : float , temperature : float , think : bool
292+ ) -> Dict [str , Any ]:
271293 """Build request kwargs for generate_simple."""
272- kwargs : Dict [str , Any ] = {"model" : model , "messages" : [{"role" : "user" , "content" : prompt }], "max_tokens" : 4096 }
294+ kwargs : Dict [str , Any ] = {
295+ "model" : model ,
296+ "messages" : [{"role" : "user" , "content" : prompt }],
297+ "max_tokens" : 4096 ,
298+ }
273299 if think :
274300 kwargs ["temperature" ] = 1
275301 kwargs ["thinking" ] = {"type" : "enabled" , "budget_tokens" : 2048 }
0 commit comments