fix: DuckDuckGo image search tool error (#5606)

This commit is contained in:
非法操作 2024-06-26 13:21:40 +08:00 committed by GitHub
parent 43335b5c87
commit b8926ea267
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 26 additions and 16 deletions

View File

@ -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

View File

@ -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,

View File

@ -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(

View File

@ -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,

View File

@ -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

View File

@ -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
))

View File

@ -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,

View File

@ -46,6 +46,7 @@ const ImageGallery: FC<Props> = ({
src={src}
alt=''
onClick={() => setImagePreviewUrl(src)}
onError={e => e.currentTarget.remove()}
/>
))}
{