mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-06 02:30:41 -08:00
Check api_key for models
This commit is contained in:
parent
9563f8df3a
commit
b3c1d1f3b1
10 changed files with 19 additions and 8 deletions
|
|
@ -23,6 +23,7 @@ class OpenaiTemplate(AsyncGeneratorProvider, ProviderModelMixin, RaiseErrorMixin
|
|||
default_model = ""
|
||||
fallback_models = []
|
||||
sort_models = True
|
||||
models_needs_auth = False
|
||||
ssl = None
|
||||
|
||||
@classmethod
|
||||
|
|
@ -36,6 +37,8 @@ class OpenaiTemplate(AsyncGeneratorProvider, ProviderModelMixin, RaiseErrorMixin
|
|||
api_key = cls.api_key
|
||||
if not api_key:
|
||||
api_key = AuthManager.load_api_key(cls)
|
||||
if cls.models_needs_auth and not api_key:
|
||||
raise MissingAuthError('Add a "api_key"')
|
||||
if api_key is not None:
|
||||
headers["authorization"] = f"Bearer {api_key}"
|
||||
response = requests.get(f"{api_base}/models", headers=headers, verify=cls.ssl)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue