Skip to content

Commit ae7c446

Browse files
committed
fix: show tips for non exist ollama model
--bug=1050792 --user=刘瑞斌 【模型管理】ollama图片理解模型,选择服务器上不存在的模型时没有自动下载 https://www.tapd.cn/57709429/s/1636732
1 parent 9e1b7fc commit ae7c446

File tree

1 file changed

+7
-17
lines changed
  • apps/setting/models_provider/impl/ollama_model_provider/credential

1 file changed

+7
-17
lines changed

apps/setting/models_provider/impl/ollama_model_provider/credential/image.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,15 @@ def is_valid(self, model_type: str, model_name, model_credential: Dict[str, obje
3737
model_type_list = provider.get_model_type_list()
3838
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
3939
raise AppApiException(ValidCode.valid_error.value, f'{model_type} 模型类型不支持')
40-
41-
for key in ['api_base', 'api_key']:
42-
if key not in model_credential:
43-
if raise_exception:
44-
raise AppApiException(ValidCode.valid_error.value, f'{key} 字段为必填字段')
45-
else:
46-
return False
4740
try:
48-
model = provider.get_model(model_type, model_name, model_credential)
49-
res = model.stream([HumanMessage(content=[{"type": "text", "text": "你好"}])])
50-
for chunk in res:
51-
print(chunk)
41+
model_list = provider.get_base_model_list(model_credential.get('api_base'))
5242
except Exception as e:
53-
if isinstance(e, AppApiException):
54-
raise e
55-
if raise_exception:
56-
raise AppApiException(ValidCode.valid_error.value, f'校验失败,请检查参数是否正确: {str(e)}')
57-
else:
58-
return False
43+
raise AppApiException(ValidCode.valid_error.value, "API 域名无效")
44+
exist = [model for model in (model_list.get('models') if model_list.get('models') is not None else []) if
45+
model.get('model') == model_name or model.get('model').replace(":latest", "") == model_name]
46+
if len(exist) == 0:
47+
raise AppApiException(ValidCode.model_not_fount, "模型不存在,请先下载模型")
48+
5949
return True
6050

6151
def encryption_dict(self, model: Dict[str, object]):

0 commit comments

Comments
 (0)