Skip to content

Commit d009a7f

Browse files
authored
add fall back when file name input is invalid (#560)
1 parent 0011c64 commit d009a7f

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

apps/agentfabric/server.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,21 @@ def generate():
426426
f'load history method: time consumed {time.time() - start_time}'
427427
)
428428

429+
# skip image upsert
430+
filtered_files = [
431+
item for item in file_paths
432+
if not item.lower().endswith(('.jpeg', '.png', '.jpg'))
433+
]
434+
429435
use_llm = True if len(user_agent.function_list) else False
430436
ref_doc = user_memory.run(
431437
query=input_content,
432-
url=file_paths,
438+
url=filtered_files,
433439
checked=True,
434440
use_llm=use_llm)
435441
logger.info(
436442
f'load knowledge method: time consumed {time.time() - start_time}, '
437-
f'the uploaded_file name is {file_paths}') # noqa
443+
f'the uploaded_file name is {filtered_files}') # noqa
438444

439445
response = ''
440446

modelscope_agent/agent.py

+4
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ def _call_tool(self, tool_list: list, **kwargs):
133133
try:
134134
result = self.function_map[tool_name].call(tool_args, **kwargs)
135135
except BaseException as e:
136+
import traceback
137+
print(
138+
f'The error is {e}, and the traceback is {traceback.format_exc()}'
139+
)
136140
result = f'Tool api {tool_name} failed to call. Args: {tool_args}.'
137141
result += f'Details: {str(e)[:200]}'
138142
self.callback_manager.on_tool_end(tool_name, result)

modelscope_agent/tools/dashscope_tools/paraformer_asr_tool.py

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def call(self, params: str, **kwargs):
4646
except AssertionError:
4747
raise ValueError('Please set valid DASHSCOPE_API_KEY!')
4848

49+
# make sure the audio_path is file name not file path
50+
params['audio_path'] = params['audio_path'].split('/')[-1]
4951
if LOCAL_FILE_PATHS not in kwargs or kwargs[LOCAL_FILE_PATHS] == {}:
5052
raw_audio_file = WORK_DIR + '/' + params['audio_path']
5153
else:

modelscope_agent/tools/dashscope_tools/style_repaint.py

+2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ def _parse_input(self, *args, **kwargs):
118118
kwargs = restored_dict
119119
image_path = kwargs['input'].pop('image_path', None)
120120
if image_path and image_path.endswith(('.jpeg', '.png', '.jpg')):
121+
# make sure the image_path is a valid image file we only get the name of the file
122+
image_path = image_path.split('/')[-1]
121123
# 生成 image_url,然后设置到 kwargs['input'] 中
122124
# 复用dashscope公共oss
123125
if LOCAL_FILE_PATHS not in kwargs or kwargs[

modelscope_agent_servers/tool_node_server/api.py

+3
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ async def execute_tool(request: ToolRequest):
132132
result = await result
133133
return create_success_msg(result, request_id=request.request_id)
134134
except Exception as e:
135+
import traceback
136+
print(
137+
f'The error is {e}, and the traceback is {traceback.format_exc()}')
135138
return create_error_msg(
136139
status_code=400,
137140
request_id=request.request_id,

0 commit comments

Comments
 (0)