Fix image search: embed markdown instead of describing URLs
- tools.py: search_images result now includes 'embed' (ready-to-use markdown image syntax) and 'citation' fields instead of raw 'local_url'; adds 'instructions' field so the model knows to render them verbatim - llm.py: system prompt now explicitly tells the model to embed images using the 'embed' field rather than describing or listing URLs - markdown.ts: explicitly allow src/alt in PURIFY_OPTS_FULL so img tags are never stripped by DOMPurify Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1264,18 +1264,28 @@ async def execute_tool(user_id: int, tool_name: str, arguments: dict) -> dict:
|
||||
source_domain=r.get("source_domain"),
|
||||
)
|
||||
if record:
|
||||
title = record.title or query
|
||||
page_url = r.get("page_url", "")
|
||||
source_domain = r.get("source_domain", "")
|
||||
images.append({
|
||||
"local_url": f"/api/images/{record.id}",
|
||||
"page_url": r.get("page_url", ""),
|
||||
"source_domain": r.get("source_domain", ""),
|
||||
"title": record.title or query,
|
||||
"embed": f"",
|
||||
"citation": f"*Source: [{source_domain or 'image'}]({page_url})*",
|
||||
"page_url": page_url,
|
||||
"title": title,
|
||||
})
|
||||
if not images:
|
||||
return {"success": False, "error": f"Could not retrieve images for '{query}'"}
|
||||
return {
|
||||
"success": True,
|
||||
"type": "image_search",
|
||||
"data": {"query": query, "images": images},
|
||||
"data": {
|
||||
"query": query,
|
||||
"images": images,
|
||||
"instructions": (
|
||||
"Embed each image in your response by writing the 'embed' field verbatim, "
|
||||
"then the 'citation' field on the next line. Do not paraphrase or list URLs."
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user