Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duckduckgo image search not work #9821

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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