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

XFEstudio/gpt4free

Improve Yupp provider account handling and request timeout

Refactored account loading to preserve account history and error counts when updating tokens. Enhanced request logic to support custom timeouts using aiohttp's ClientTimeout, allowing for more flexible timeout configuration.

7eb1d1a4
Ammar <ammar.alkotb@gmail.com>
提交于

代码差异

1 个文件 +16 -7
Modified g4f/Provider/Yupp.py +16 -7
@@ -6,7 +6,7 @@ import re
6 6 import os
7 7 import asyncio
8 8 import aiohttp
9 from aiohttp import ClientResponseError
9 from aiohttp import ClientResponseError, ClientTimeout
10 10
11 11 from ..typing import AsyncResult, Messages, Optional, Dict, Any, List
12 12 from ..providers.base_provider import AsyncGeneratorProvider, ProviderModelMixin
@@ -44,15 +44,19 @@ def load_yupp_accounts(tokens_str: str):
44 44 return
45 45
46 46 tokens = [token.strip() for token in tokens_str.split(',') if token.strip()]
47 YUPP_ACCOUNTS = [
48 {
47 # reuse history of accounts
48 old_account = YUPP_ACCOUNTS.copy()
49 YUPP_ACCOUNTS.clear()
50 YUPP_ACCOUNTS.extend([
51 next(filter(lambda x:x.get("token")==token, old_account),
52 {
49 53 "token": token,
50 54 "is_valid": True,
51 55 "error_count": 0,
52 56 "last_used": 0.0
53 }
57 })
54 58 for token in tokens
55 ]
59 ])
56 60
57 61 def create_headers() -> Dict[str, str]:
58 62 """Create headers for requests"""
@@ -390,9 +394,14 @@ class Yupp(AsyncGeneratorProvider, ProviderModelMixin):
390 394
391 395 log_debug(f"Sending request to: {url}")
392 396 log_debug(f"Payload structure: {type(payload)}, length: {len(str(payload))}")
393
397 _timeout = kwargs.get("timeout")
398 if isinstance(_timeout, ClientTimeout):
399 timeout = _timeout
400 else:
401 total = float(_timeout) if isinstance(_timeout, (int, float)) else 5 * 60
402 timeout = ClientTimeout(total=total)
394 403 # Send request
395 async with session.post(url, json=payload, headers=headers, proxy=proxy) as response:
404 async with session.post(url, json=payload, headers=headers, proxy=proxy, timeout=timeout) as response:
396 405 response.raise_for_status()
397 406
398 407 # Make chat private in background