fix: duckduckgo image search not work (#9821)
This commit is contained in:
@@ -2,7 +2,6 @@ from typing import Any
|
|||||||
|
|
||||||
from duckduckgo_search import DDGS
|
from duckduckgo_search import DDGS
|
||||||
|
|
||||||
from core.file.models import FileTransferMethod
|
|
||||||
from core.tools.entities.tool_entities import ToolInvokeMessage
|
from core.tools.entities.tool_entities import ToolInvokeMessage
|
||||||
from core.tools.tool.builtin_tool import BuiltinTool
|
from core.tools.tool.builtin_tool import BuiltinTool
|
||||||
|
|
||||||
@@ -20,11 +19,9 @@ class DuckDuckGoImageSearchTool(BuiltinTool):
|
|||||||
"max_results": tool_parameters.get("max_results"),
|
"max_results": tool_parameters.get("max_results"),
|
||||||
}
|
}
|
||||||
response = DDGS().images(**query_dict)
|
response = DDGS().images(**query_dict)
|
||||||
result = []
|
markdown_result = "\n\n"
|
||||||
|
json_result = []
|
||||||
for res in response:
|
for res in response:
|
||||||
res["transfer_method"] = FileTransferMethod.REMOTE_URL
|
markdown_result += f" or ''})"
|
||||||
msg = ToolInvokeMessage(
|
json_result.append(self.create_json_message(res))
|
||||||
type=ToolInvokeMessage.MessageType.IMAGE_LINK, message=res.get("image"), save_as="", meta=res
|
return [self.create_text_message(markdown_result)] + json_result
|
||||||
)
|
|
||||||
result.append(msg)
|
|
||||||
return result
|
|
||||||
|
Reference in New Issue
Block a user