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 # publish files
for message_file, save_as in message_files: for message_file_id, save_as in message_files:
if save_as: if save_as:
self.variables_pool.set_file( 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 # publish message file
self.queue_manager.publish(QueueMessageFileEvent( self.queue_manager.publish(QueueMessageFileEvent(
message_file_id=message_file.id message_file_id=message_file_id
), PublishFrom.APPLICATION_MANAGER) ), PublishFrom.APPLICATION_MANAGER)
# add message file ids # 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 return tool_invoke_response, tool_invoke_meta

View File

@ -245,16 +245,16 @@ class FunctionCallAgentRunner(BaseAgentRunner):
agent_tool_callback=self.agent_callback, agent_tool_callback=self.agent_callback,
) )
# publish files # publish files
for message_file, save_as in message_files: for message_file_id, save_as in message_files:
if save_as: 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 # publish message file
self.queue_manager.publish(QueueMessageFileEvent( self.queue_manager.publish(QueueMessageFileEvent(
message_file_id=message_file.id message_file_id=message_file_id
), PublishFrom.APPLICATION_MANAGER) ), PublishFrom.APPLICATION_MANAGER)
# add message file ids # add message file ids
message_file_ids.append(message_file.id) message_file_ids.append(message_file_id)
tool_response = { tool_response = {
"tool_call_id": tool_call_id, "tool_call_id": tool_call_id,

View File

@ -167,8 +167,11 @@ class MessageCycleManage:
extension = '.bin' extension = '.bin'
else: else:
extension = '.bin' extension = '.bin'
# add sign url # add sign url to local file
url = ToolFileManager.sign_file(tool_file_id=tool_file_id, extension=extension) 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( return MessageFileStreamResponse(
task_id=self._application_generate_entity.task_id, task_id=self._application_generate_entity.task_id,

View File

@ -65,6 +65,7 @@ class FileVar(BaseModel):
'type': self.type.value, 'type': self.type.value,
'transfer_method': self.transfer_method.value, 'transfer_method': self.transfer_method.value,
'url': self.preview_url, 'url': self.preview_url,
'remote_url': self.url,
'related_id': self.related_id, 'related_id': self.related_id,
'filename': self.filename, 'filename': self.filename,
'extension': self.extension, 'extension': self.extension,

View File

@ -19,7 +19,11 @@ 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)
results = [] result = []
for res in response: for res in response:
results.append(self.create_image_message(image=res.get("image"))) msg = ToolInvokeMessage(type=ToolInvokeMessage.MessageType.IMAGE_LINK,
return results 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 copy import deepcopy
from datetime import datetime, timezone from datetime import datetime, timezone
from mimetypes import guess_type from mimetypes import guess_type
from typing import Union from typing import Any, Union
from yarl import URL from yarl import URL
@ -250,7 +250,7 @@ class ToolEngine:
agent_message: Message, agent_message: Message,
invoke_from: InvokeFrom, invoke_from: InvokeFrom,
user_id: str user_id: str
) -> list[tuple[MessageFile, bool]]: ) -> list[tuple[Any, str]]:
""" """
Create message file Create message file
@ -291,7 +291,7 @@ class ToolEngine:
db.session.refresh(message_file) db.session.refresh(message_file)
result.append(( result.append((
message_file, message_file.id,
message.save_as message.save_as
)) ))

View File

@ -174,6 +174,7 @@ class ToolNode(BaseNode):
tenant_id=self.tenant_id, tenant_id=self.tenant_id,
type=FileType.IMAGE, type=FileType.IMAGE,
transfer_method=FileTransferMethod.TOOL_FILE, transfer_method=FileTransferMethod.TOOL_FILE,
url=url,
related_id=tool_file_id, related_id=tool_file_id,
filename=filename, filename=filename,
extension=ext, extension=ext,

View File

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