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

XFEstudio/gpt4free

Enhance Yupp provider by importing cloudscraper and updating error handling for missing requirements; refactor OpenaiTemplate to use Usage.from_dict for improved data handling

63363c22
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

2 个文件 +8 -5
Modified g4f/Provider/Yupp.py +5 -2
@@ -8,6 +8,7 @@ import uuid
8 8 from concurrent.futures import ThreadPoolExecutor
9 9
10 10 try:
11 import cloudscraper
11 12 from cloudscraper import CloudScraper
12 13 from cloudscraper import create_scraper
13 14 except ImportError:
@@ -17,7 +18,7 @@ from .helper import get_last_user_message
17 18 from .yupp.models import YuppModelManager
18 19 from ..cookies import get_cookies
19 20 from ..debug import log
20 from ..errors import RateLimitError, ProviderException, MissingAuthError
21 from ..errors import RateLimitError, ProviderException, MissingAuthError, MissingRequirementsError
21 22 from ..image import is_accepted_format, to_bytes
22 23 from ..providers.base_provider import AsyncGeneratorProvider, ProviderModelMixin
23 24 from ..providers.response import Reasoning, PlainTextResponse, PreviewResponse, JsonConversation, ImageResponse, \
@@ -34,7 +35,7 @@ _executor = ThreadPoolExecutor(max_workers=10)
34 35
35 36
36 37 def create_scraper():
37 scraper = create_scraper(
38 scraper = cloudscraper.create_scraper(
38 39 browser={
39 40 'browser': 'chrome',
40 41 'platform': 'windows',
@@ -329,6 +330,8 @@ class Yupp(AsyncGeneratorProvider, ProviderModelMixin):
329 330 proxy: str = None,
330 331 **kwargs,
331 332 ) -> AsyncResult:
333 if CloudScraper is None:
334 raise MissingRequirementsError("cloudscraper library is required for Yupp provider | install it via 'pip install cloudscraper'")
332 335 api_key = kwargs.get("api_key")
333 336 if not api_key:
334 337 api_key = get_cookies("yupp.ai", False).get("__Secure-yupp.session-token")
Modified g4f/Provider/template/OpenaiTemplate.py +3 -3
@@ -186,7 +186,7 @@ async def read_response(response: StreamResponse, stream: bool, prompt: str, pro
186 186 if model:
187 187 yield ProviderInfo(**provider_info, model=model)
188 188 if "usage" in data:
189 yield Usage(**data["usage"], cache=response.headers.get("x-cache", "MISS"))
189 yield Usage.from_dict(data["usage"])
190 190 if "conversation" in data:
191 191 yield JsonConversation.from_dict(data["conversation"])
192 192 if "choices" in data:
@@ -241,8 +241,8 @@ async def read_response(response: StreamResponse, stream: bool, prompt: str, pro
241 241 if reasoning_content:
242 242 reasoning = True
243 243 yield Reasoning(reasoning_content)
244 if "usage" in data and data["usage"]:
245 yield Usage(**data["usage"], cache=response.headers.get("x-cache", "MISS"))
244 if "usage" in data and data["usage"] and "total_tokens" in data["usage"]:
245 yield Usage.from_dict(data["usage"])
246 246 if "conversation" in data and data["conversation"]:
247 247 yield JsonConversation.from_dict(data["conversation"])
248 248 if choice and choice.get("finish_reason") is not None: