@@ -182,6 +182,7 @@ def _last_image_file(user_state: dict) -> str:
182182 """Per-user path where the most recently generated/edited image is cached,
183183 so edit_image can target it via image_url='last'."""
184184 import os
185+
185186 uid = (user_state or {}).get ("id" , "anon" )
186187 d = os .path .join (STORAGE_MOUNT_POINT , f"user_{ uid } " , "images" )
187188 os .makedirs (d , exist_ok = True )
@@ -190,6 +191,7 @@ def _last_image_file(user_state: dict) -> str:
190191
191192def _save_last_image (user_state : dict , src_path : str ) -> None :
192193 import shutil
194+
193195 try :
194196 shutil .copyfile (src_path , _last_image_file (user_state ))
195197 except Exception : # nosec B110
@@ -319,22 +321,27 @@ def _handler(args: dict):
319321
320322 image_url = (args .get ("image_url" ) or "" ).strip ()
321323 prompt = (args .get ("prompt" ) or "" ).strip ()
322- model = ("flux-kontext-max" if args .get ("high_fidelity" )
323- else "flux-kontext-pro" )
324+ model = "flux-kontext-max" if args .get ("high_fidelity" ) else "flux-kontext-pro"
324325
325326 if not prompt :
326- return ToolResult (text = "Error: 'prompt' (the edit) is required." ,
327- error = True )
327+ return ToolResult (text = "Error: 'prompt' (the edit) is required." , error = True )
328328 bfl_key = api_keys .get ("BFL" , "" )
329329 if not bfl_key :
330330 return ToolResult (
331- text = "Image editing needs a BFL API key, which is not configured." ,
332- error = True )
331+ text = "Image editing needs a BFL API key, which is not configured." , error = True
332+ )
333333
334334 # Resolve the input image: a public URL, a local path, or 'last'
335335 # (the most recently generated/edited image in this session).
336- _LAST_KW = {"" , "last" , "previous" , "last_generated" , "last image" ,
337- "the last image" , "previous image" }
336+ _LAST_KW = {
337+ "" ,
338+ "last" ,
339+ "previous" ,
340+ "last_generated" ,
341+ "last image" ,
342+ "the last image" ,
343+ "previous image" ,
344+ }
338345 if image_url .startswith (("http://" , "https://" )):
339346 input_image , src_label = image_url , image_url [:80 ]
340347 else :
@@ -343,22 +350,22 @@ def _handler(args: dict):
343350 if not os .path .exists (local ):
344351 return ToolResult (
345352 text = "No previous image to edit. Generate one first or "
346- "pass a public image_url." , error = True )
353+ "pass a public image_url." ,
354+ error = True ,
355+ )
347356 src_label = "last generated image"
348357 elif os .path .exists (image_url ):
349358 local , src_label = image_url , os .path .basename (image_url )
350359 else :
351360 return ToolResult (
352- text = "Provide a public image_url, a local path, or 'last'." ,
353- error = True )
361+ text = "Provide a public image_url, a local path, or 'last'." , error = True
362+ )
354363 with open (local , "rb" ) as f :
355364 input_image = base64 .b64encode (f .read ()).decode () # BFL accepts base64
356365
357- print (f"[TOOLS] 🖌️ edit_image | model={ model } src={ src_label !r} "
358- f"prompt={ prompt [:80 ]!r} …" )
366+ print (f"[TOOLS] 🖌️ edit_image | model={ model } src={ src_label !r} prompt={ prompt [:80 ]!r} …" )
359367 try :
360- file_path , status = run_image_edit (
361- prompt , input_image , model , bfl_key , user_state )
368+ file_path , status = run_image_edit (prompt , input_image , model , bfl_key , user_state )
362369 except Exception as e :
363370 print (f"[TOOLS] ⚠️ edit_image failed: { e } " )
364371 return ToolResult (text = f"Image edit failed: { e } " , error = True )
@@ -371,12 +378,14 @@ def _handler(args: dict):
371378 b64 = base64 .b64encode (f .read ()).decode ()
372379 ext = os .path .splitext (file_path )[1 ].lstrip ("." ).lower () or "jpeg"
373380 mime = f"image/{ ext } " if ext != "jpg" else "image/jpeg"
374- img_html = (f'<img src="data:{ mime } ;base64,{ b64 } " '
375- f'style="max-width:100%;border-radius:8px;margin-top:8px;" />' )
381+ img_html = (
382+ f'<img src="data:{ mime } ;base64,{ b64 } " '
383+ f'style="max-width:100%;border-radius:8px;margin-top:8px;" />'
384+ )
376385 except Exception as e :
377386 img_html = f"*(edited image saved to { file_path } — could not embed: { e } )*"
378387
379- text_summary = ( f"✅ Image edited via BFL/{ model } .\n Edit: { prompt [:120 ]} " )
388+ text_summary = f"✅ Image edited via BFL/{ model } .\n Edit: { prompt [:120 ]} "
380389 return ToolResult (text = text_summary , ui = f"{ text_summary } \n \n { img_html } " )
381390
382391 return _handler
@@ -456,6 +465,7 @@ def _handler(args: dict) -> str:
456465 # Load transcription history from DB
457466 try :
458467 from db_ops import get_user_transcriptions
468+
459469 transcriptions = get_user_transcriptions (user_id , limit = 100 )
460470 except Exception as e :
461471 return f"Could not load transcription history: { e } "
@@ -471,18 +481,21 @@ def _handler(args: dict) -> str:
471481 if text and len (text ) > 20 :
472482 # Truncate very long texts to keep embedding fast
473483 docs .append (text [:2000 ])
474- meta .append ({
475- "id" : t .get ("id" ),
476- "provider" : t .get ("provider" , "?" ),
477- "created" : str (t .get ("created_at" , "?" )),
478- "full_len" : len (text ),
479- })
484+ meta .append (
485+ {
486+ "id" : t .get ("id" ),
487+ "provider" : t .get ("provider" , "?" ),
488+ "created" : str (t .get ("created_at" , "?" )),
489+ "full_len" : len (text ),
490+ }
491+ )
480492
481493 if not docs :
482494 return "No transcription texts found (all empty)."
483495
484496 try :
485497 from crispembed_tool import semantic_search
498+
486499 results = semantic_search (query , docs , top_k = top_k )
487500 except Exception as e :
488501 return f"Semantic search failed: { e } "
@@ -551,7 +564,9 @@ def no_creds_error(*args, **kwargs): # type: ignore[no-untyped-def]
551564 "exchange_contact_edit" : no_creds_error ,
552565 }
553566
554- logger .info ("[EXCH] Credentials loaded for user_id=%s: email=%s" , user_id , creds .get ("email" , "?" ))
567+ logger .info (
568+ "[EXCH] Credentials loaded for user_id=%s: email=%s" , user_id , creds .get ("email" , "?" )
569+ )
555570
556571 def handle_exchange_list (args : dict ) -> str :
557572 logger .debug ("[EXCH] exchange_list called with args=%s" , args )
@@ -1200,9 +1215,8 @@ def run_chat(
12001215 # ppt-llm presentation tools (provider/model/key + per-user storage)
12011216 try :
12021217 from pptx_tool import make_pptx_tool_handlers
1203- handlers .update (make_pptx_tool_handlers (
1204- API_KEYS , user_state , provider , model , key
1205- ))
1218+
1219+ handlers .update (make_pptx_tool_handlers (API_KEYS , user_state , provider , model , key ))
12061220 except Exception as _ppt_e :
12071221 logger .debug (f"[TOOLS] pptx handlers unavailable: { _ppt_e } " )
12081222
0 commit comments