Skip to content

Commit

Permalink
add fall back when file name input is invalid (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzhangpurdue authored Aug 1, 2024
1 parent 0011c64 commit d009a7f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions apps/agentfabric/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,21 @@ def generate():
f'load history method: time consumed {time.time() - start_time}'
)

# skip image upsert
filtered_files = [
item for item in file_paths
if not item.lower().endswith(('.jpeg', '.png', '.jpg'))
]

use_llm = True if len(user_agent.function_list) else False
ref_doc = user_memory.run(
query=input_content,
url=file_paths,
url=filtered_files,
checked=True,
use_llm=use_llm)
logger.info(
f'load knowledge method: time consumed {time.time() - start_time}, '
f'the uploaded_file name is {file_paths}') # noqa
f'the uploaded_file name is {filtered_files}') # noqa

response = ''

Expand Down
4 changes: 4 additions & 0 deletions modelscope_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ def _call_tool(self, tool_list: list, **kwargs):
try:
result = self.function_map[tool_name].call(tool_args, **kwargs)
except BaseException as e:
import traceback
print(
f'The error is {e}, and the traceback is {traceback.format_exc()}'
)
result = f'Tool api {tool_name} failed to call. Args: {tool_args}.'
result += f'Details: {str(e)[:200]}'
self.callback_manager.on_tool_end(tool_name, result)
Expand Down
2 changes: 2 additions & 0 deletions modelscope_agent/tools/dashscope_tools/paraformer_asr_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def call(self, params: str, **kwargs):
except AssertionError:
raise ValueError('Please set valid DASHSCOPE_API_KEY!')

# make sure the audio_path is file name not file path
params['audio_path'] = params['audio_path'].split('/')[-1]
if LOCAL_FILE_PATHS not in kwargs or kwargs[LOCAL_FILE_PATHS] == {}:
raw_audio_file = WORK_DIR + '/' + params['audio_path']
else:
Expand Down
2 changes: 2 additions & 0 deletions modelscope_agent/tools/dashscope_tools/style_repaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def _parse_input(self, *args, **kwargs):
kwargs = restored_dict
image_path = kwargs['input'].pop('image_path', None)
if image_path and image_path.endswith(('.jpeg', '.png', '.jpg')):
# make sure the image_path is a valid image file we only get the name of the file
image_path = image_path.split('/')[-1]
# 生成 image_url,然后设置到 kwargs['input'] 中
# 复用dashscope公共oss
if LOCAL_FILE_PATHS not in kwargs or kwargs[
Expand Down
3 changes: 3 additions & 0 deletions modelscope_agent_servers/tool_node_server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ async def execute_tool(request: ToolRequest):
result = await result
return create_success_msg(result, request_id=request.request_id)
except Exception as e:
import traceback
print(
f'The error is {e}, and the traceback is {traceback.format_exc()}')
return create_error_msg(
status_code=400,
request_id=request.request_id,
Expand Down

0 comments on commit d009a7f

Please sign in to comment.