XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/gpt4free

Enhance Azure provider error handling and update environment variables

391e1f46
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

4 个文件 +9 -8
Modified example.env +2 -0
@@ -5,6 +5,8 @@ G4F_API_KEY=
5 5 G4F_PROXY=
6 6 G4F_TIMEOUT=
7 7 G4F_STREAM_TIMEOUT=
8 G4F_BROWSER_PORT=
9 G4F_BROWSER_HOST=
8 10
9 11 HUGGINGFACE_API_KEY=
10 12 POLLINATIONS_API_KEY=
Modified g4f/Provider/needs_auth/Azure.py +2 -4
@@ -132,9 +132,7 @@ class Azure(OpenaiTemplate):
132 132 for key, value in cls.model_extra_body[model].items():
133 133 kwargs.setdefault(key, value)
134 134 stream = False
135 if stream:
136 kwargs.setdefault("stream_options", {"include_usage": True})
137 if cls.failed.get(api_key, 0) >= 3:
135 if cls.failed.get(model + api_key, 0) >= 3:
138 136 raise MissingAuthError(f"API key has failed too many times.")
139 137 try:
140 138 async for chunk in super().create_async_generator(
@@ -148,5 +146,5 @@ class Azure(OpenaiTemplate):
148 146 ):
149 147 yield chunk
150 148 except MissingAuthError as e:
151 cls.failed[api_key] = cls.failed.get(api_key, 0) + 1
149 cls.failed[model + api_key] = cls.failed.get(model + api_key, 0) + 1
152 150 raise MissingAuthError(f"{e}. Ask for help in the {cls.login_url} Discord server.") from e
Modified g4f/Provider/template/OpenaiTemplate.py +3 -1
@@ -89,7 +89,7 @@ class OpenaiTemplate(AsyncGeneratorProvider, ProviderModelMixin, RaiseErrorMixin
89 89 headers: dict = None,
90 90 impersonate: str = None,
91 91 download_media: bool = True,
92 extra_parameters: list[str] = ["tools", "parallel_tool_calls", "tool_choice", "reasoning_effort", "logit_bias", "modalities", "audio", "stream_options"],
92 extra_parameters: list[str] = ["tools", "parallel_tool_calls", "tool_choice", "reasoning_effort", "logit_bias", "modalities", "audio", "stream_options", "include_reasoning", "response_format", "max_completion_tokens", "reasoning_effort", "search_settings"],
93 93 extra_body: dict = None,
94 94 **kwargs
95 95 ) -> AsyncResult:
@@ -127,6 +127,8 @@ class OpenaiTemplate(AsyncGeneratorProvider, ProviderModelMixin, RaiseErrorMixin
127 127 yield ImageResponse([image["url"] for image in data["data"]], prompt)
128 128 return
129 129
130 if stream:
131 kwargs.setdefault("stream_options", {"include_usage": True})
130 132 extra_parameters = {key: kwargs[key] for key in extra_parameters if key in kwargs}
131 133 if extra_body is None:
132 134 extra_body = {}
Modified g4f/api/__init__.py +2 -3
@@ -11,7 +11,6 @@ import time
11 11 from email.utils import formatdate
12 12 import os.path
13 13 import hashlib
14 import asyncio
15 14 import base64
16 15 from contextlib import asynccontextmanager
17 16 from urllib.parse import quote_plus
@@ -109,7 +108,7 @@ async def lifespan(app: FastAPI):
109 108 try:
110 109 os.remove(lock_file)
111 110 except Exception as e:
112 debug.error(f"Failed to remove lock file {lock_file}:" ,e)
111 debug.error(f"Failed to remove lock file {lock_file}:", e)
113 112
114 113 def create_app():
115 114 app = FastAPI(lifespan=lifespan)
@@ -270,7 +269,7 @@ class Api:
270 269 user = "admin"
271 270 path = request.url.path
272 271 if path.startswith("/v1") or path.startswith("/api/") or (AppConfig.demo and path == '/backend-api/v2/upload_cookies'):
273 if request.method != "OPTIONS":
272 if request.method != "OPTIONS" and not path.endswith("/models"):
274 273 if user_g4f_api_key is None:
275 274 return ErrorResponse.from_message("G4F API key required", HTTP_401_UNAUTHORIZED)
276 275 if AppConfig.g4f_api_key is None and user is None: