@@ -19,10 +19,11 @@ def initialize_tools():
1919 Generate a high-quality image based on a detailed prompt. This tool creates stunning images using advanced AI generation techniques.
2020
2121 PARAMETERS:
22- - prompt (required): A detailed, artistic description of what to generate.\
23- Should include style, mood, lighting, composition, and specific details for best results.
22+ - prompt (required): A detailed description of what to generate.\
23+ Should include style, mood, lighting, composition, and specific details for best results.\
24+ Still be concise and to the point.
2425 - user_id (required): The unique identifier for the user requesting the image.
25- - image_url (required): URL of the source/reference image to base the generation on. Use empty string if no source image.
26+ - image_url (required): URL of the source/reference image to base the generation on.
2627 - title (optional): A concise, accurate title for the generated image. Defaults to "Generated Image" if not provided.
2728
2829 USAGE GUIDELINES:
@@ -55,32 +56,45 @@ def generate_image(
5556 """
5657 print (f"[TOOL] generate_image called with prompt: { prompt [:50 ]} ..., user_id: { user_id } , image_url: { image_url [:50 ]} ..." )
5758 input = {
58- "width" : 768 ,
59- "height" : 768 ,
6059 "prompt" : prompt ,
61- "refine" : "expert_ensemble_refiner" ,
62- "apply_watermark" : False ,
63- "num_inference_steps" : 25 ,
64- "prompt_strength" : 0.5 ,
65- "image" : image_url ,
60+ "input_image" : image_url ,
61+ "output_format" : "png" ,
6662 }
6763
6864 # Generate image using Replicate
6965 print (f"[TOOL] Calling Replicate with input: { input } " )
70- version = "stability-ai/sdxl:" "7762fd07cf82c948538e41f63f77d685e02b063e37e496e96eefd46c929f9bdc"
7166 output = replicate .run (
72- version ,
67+ "black-forest-labs/flux-kontext-pro" ,
7368 input = input ,
7469 )
7570 print (f"[TOOL] Replicate output: { output } " )
71+ print (f"[TOOL] Output type: { type (output )} " )
72+ print (f"[TOOL] Output length: { len (output ) if hasattr (output , '__len__' ) else 'N/A' } " )
7673
7774 # Check if generation was successful
78- if not output or len (output ) == 0 :
75+ if not output or ( hasattr ( output , "__len__" ) and len (output ) == 0 ) :
7976 print ("[TOOL] Replicate generation failed - no output" )
8077 return "Failed to generate image. Please try again."
8178
82- generated_image_url = output [0 ] if isinstance (output , list ) else output
83- print (f"[TOOL] Generated image URL: { generated_image_url } " )
79+ # Handle Flux Kontext Pro output format
80+ try :
81+ # Flux Kontext Pro returns an object with .url() method
82+ generated_image_url = output .url ()
83+ print (f"[TOOL] Extracted URL using output.url(): { generated_image_url } " )
84+ except AttributeError :
85+ # Fallback for unexpected output formats
86+ print (f"[TOOL] No .url() method found, output type: { type (output )} " )
87+ if isinstance (output , list ):
88+ generated_image_url = output [0 ]
89+ print (f"[TOOL] Fallback: Extracted URL from list: { generated_image_url } " )
90+ elif isinstance (output , str ):
91+ generated_image_url = output
92+ print (f"[TOOL] Fallback: Using direct string URL: { generated_image_url } " )
93+ else :
94+ print (f"[TOOL] Unexpected output type: { type (output )} , trying to convert to string" )
95+ generated_image_url = str (output )
96+
97+ print (f"[TOOL] Final generated image URL: { generated_image_url } " )
8498
8599 # Download the generated image
86100 image_data : Optional [bytes ] = None
0 commit comments