Fix some issues around async and tool constraints
This commit is contained in:
parent
0e2e69a71d
commit
22b6d5866c
3 changed files with 22 additions and 9 deletions
|
|
@ -581,8 +581,21 @@ def handle_image_function_call(function_name: str, function_args: Dict[str, Any]
|
||||||
allow_nsfw_images = True
|
allow_nsfw_images = True
|
||||||
seed = None
|
seed = None
|
||||||
|
|
||||||
# Run async function in event loop
|
# Run async function in event loop with proper handling for multiprocessing
|
||||||
return asyncio.run(image_generate_tool(
|
try:
|
||||||
|
# Try to get existing event loop
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
if loop.is_closed():
|
||||||
|
# If closed, create a new one
|
||||||
|
loop = asyncio.new_event_loop()
|
||||||
|
asyncio.set_event_loop(loop)
|
||||||
|
except RuntimeError:
|
||||||
|
# No event loop in current thread, create one
|
||||||
|
loop = asyncio.new_event_loop()
|
||||||
|
asyncio.set_event_loop(loop)
|
||||||
|
|
||||||
|
# Run the coroutine in the event loop
|
||||||
|
result = loop.run_until_complete(image_generate_tool(
|
||||||
prompt=prompt,
|
prompt=prompt,
|
||||||
image_size=image_size,
|
image_size=image_size,
|
||||||
num_inference_steps=num_inference_steps,
|
num_inference_steps=num_inference_steps,
|
||||||
|
|
@ -594,6 +607,8 @@ def handle_image_function_call(function_name: str, function_args: Dict[str, Any]
|
||||||
allow_nsfw_images=allow_nsfw_images,
|
allow_nsfw_images=allow_nsfw_images,
|
||||||
seed=seed
|
seed=seed
|
||||||
))
|
))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return json.dumps({"error": f"Unknown image generation function: {function_name}"})
|
return json.dumps({"error": f"Unknown image generation function: {function_name}"})
|
||||||
|
|
|
||||||
|
|
@ -319,9 +319,6 @@ async def image_generate_tool(
|
||||||
if not prompt or not isinstance(prompt, str) or len(prompt.strip()) == 0:
|
if not prompt or not isinstance(prompt, str) or len(prompt.strip()) == 0:
|
||||||
raise ValueError("Prompt is required and must be a non-empty string")
|
raise ValueError("Prompt is required and must be a non-empty string")
|
||||||
|
|
||||||
if len(prompt) > 1000:
|
|
||||||
raise ValueError("Prompt must be 1000 characters or less")
|
|
||||||
|
|
||||||
# Check API key availability
|
# Check API key availability
|
||||||
if not os.getenv("FAL_KEY"):
|
if not os.getenv("FAL_KEY"):
|
||||||
raise ValueError("FAL_KEY environment variable not set")
|
raise ValueError("FAL_KEY environment variable not set")
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,11 @@ DISTRIBUTIONS = {
|
||||||
"image_gen": {
|
"image_gen": {
|
||||||
"description": "Heavy focus on image generation with vision and web support",
|
"description": "Heavy focus on image generation with vision and web support",
|
||||||
"toolsets": {
|
"toolsets": {
|
||||||
"image_gen": 80, # 80% chance of image generation tools
|
"image_gen": 90, # 80% chance of image generation tools
|
||||||
"vision": 60, # 60% chance of vision tools
|
"vision": 90, # 60% chance of vision tools
|
||||||
"web": 40, # 40% chance of web tools
|
"web": 55, # 40% chance of web tools
|
||||||
"moa": 20 # 20% chance of reasoning tools
|
"terminal": 45,
|
||||||
|
"moa": 10 # 20% chance of reasoning tools
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue