Skip to content

fix: 修复 XInference 供应商加载模型时的未认证导致 API 域名无效的问题 #1334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def is_valid(self, model_type: str, model_name, model_credential: Dict[str, obje
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
raise AppApiException(ValidCode.valid_error.value, f'{model_type} 模型类型不支持')
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:
raise AppApiException(ValidCode.valid_error.value, "API 域名无效")
exist = provider.get_model_info_by_name(model_list, model_name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,13 @@ def get_model_provide_info(self):
'xinference_icon_svg')))

@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 = 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()
model_list = r.json().get('data')
return [model for model in model_list if model.get('model_type') == model_type]
Expand Down