返回提交历史
Modified
g4f/Provider/needs_auth/Azure.py
+4
-0
Modified
g4f/providers/base_provider.py
+4
-4
XFEstudio/gpt4free
feat: track Azure model failures; stop unlinking auth cache
- g4f/Provider/needs_auth/Azure.py: add class attribute failed: dict[str, int] = {} - g4f/Provider/needs_auth/Azure.py: before creating async generator, raise MissingAuthError if failed[model] >= 3 - g4f/Provider/needs_auth/Azure.py: on MissingAuthError, increment failed[model] and re-raise with message - g4f/providers/base_provider.py (AsyncAuthedProvider): comment out cache_file.unlink() in the branch following JSON dump handling - g4f/providers/base_provider.py (AsyncAuthedProvider): comment out cache_file.unlink() in exception handler for (MissingAuthError, NoValidHarFileError, CloudflareError) before re-authentication
2cf62a8e
代码差异
2 个文件
+8
-4
@@ -37,6 +37,7 @@ class Azure(OpenaiTemplate):
37
37
}
38
38
}
39
39
api_keys: dict[str, str] = {}
40
failed: dict[str, int] = {}
40
41
41
42
@classmethod
42
43
def get_models(cls, api_key: str = None, **kwargs) -> list[str]:
@@ -131,6 +132,8 @@ class Azure(OpenaiTemplate):
131
132
stream = False
132
133
if stream:
133
134
kwargs.setdefault("stream_options", {"include_usage": True})
135
if cls.failed.get(model, 0) >= 3:
136
raise MissingAuthError(f"Model {model} has failed too many times.")
134
137
try:
135
138
async for chunk in super().create_async_generator(
136
139
model=model,
@@ -143,4 +146,5 @@ class Azure(OpenaiTemplate):
143
146
):
144
147
yield chunk
145
148
except MissingAuthError as e:
149
cls.failed[model] = cls.failed.get(model, 0) + 1
146
150
raise MissingAuthError(f"{e}. Ask for help in the {cls.login_url} Discord server.") from e
@@ -444,8 +444,8 @@ class AsyncAuthedProvider(AsyncGeneratorProvider, AuthFileMixin):
444
444
json.dump(auth_result, cache_file, default=toJSON)
445
445
except TypeError as e:
446
446
raise RuntimeError(f"Failed to save: {auth_result.get_dict()}\n{type(e).__name__}: {e}")
447
elif cache_file.exists():
448
cache_file.unlink()
447
# elif cache_file.exists():
448
# cache_file.unlink()
449
449
450
450
@classmethod
451
451
def get_auth_result(cls) -> AuthResult:
@@ -503,8 +503,8 @@ class AsyncAuthedProvider(AsyncGeneratorProvider, AuthFileMixin):
503
503
async for chunk in response:
504
504
yield chunk
505
505
except (MissingAuthError, NoValidHarFileError, CloudflareError):
506
if cache_file.exists():
507
cache_file.unlink()
506
# if cache_file.exists():
507
# cache_file.unlink()
508
508
response = cls.on_auth_async(**kwargs)
509
509
async for chunk in response:
510
510
if isinstance(chunk, AuthResult):