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,7 +23,10 @@ class Ollama(OpenaiAPI):
|
|||
url = f"http://{host}:{port}/api/tags"
|
||||
else:
|
||||
url = api_base.replace("/v1", "/api/tags")
|
||||
models = requests.get(url).json()["models"]
|
||||
try:
|
||||
models = requests.get(url).json()["models"]
|
||||
except requests.exceptions.RequestException as e:
|
||||
return cls.fallback_models
|
||||
cls.models = [model["name"] for model in models]
|
||||
cls.default_model = cls.models[0]
|
||||
return cls.models
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class Azure(OpenaiTemplate):
|
|||
vision_models = ["gpt-4.1", "o4-mini", "model-router", "flux.1-kontext-pro"]
|
||||
image_models = ["flux-1.1-pro", "flux.1-kontext-pro"]
|
||||
model_aliases = {
|
||||
"flux-kontext": "flux-1-kontext-pro"
|
||||
"flux-kontext": "flux.1-kontext-pro"
|
||||
}
|
||||
model_extra_body = {
|
||||
"gpt-4o-mini-audio-preview": {
|
||||
|
|
@ -92,8 +92,8 @@ class Azure(OpenaiTemplate):
|
|||
if media:
|
||||
form = FormData()
|
||||
form.add_field("prompt", prompt)
|
||||
form.add_field("width", width)
|
||||
form.add_field("height", height)
|
||||
form.add_field("width", str(width))
|
||||
form.add_field("height", str(height))
|
||||
output_format = "png"
|
||||
for i in range(len(media)):
|
||||
if media[i][1] is None and isinstance(media[i][0], str):
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class CablyAI(OpenaiTemplate):
|
|||
login_url = "https://cablyai.com"
|
||||
api_base = "https://cablyai.com/v1"
|
||||
|
||||
working = True
|
||||
working = False
|
||||
needs_auth = True
|
||||
supports_stream = True
|
||||
supports_system_message = True
|
||||
|
|
|
|||
|
|
@ -13,3 +13,4 @@ class DeepSeek(OpenaiAPI):
|
|||
supports_message_history = True
|
||||
default_model = "deepseek-chat"
|
||||
fallback_models = [default_model]
|
||||
models_needs_auth = True
|
||||
|
|
@ -9,6 +9,7 @@ class FenayAI(OpenaiTemplate):
|
|||
api_base = "https://fenayai.com/v1"
|
||||
working = True
|
||||
needs_auth = True
|
||||
models_needs_auth = True
|
||||
default_model = DEFAULT_MODEL.split("/")[-1]
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -9,4 +9,4 @@ class GithubCopilotAPI(OpenaiAPI):
|
|||
working = True
|
||||
api_base = "https://api.githubcopilot.com"
|
||||
needs_auth = True
|
||||
|
||||
models_needs_auth = True
|
||||
|
|
|
|||
|
|
@ -9,3 +9,4 @@ class OpenaiAPI(OpenaiTemplate):
|
|||
api_base = "https://api.openai.com/v1"
|
||||
working = True
|
||||
needs_auth = True
|
||||
models_needs_auth = True
|
||||
|
|
@ -26,6 +26,7 @@ class ThebApi(OpenaiTemplate):
|
|||
api_base = "https://api.theb.ai/v1"
|
||||
working = True
|
||||
needs_auth = True
|
||||
models_needs_auth = True
|
||||
|
||||
default_model = "theb-ai"
|
||||
fallback_models = list(models)
|
||||
|
|
|
|||
|
|
@ -8,3 +8,4 @@ class xAI(OpenaiTemplate):
|
|||
api_base = "https://api.x.ai/v1"
|
||||
working = True
|
||||
needs_auth = True
|
||||
models_needs_auth = True
|
||||
|
|
@ -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