fix: added error handling for novita ai tool query (#5506)

Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
This commit is contained in:
Xiao Ley 2024-06-23 17:59:03 +08:00 committed by GitHub
parent e9ce0b10de
commit 3a626cd251
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 6 deletions

View File

@ -42,17 +42,18 @@ class NovitaAiModelQueryTool(BuiltinTool):
result_str = ''
if result_type == 'first sd_name':
result_str = models_data[0]['sd_name_in_api']
result_str = models_data[0]['sd_name_in_api'] if len(models_data) > 0 else ''
elif result_type == 'first name sd_name pair':
result_str = json.dumps({'name': models_data[0]['name'], 'sd_name': models_data[0]['sd_name_in_api']})
result_str = json.dumps({'name': models_data[0]['name'], 'sd_name': models_data[0]['sd_name_in_api']}) if len(models_data) > 0 else ''
elif result_type == 'sd_name array':
sd_name_array = [model['sd_name_in_api'] for model in models_data]
sd_name_array = [model['sd_name_in_api'] for model in models_data] if len(models_data) > 0 else []
result_str = json.dumps(sd_name_array)
elif result_type == 'name array':
name_array = [model['name'] for model in models_data]
name_array = [model['name'] for model in models_data] if len(models_data) > 0 else []
result_str = json.dumps(name_array)
elif result_type == 'name sd_name pair array':
name_sd_name_pair_array = [{'name': model['name'], 'sd_name': model['sd_name_in_api']} for model in models_data]
name_sd_name_pair_array = [{'name': model['name'], 'sd_name': model['sd_name_in_api']}
for model in models_data] if len(models_data) > 0 else []
result_str = json.dumps(name_sd_name_pair_array)
elif result_type == 'whole info array':
result_str = json.dumps(models_data)

View File

@ -19,7 +19,8 @@ parameters:
human_description:
en_US: Seaching the content of sd_name, name, tags.
zh_Hans: 搜索 sd_name、name、tags 中的内容
form: form
llm_description: Enter the content to search
form: llm
- name: result_type
type: select
default: "first sd_name"