Skip to content

Commit

Permalink
fix: duckduckgo image search not work (langgenius#9821)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjlarry authored Oct 25, 2024
1 parent 5bf31e7 commit ac9f1e9
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions api/core/tools/provider/builtin/duckduckgo/tools/ddgo_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from duckduckgo_search import DDGS

from core.file.models import FileTransferMethod
from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool

Expand All @@ -20,11 +19,9 @@ def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> list[ToolInv
"max_results": tool_parameters.get("max_results"),
}
response = DDGS().images(**query_dict)
result = []
markdown_result = "\n\n"
json_result = []
for res in response:
res["transfer_method"] = FileTransferMethod.REMOTE_URL
msg = ToolInvokeMessage(
type=ToolInvokeMessage.MessageType.IMAGE_LINK, message=res.get("image"), save_as="", meta=res
)
result.append(msg)
return result
markdown_result += f"![{res.get('title') or ''}]({res.get('image') or ''})"
json_result.append(self.create_json_message(res))
return [self.create_text_message(markdown_result)] + json_result

0 comments on commit ac9f1e9

Please sign in to comment.