fix: duckduckgo image search not work (#9821)
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions

This commit is contained in:
非法操作 2024-10-25 10:11:33 +08:00 committed by GitHub
parent 5bf31e7a86
commit ac9f1e9de5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,7 +2,6 @@ from typing import Any
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
@ -20,11 +19,9 @@ class DuckDuckGoImageSearchTool(BuiltinTool):
"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