返回提交历史
Modified
g4f/client/__init__.py
+1
-1
Modified
g4f/gui/server/backend_api.py
+2
-2
Modified
g4f/providers/base_provider.py
+0
-4
Modified
g4f/providers/helper.py
+2
-1
XFEstudio/gpt4free
Enhance provider handling by adding JsonResponse support and removing redundant model checks
1786290c
代码差异
4 个文件
+5
-8
@@ -861,8 +861,8 @@ class ClientFactory:
861
861
else:
862
862
if not cls._live_providers:
863
863
path = Path(get_cookies_dir()) / "models" / datetime.today().strftime('%Y-%m-%d') / f"providers.json"
864
path.parent.mkdir(parents=True, exist_ok=True)
864
865
if path.exists():
865
path.parent.mkdir(parents=True, exist_ok=True)
866
866
with open(path, "r", encoding="utf-8") as f:
867
867
cls._live_providers = json.load(f)
868
868
cls._live_providers = requests.get(cls._live_providers_url).json()
@@ -38,7 +38,7 @@ except ImportError:
38
38
39
39
from ...client.service import convert_to_provider
40
40
from ...providers.asyncio import to_sync_generator
41
from ...providers.response import FinishReason, AudioResponse, MediaResponse, Reasoning, HiddenResponse
41
from ...providers.response import FinishReason, AudioResponse, MediaResponse, Reasoning, HiddenResponse, JsonResponse
42
42
from ...client.helper import filter_markdown
43
43
from ...tools.files import supports_filename, get_streaming, get_bucket_dir, get_tempfile
44
44
from ...tools.run_tools import iter_run_tools
@@ -312,7 +312,7 @@ class Backend_Api(Api):
312
312
parameters["audio"] = {}
313
313
def cast_str(response):
314
314
buffer = next(response)
315
while isinstance(buffer, (Reasoning, HiddenResponse)):
315
while isinstance(buffer, (Reasoning, HiddenResponse, JsonResponse)):
316
316
buffer = next(response)
317
317
if isinstance(buffer, MediaResponse):
318
318
if len(buffer.get_list()) == 1:
@@ -401,10 +401,6 @@ class ProviderModelMixin:
401
401
return selected_model
402
402
debug.log(f"{cls.__name__}: Using model '{alias}' for alias '{model}'")
403
403
return alias
404
if model not in cls.model_aliases.values():
405
if model not in cls.get_models(**kwargs) and cls.models:
406
raise ModelNotFoundError(f"Model not found: {model} in: {cls.__name__} Valid models: {cls.models}")
407
cls.last_model = model
408
404
return model
409
405
410
406
class RaiseErrorMixin():
@@ -6,6 +6,7 @@ from pathlib import Path
6
6
7
7
from ..typing import Messages, Cookies, AsyncIterator, Iterator
8
8
from ..tools.files import get_bucket_dir, read_bucket
9
from .response import JsonResponse, HiddenResponse
9
10
from .. import debug
10
11
11
12
def to_string(value) -> str:
@@ -154,7 +155,7 @@ async def async_concat_chunks(chunks: AsyncIterator) -> str:
154
155
def concat_chunks(chunks: Iterator) -> str:
155
156
return "".join([
156
157
str(chunk) for chunk in chunks
157
if chunk and not isinstance(chunk, Exception)
158
if chunk and not isinstance(chunk, (JsonResponse, HiddenResponse, Exception))
158
159
])
159
160
160
161
def format_cookies(cookies: Cookies) -> str: