Skip to content

Commit

Permalink
fix: show tips for non exist ollama model
Browse files Browse the repository at this point in the history
--bug=1050792 --user=刘瑞斌 【模型管理】ollama图片理解模型,选择服务器上不存在的模型时没有自动下载 https://www.tapd.cn/57709429/s/1636732
  • Loading branch information
liuruibin committed Dec 25, 2024
1 parent 9e1b7fc commit ae7c446
Showing 1 changed file with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,15 @@ def is_valid(self, model_type: str, model_name, model_credential: Dict[str, obje
model_type_list = provider.get_model_type_list()
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
raise AppApiException(ValidCode.valid_error.value, f'{model_type} 模型类型不支持')

for key in ['api_base', 'api_key']:
if key not in model_credential:
if raise_exception:
raise AppApiException(ValidCode.valid_error.value, f'{key} 字段为必填字段')
else:
return False
try:
model = provider.get_model(model_type, model_name, model_credential)
res = model.stream([HumanMessage(content=[{"type": "text", "text": "你好"}])])
for chunk in res:
print(chunk)
model_list = provider.get_base_model_list(model_credential.get('api_base'))
except Exception as e:
if isinstance(e, AppApiException):
raise e
if raise_exception:
raise AppApiException(ValidCode.valid_error.value, f'校验失败,请检查参数是否正确: {str(e)}')
else:
return False
raise AppApiException(ValidCode.valid_error.value, "API 域名无效")
exist = [model for model in (model_list.get('models') if model_list.get('models') is not None else []) if
model.get('model') == model_name or model.get('model').replace(":latest", "") == model_name]
if len(exist) == 0:
raise AppApiException(ValidCode.model_not_fount, "模型不存在,请先下载模型")

return True

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

0 comments on commit ae7c446

Please sign in to comment.