返回提交历史
Modified
g4f/Provider/local/Ollama.py
+4
-1
Modified
g4f/Provider/needs_auth/Azure.py
+3
-3
Modified
g4f/Provider/needs_auth/CablyAI.py
+1
-1
Modified
g4f/Provider/needs_auth/DeepSeek.py
+1
-0
Modified
g4f/Provider/needs_auth/FenayAI.py
+1
-0
Modified
g4f/Provider/needs_auth/GithubCopilotAPI.py
+1
-1
Modified
g4f/Provider/needs_auth/OpenaiAPI.py
+2
-1
Modified
g4f/Provider/needs_auth/ThebApi.py
+1
-0
Modified
g4f/Provider/needs_auth/xAI.py
+2
-1
Modified
g4f/Provider/template/OpenaiTemplate.py
+3
-0
XFEstudio/gpt4free
Check api_key for models
b3c1d1f3
代码差异
10 个文件
+19
-8
@@ -23,7 +23,10 @@ class Ollama(OpenaiAPI):
23
23
url = f"http://{host}:{port}/api/tags"
24
24
else:
25
25
url = api_base.replace("/v1", "/api/tags")
26
models = requests.get(url).json()["models"]
26
try:
27
models = requests.get(url).json()["models"]
28
except requests.exceptions.RequestException as e:
29
return cls.fallback_models
27
30
cls.models = [model["name"] for model in models]
28
31
cls.default_model = cls.models[0]
29
32
return cls.models
@@ -23,7 +23,7 @@ class Azure(OpenaiTemplate):
23
23
vision_models = ["gpt-4.1", "o4-mini", "model-router", "flux.1-kontext-pro"]
24
24
image_models = ["flux-1.1-pro", "flux.1-kontext-pro"]
25
25
model_aliases = {
26
"flux-kontext": "flux-1-kontext-pro"
26
"flux-kontext": "flux.1-kontext-pro"
27
27
}
28
28
model_extra_body = {
29
29
"gpt-4o-mini-audio-preview": {
@@ -92,8 +92,8 @@ class Azure(OpenaiTemplate):
92
92
if media:
93
93
form = FormData()
94
94
form.add_field("prompt", prompt)
95
form.add_field("width", width)
96
form.add_field("height", height)
95
form.add_field("width", str(width))
96
form.add_field("height", str(height))
97
97
output_format = "png"
98
98
for i in range(len(media)):
99
99
if media[i][1] is None and isinstance(media[i][0], str):
@@ -8,7 +8,7 @@ class CablyAI(OpenaiTemplate):
8
8
login_url = "https://cablyai.com"
9
9
api_base = "https://cablyai.com/v1"
10
10
11
working = True
11
working = False
12
12
needs_auth = True
13
13
supports_stream = True
14
14
supports_system_message = True
@@ -13,3 +13,4 @@ class DeepSeek(OpenaiAPI):
13
13
supports_message_history = True
14
14
default_model = "deepseek-chat"
15
15
fallback_models = [default_model]
16
models_needs_auth = True
@@ -9,6 +9,7 @@ class FenayAI(OpenaiTemplate):
9
9
api_base = "https://fenayai.com/v1"
10
10
working = True
11
11
needs_auth = True
12
models_needs_auth = True
12
13
default_model = DEFAULT_MODEL.split("/")[-1]
13
14
14
15
@classmethod
@@ -9,4 +9,4 @@ class GithubCopilotAPI(OpenaiAPI):
9
9
working = True
10
10
api_base = "https://api.githubcopilot.com"
11
11
needs_auth = True
12
12
models_needs_auth = True
@@ -8,4 +8,5 @@ class OpenaiAPI(OpenaiTemplate):
8
8
login_url = "https://platform.openai.com/settings/organization/api-keys"
9
9
api_base = "https://api.openai.com/v1"
10
10
working = True
11
needs_auth = True
11
needs_auth = True
12
models_needs_auth = True
@@ -26,6 +26,7 @@ class ThebApi(OpenaiTemplate):
26
26
api_base = "https://api.theb.ai/v1"
27
27
working = True
28
28
needs_auth = True
29
models_needs_auth = True
29
30
30
31
default_model = "theb-ai"
31
32
fallback_models = list(models)
@@ -7,4 +7,5 @@ class xAI(OpenaiTemplate):
7
7
login_url = "https://console.x.ai"
8
8
api_base = "https://api.x.ai/v1"
9
9
working = True
10
needs_auth = True
10
needs_auth = True
11
models_needs_auth = True
@@ -23,6 +23,7 @@ class OpenaiTemplate(AsyncGeneratorProvider, ProviderModelMixin, RaiseErrorMixin
23
23
default_model = ""
24
24
fallback_models = []
25
25
sort_models = True
26
models_needs_auth = False
26
27
ssl = None
27
28
28
29
@classmethod
@@ -36,6 +37,8 @@ class OpenaiTemplate(AsyncGeneratorProvider, ProviderModelMixin, RaiseErrorMixin
36
37
api_key = cls.api_key
37
38
if not api_key:
38
39
api_key = AuthManager.load_api_key(cls)
40
if cls.models_needs_auth and not api_key:
41
raise MissingAuthError('Add a "api_key"')
39
42
if api_key is not None:
40
43
headers["authorization"] = f"Bearer {api_key}"
41
44
response = requests.get(f"{api_base}/models", headers=headers, verify=cls.ssl)