mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-28 10:26:33 +02:00
refactor: remove display_image tool and update related components to streamline image handling
This commit is contained in:
parent
eed792c19a
commit
6c507989d2
16 changed files with 385 additions and 93 deletions
|
|
@ -351,22 +351,19 @@ async def _stream_agent_events(
|
|||
status="in_progress",
|
||||
items=last_active_step_items,
|
||||
)
|
||||
elif tool_name == "display_image":
|
||||
src = (
|
||||
tool_input.get("src", "")
|
||||
elif tool_name == "generate_image":
|
||||
prompt = (
|
||||
tool_input.get("prompt", "")
|
||||
if isinstance(tool_input, dict)
|
||||
else str(tool_input)
|
||||
)
|
||||
title = (
|
||||
tool_input.get("title", "") if isinstance(tool_input, dict) else ""
|
||||
)
|
||||
last_active_step_title = "Analyzing the image"
|
||||
last_active_step_title = "Generating image"
|
||||
last_active_step_items = [
|
||||
f"Analyzing: {title[:50] if title else src[:50]}{'...' if len(title or src) > 50 else ''}"
|
||||
f"Prompt: {prompt[:80]}{'...' if len(prompt) > 80 else ''}"
|
||||
]
|
||||
yield streaming_service.format_thinking_step(
|
||||
step_id=tool_step_id,
|
||||
title="Analyzing the image",
|
||||
title="Generating image",
|
||||
status="in_progress",
|
||||
items=last_active_step_items,
|
||||
)
|
||||
|
|
@ -531,20 +528,22 @@ async def _stream_agent_events(
|
|||
status="completed",
|
||||
items=completed_items,
|
||||
)
|
||||
elif tool_name == "display_image":
|
||||
if isinstance(tool_output, dict):
|
||||
title = tool_output.get("title", "")
|
||||
alt = tool_output.get("alt", "Image")
|
||||
display_name = title or alt
|
||||
elif tool_name == "generate_image":
|
||||
if isinstance(tool_output, dict) and not tool_output.get("error"):
|
||||
completed_items = [
|
||||
*last_active_step_items,
|
||||
f"Analyzed: {display_name[:50]}{'...' if len(display_name) > 50 else ''}",
|
||||
"Image generated successfully",
|
||||
]
|
||||
else:
|
||||
completed_items = [*last_active_step_items, "Image analyzed"]
|
||||
error_msg = (
|
||||
tool_output.get("error", "Generation failed")
|
||||
if isinstance(tool_output, dict)
|
||||
else "Generation failed"
|
||||
)
|
||||
completed_items = [*last_active_step_items, f"Error: {error_msg}"]
|
||||
yield streaming_service.format_thinking_step(
|
||||
step_id=original_step_id,
|
||||
title="Analyzing the image",
|
||||
title="Generating image",
|
||||
status="completed",
|
||||
items=completed_items,
|
||||
)
|
||||
|
|
@ -842,7 +841,7 @@ async def _stream_agent_events(
|
|||
f"Link preview failed: {error_msg}",
|
||||
"error",
|
||||
)
|
||||
elif tool_name == "display_image":
|
||||
elif tool_name == "generate_image":
|
||||
yield streaming_service.format_tool_output_available(
|
||||
tool_call_id,
|
||||
tool_output
|
||||
|
|
@ -850,11 +849,16 @@ async def _stream_agent_events(
|
|||
else {"result": tool_output},
|
||||
)
|
||||
if isinstance(tool_output, dict):
|
||||
title = tool_output.get("title") or tool_output.get("alt", "Image")
|
||||
yield streaming_service.format_terminal_info(
|
||||
f"Image analyzed: {title[:40]}{'...' if len(title) > 40 else ''}",
|
||||
"success",
|
||||
)
|
||||
if tool_output.get("error"):
|
||||
yield streaming_service.format_terminal_info(
|
||||
f"Image generation failed: {tool_output['error'][:60]}",
|
||||
"error",
|
||||
)
|
||||
else:
|
||||
yield streaming_service.format_terminal_info(
|
||||
"Image generated successfully",
|
||||
"success",
|
||||
)
|
||||
elif tool_name == "scrape_webpage":
|
||||
if isinstance(tool_output, dict):
|
||||
display_output = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue