From a221e9e2290d5275f8c34e9a7c78b70605e8d71d Mon Sep 17 00:00:00 2001 From: suluyana Date: Mon, 25 Nov 2024 15:02:27 +0800 Subject: [PATCH 01/11] fix bugs --- apps/agentfabric/app.py | 7 ++++++- apps/agentfabric/appBot.py | 8 +++++++- apps/agentfabric/server.py | 4 ++-- modelscope_agent/agents/multi_role_play.py | 7 +++---- .../llm/utils/function_call_with_raw_prompt.py | 14 ++++++-------- modelscope_agent/tools/utils/output_wrapper.py | 2 +- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/apps/agentfabric/app.py b/apps/agentfabric/app.py index ccebcf2db..ccb7c9189 100644 --- a/apps/agentfabric/app.py +++ b/apps/agentfabric/app.py @@ -621,11 +621,16 @@ def preview_send_message(chatbot, input, _state, uuid_str, _user_token): # get chat history from memory history = user_memory.get_history() + # skip + filtered_files = [ + item for item in append_files + if not item.lower().endswith(('.jpeg', '.png', '.jpg', '.wav', '.gif', '.mp3')) + ] use_llm = True if len(user_agent.function_list) else False ref_doc = user_memory.run( query=input.text, - url=append_files, + url=filtered_files, max_token=4000, top_k=2, checked=True, diff --git a/apps/agentfabric/appBot.py b/apps/agentfabric/appBot.py index d1b3b440e..2b3d085bb 100644 --- a/apps/agentfabric/appBot.py +++ b/apps/agentfabric/appBot.py @@ -150,9 +150,15 @@ def send_message(chatbot, input, _state, _user_token): # get short term memory history history = user_memory.get_history() + # skip + filtered_files = [ + item for item in append_files + if not item.lower().endswith(('.jpeg', '.png', '.jpg', '.wav', '.gif', '.mp3')) + ] + use_llm = True if len(user_agent.function_list) else False ref_doc = user_memory.run( - query=input.text, url=append_files, checked=True, use_llm=use_llm) + query=input.text, url=filtered_files, checked=True, use_llm=use_llm) response = '' try: diff --git a/apps/agentfabric/server.py b/apps/agentfabric/server.py index c75edb24f..b78631bb4 100644 --- a/apps/agentfabric/server.py +++ b/apps/agentfabric/server.py @@ -424,10 +424,10 @@ def generate(): f'load history method: time consumed {time.time() - start_time}' ) - # skip image upsert + # skip filtered_files = [ item for item in file_paths - if not item.lower().endswith(('.jpeg', '.png', '.jpg')) + if not item.lower().endswith(('.jpeg', '.png', '.jpg', '.wav', '.gif', '.mp3')) ] use_llm = True if len(user_agent.function_list) else False diff --git a/modelscope_agent/agents/multi_role_play.py b/modelscope_agent/agents/multi_role_play.py index 1e8d8fca4..12bd751cd 100644 --- a/modelscope_agent/agents/multi_role_play.py +++ b/modelscope_agent/agents/multi_role_play.py @@ -30,7 +30,7 @@ Action: 工具的名称,必须是[{tool_names}]之一 Action Input: 工具的输入 Observation: 工具返回的结果 -Answer: 根据Observation总结本次工具调用返回的结果,如果结果中出现url,请使用如下格式展示出来:![图片](url) +Answer: 根据Observation总结本次工具调用返回的结果 """ @@ -59,10 +59,9 @@ Action: The name of the tool, must be one of [{tool_names}] Action Input: Tool input Observation: Tool returns result -Answer: Summarize the results of this tool call based on Observation. If the result contains url, %s +Answer: Summarize the results of this tool call based on Observation. -""" % ('You can call zero or more times according to your needs:', - 'please display it in the following format:![Image](URL)') +""" % ('You can call zero or more times according to your needs:') PROMPT_TEMPLATE_EN = """{role_prompt}""" diff --git a/modelscope_agent/llm/utils/function_call_with_raw_prompt.py b/modelscope_agent/llm/utils/function_call_with_raw_prompt.py index d06c46b5d..6dd02ef9c 100644 --- a/modelscope_agent/llm/utils/function_call_with_raw_prompt.py +++ b/modelscope_agent/llm/utils/function_call_with_raw_prompt.py @@ -21,7 +21,7 @@ Action: 工具的名称,必须是[{tool_names}]之一 Action Input: 工具的输入 Observation: 工具返回的结果 -Answer: 根据Observation总结本次工具调用返回的结果,如果结果中出现url,请使用如下格式展示出来:![图片](url) +Answer: 根据Observation总结本次工具调用返回的结果 """ @@ -47,7 +47,7 @@ ... Observation: 工具N返回的结果 -Answer: 根据Observation总结本次工具调用返回的结果,如果结果中出现url,请使用如下格式展示出来:![图片](url) +Answer: 根据Observation总结本次工具调用返回的结果 """ @@ -64,10 +64,9 @@ Action: The name of the tool, must be one of [{tool_names}] Action Input: Tool input Observation: Tool returns result -Answer: Summarize the results of this tool call based on Observation. If the result contains url, %s +Answer: Summarize the results of this tool call based on Observation. -""" % ('You can call zero or more times according to your needs:', - 'please display it in the following format:![Image](URL)') +""" % ('You can call zero or more times according to your needs:') TOOL_TEMPLATE_EN_PARALLEL = """ # Tools @@ -90,10 +89,9 @@ Observation: Tool 1 returns result ... Observation: Tool N returns result -Answer: Summarize the results of this tool call based on Observation. If the result contains url, %s +Answer: Summarize the results of this tool call based on Observation. -""" % ('You can call zero or more times according to your needs:', - 'please display it in the following format:![Image](URL)') +""" % ('You can call zero or more times according to your needs:') TOOL_TEMPLATE = { 'zh': TOOL_TEMPLATE_ZH, diff --git a/modelscope_agent/tools/utils/output_wrapper.py b/modelscope_agent/tools/utils/output_wrapper.py index c809abb5d..ad65d5385 100644 --- a/modelscope_agent/tools/utils/output_wrapper.py +++ b/modelscope_agent/tools/utils/output_wrapper.py @@ -178,7 +178,7 @@ def __init__(self, video, **kwargs) -> None: self._raw_data = video - if self._path.endswith('.gif'): + if self._path.split('?')[0].endswith('.gif'): self._repr = f'![IMAGEGEN]({self._path})' else: self._repr = f'