Skip to content

Commit e6abf45

Browse files
committed
1 parent 7430b46 commit e6abf45

1 file changed

Lines changed: 18 additions & 27 deletions

File tree

LocalBot.py

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ async def handle_tool_call(
242242

243243
# Define available tools with type hints
244244
tool_actions = {
245-
"imagine": lambda: imagine(ctx, prompt=tool_arguments.get("prompt"), from_tool_call=send_directly),
245+
"imagine": lambda: imagine(ctx, prompt=tool_arguments.get("prompt")),
246246
"cat": lambda: cat(ctx, from_tool_call=send_directly),
247247
"dog": lambda: dog(ctx, from_tool_call=send_directly),
248248
"gtn": lambda: gtn(ctx, from_tool_call=send_directly),
@@ -571,6 +571,8 @@ async def chat(ctx, *, message):
571571
# There's another tool call, continue processing
572572
response = remaining_text
573573
else:
574+
if "imagine" in tool_call_text:
575+
break
574576
# No more tool calls, generate final response with all tool results
575577
followup_prompt = (
576578
f"You used one or more tools to answer the user's question. "
@@ -621,7 +623,7 @@ async def send_complete_response(ctx, response):
621623

622624

623625
@bot.slash_command(description="Generate an image based on a prompt.")
624-
async def imagine(ctx, *, prompt: str, from_tool_call=False) -> None:
626+
async def imagine(ctx, *, prompt: str) -> None:
625627
async def send_initial_message():
626628
if hasattr(ctx, "respond"):
627629
return await ctx.respond("Generating image, please wait...")
@@ -636,9 +638,7 @@ async def edit_message(initial_message, content=None, embed=None, file=None):
636638

637639
try:
638640
start_time = time.time()
639-
640-
# Only send the initial message if not called from a tool call
641-
initial_message = await send_initial_message() if not from_tool_call else None
641+
initial_message = await send_initial_message()
642642
image_path = await generate_image(prompt)
643643
time_taken = time.time() - start_time
644644

@@ -649,33 +649,24 @@ async def edit_message(initial_message, content=None, embed=None, file=None):
649649
)
650650
embed.set_image(url=f"attachment://{os.path.basename(image_path)}")
651651
embed.set_footer(text=f"Time taken: {time_taken:.2f}s")
652-
653-
# Only edit/send the message if not called from a tool call
654-
if not from_tool_call:
655-
await edit_message(
656-
initial_message,
657-
content=None,
658-
embed=embed,
659-
file=discord.File(image_path),
660-
)
661-
652+
await edit_message(
653+
initial_message,
654+
content=None,
655+
embed=embed,
656+
file=discord.File(image_path),
657+
)
662658
if os.path.exists(image_path):
663659
os.remove(image_path)
664-
return
660+
661+
return "Image generated and sent successfully."
665662
else:
666-
# Only edit/send the message if not called from a tool call
667-
if not from_tool_call:
668-
await edit_message(initial_message, content="Failed to generate image.")
669-
return "Failed to generate image."
663+
await edit_message(initial_message, content="Failed to generate image.")
670664
except Exception as e:
671665
print(f"Error generating image: {e}")
672-
673-
if not from_tool_call:
674-
if hasattr(ctx, "respond"):
675-
await ctx.respond("An error occurred while generating the image.")
676-
else:
677-
await ctx.reply("An error occurred while generating the image.")
678-
return f"Error: {str(e)}"
666+
if hasattr(ctx, "respond"):
667+
await ctx.respond("An error occurred while generating the image.")
668+
else:
669+
await ctx.reply("An error occurred while generating the image.")
679670

680671

681672
@bot.slash_command(description="Delete a set number of messages.")

0 commit comments

Comments
 (0)