fix: 修复 XInference 供应商加载模型时的未认证导致 API 域名无效的问题
This commit is contained in:
parent
e34f4074fe
commit
ccc0be788a
@ -34,7 +34,7 @@ class XinferenceLLMModelCredential(BaseForm, BaseModelCredential):
|
|||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, 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} 模型类型不支持')
|
raise AppApiException(ValidCode.valid_error.value, f'{model_type} 模型类型不支持')
|
||||||
try:
|
try:
|
||||||
model_list = provider.get_base_model_list(model_credential.get('api_base'), model_type)
|
model_list = provider.get_base_model_list(model_credential.get('api_base'), model_credential.get('api_key'), model_type)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AppApiException(ValidCode.valid_error.value, "API 域名无效")
|
raise AppApiException(ValidCode.valid_error.value, "API 域名无效")
|
||||||
exist = provider.get_model_info_by_name(model_list, model_name)
|
exist = provider.get_model_info_by_name(model_list, model_name)
|
||||||
|
|||||||
@ -371,10 +371,13 @@ class XinferenceModelProvider(IModelProvider):
|
|||||||
'xinference_icon_svg')))
|
'xinference_icon_svg')))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_base_model_list(api_base, model_type):
|
def get_base_model_list(api_base, api_key, model_type):
|
||||||
base_url = get_base_url(api_base)
|
base_url = get_base_url(api_base)
|
||||||
base_url = base_url if base_url.endswith('/v1') else (base_url + '/v1')
|
base_url = base_url if base_url.endswith('/v1') else (base_url + '/v1')
|
||||||
r = requests.request(method="GET", url=f"{base_url}/models", timeout=5)
|
headers = {}
|
||||||
|
if api_key:
|
||||||
|
headers['Authorization'] = f"Bearer {api_key}"
|
||||||
|
r = requests.request(method="GET", url=f"{base_url}/models", headers=headers, timeout=5)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
model_list = r.json().get('data')
|
model_list = r.json().get('data')
|
||||||
return [model for model in model_list if model.get('model_type') == model_type]
|
return [model for model in model_list if model.get('model_type') == model_type]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user