@@ -1336,24 +1336,7 @@ async def process_chat(self, chat, provider_id=None):
13361336 ret .pop ("modalities" , None )
13371337 return ret
13381338
1339- async def chat (self , chat , context = None ):
1340- chat ["model" ] = self .provider_model (chat ["model" ]) or chat ["model" ]
1341-
1342- modalities = chat .get ("modalities" ) or []
1343- if len (modalities ) > 0 :
1344- for modality in modalities :
1345- # use default implementation for text modalities
1346- if modality == "text" :
1347- continue
1348- modality_provider = self .modalities .get (modality )
1349- if modality_provider :
1350- return await modality_provider .chat (chat , self , context = context )
1351- else :
1352- raise Exception (f"Provider { self .name } does not support '{ modality } ' modality" )
1353-
1354- # with open(os.path.join(os.path.dirname(__file__), 'chat.wip.json'), "w") as f:
1355- # f.write(json.dumps(chat, indent=2))
1356-
1339+ def init_chat (self , chat ):
13571340 if self .frequency_penalty is not None :
13581341 chat ["frequency_penalty" ] = self .frequency_penalty
13591342 if self .max_completion_tokens is not None :
@@ -1389,7 +1372,28 @@ async def chat(self, chat, context=None):
13891372 if self .enable_thinking is not None :
13901373 chat ["enable_thinking" ] = self .enable_thinking
13911374
1375+ async def chat (self , chat , context = None ):
1376+ chat ["model" ] = self .provider_model (chat ["model" ]) or chat ["model" ]
1377+
1378+ modalities = chat .get ("modalities" ) or []
1379+ if len (modalities ) > 0 :
1380+ for modality in modalities :
1381+ # use default implementation for text modalities
1382+ if modality == "text" :
1383+ continue
1384+ modality_provider = self .modalities .get (modality )
1385+ if modality_provider :
1386+ return await modality_provider .chat (chat , self , context = context )
1387+ else :
1388+ raise Exception (f"Provider { self .name } does not support '{ modality } ' modality" )
1389+
1390+ # with open(os.path.join(os.path.dirname(__file__), 'chat.wip.json'), "w") as f:
1391+ # f.write(json.dumps(chat, indent=2))
1392+
1393+ self .init_chat (chat )
1394+
13921395 chat = await self .process_chat (chat , provider_id = self .id )
1396+
13931397 _log (f"POST { self .chat_url } " )
13941398 _log (chat_summary (chat ))
13951399 # remove metadata if any (conflicts with some providers, e.g. Z.ai)
0 commit comments