mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
fix: DuckDuckGo image search tool error (#5606)
This commit is contained in:
parent
43335b5c87
commit
b8926ea267
|
@ -316,17 +316,17 @@ class CotAgentRunner(BaseAgentRunner, ABC):
|
|||
)
|
||||
|
||||
# publish files
|
||||
for message_file, save_as in message_files:
|
||||
for message_file_id, save_as in message_files:
|
||||
if save_as:
|
||||
self.variables_pool.set_file(
|
||||
tool_name=tool_call_name, value=message_file.id, name=save_as)
|
||||
tool_name=tool_call_name, value=message_file_id, name=save_as)
|
||||
|
||||
# publish message file
|
||||
self.queue_manager.publish(QueueMessageFileEvent(
|
||||
message_file_id=message_file.id
|
||||
message_file_id=message_file_id
|
||||
), PublishFrom.APPLICATION_MANAGER)
|
||||
# add message file ids
|
||||
message_file_ids.append(message_file.id)
|
||||
message_file_ids.append(message_file_id)
|
||||
|
||||
return tool_invoke_response, tool_invoke_meta
|
||||
|
||||
|
|
|
@ -245,16 +245,16 @@ class FunctionCallAgentRunner(BaseAgentRunner):
|
|||
agent_tool_callback=self.agent_callback,
|
||||
)
|
||||
# publish files
|
||||
for message_file, save_as in message_files:
|
||||
for message_file_id, save_as in message_files:
|
||||
if save_as:
|
||||
self.variables_pool.set_file(tool_name=tool_call_name, value=message_file.id, name=save_as)
|
||||
self.variables_pool.set_file(tool_name=tool_call_name, value=message_file_id, name=save_as)
|
||||
|
||||
# publish message file
|
||||
self.queue_manager.publish(QueueMessageFileEvent(
|
||||
message_file_id=message_file.id
|
||||
message_file_id=message_file_id
|
||||
), PublishFrom.APPLICATION_MANAGER)
|
||||
# add message file ids
|
||||
message_file_ids.append(message_file.id)
|
||||
message_file_ids.append(message_file_id)
|
||||
|
||||
tool_response = {
|
||||
"tool_call_id": tool_call_id,
|
||||
|
|
|
@ -167,7 +167,10 @@ class MessageCycleManage:
|
|||
extension = '.bin'
|
||||
else:
|
||||
extension = '.bin'
|
||||
# add sign url
|
||||
# add sign url to local file
|
||||
if message_file.url.startswith('http'):
|
||||
url = message_file.url
|
||||
else:
|
||||
url = ToolFileManager.sign_file(tool_file_id=tool_file_id, extension=extension)
|
||||
|
||||
return MessageFileStreamResponse(
|
||||
|
|
|
@ -65,6 +65,7 @@ class FileVar(BaseModel):
|
|||
'type': self.type.value,
|
||||
'transfer_method': self.transfer_method.value,
|
||||
'url': self.preview_url,
|
||||
'remote_url': self.url,
|
||||
'related_id': self.related_id,
|
||||
'filename': self.filename,
|
||||
'extension': self.extension,
|
||||
|
|
|
@ -19,7 +19,11 @@ class DuckDuckGoImageSearchTool(BuiltinTool):
|
|||
"max_results": tool_parameters.get('max_results'),
|
||||
}
|
||||
response = DDGS().images(**query_dict)
|
||||
results = []
|
||||
result = []
|
||||
for res in response:
|
||||
results.append(self.create_image_message(image=res.get("image")))
|
||||
return results
|
||||
msg = ToolInvokeMessage(type=ToolInvokeMessage.MessageType.IMAGE_LINK,
|
||||
message=res.get('image'),
|
||||
save_as='',
|
||||
meta=res)
|
||||
result.append(msg)
|
||||
return result
|
||||
|
|
|
@ -2,7 +2,7 @@ import json
|
|||
from copy import deepcopy
|
||||
from datetime import datetime, timezone
|
||||
from mimetypes import guess_type
|
||||
from typing import Union
|
||||
from typing import Any, Union
|
||||
|
||||
from yarl import URL
|
||||
|
||||
|
@ -250,7 +250,7 @@ class ToolEngine:
|
|||
agent_message: Message,
|
||||
invoke_from: InvokeFrom,
|
||||
user_id: str
|
||||
) -> list[tuple[MessageFile, bool]]:
|
||||
) -> list[tuple[Any, str]]:
|
||||
"""
|
||||
Create message file
|
||||
|
||||
|
@ -291,7 +291,7 @@ class ToolEngine:
|
|||
db.session.refresh(message_file)
|
||||
|
||||
result.append((
|
||||
message_file,
|
||||
message_file.id,
|
||||
message.save_as
|
||||
))
|
||||
|
||||
|
|
|
@ -174,6 +174,7 @@ class ToolNode(BaseNode):
|
|||
tenant_id=self.tenant_id,
|
||||
type=FileType.IMAGE,
|
||||
transfer_method=FileTransferMethod.TOOL_FILE,
|
||||
url=url,
|
||||
related_id=tool_file_id,
|
||||
filename=filename,
|
||||
extension=ext,
|
||||
|
|
|
@ -46,6 +46,7 @@ const ImageGallery: FC<Props> = ({
|
|||
src={src}
|
||||
alt=''
|
||||
onClick={() => setImagePreviewUrl(src)}
|
||||
onError={e => e.currentTarget.remove()}
|
||||
/>
|
||||
))}
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user