返回提交历史
Modified
g4f/Provider/Copilot.py
+11
-1
Modified
g4f/Provider/needs_auth/Gemini.py
+13
-3
Modified
g4f/providers/any_provider.py
+1
-0
XFEstudio/gpt4free
Disable tool support provider in /v1 route
49e302e5
代码差异
3 个文件
+25
-4
@@ -144,12 +144,22 @@ class Copilot(AsyncAuthedProvider, ProviderModelMixin):
144
144
websocket_url = f"{websocket_url}&accessToken={quote(auth_result.access_token)}" + (f"&X-UserIdentityType={quote(auth_result.useridentitytype)}" if getattr(auth_result, "useridentitytype", None) else "")
145
145
headers["authorization"] = f"Bearer {auth_result.access_token}"
146
146
147
cookies = getattr(auth_result, "cookies", None)
148
if not cookies:
149
# Cached AuthResult from an older version may not have cookies.
150
# Re-run auth to obtain a fresh AuthResult with cookies.
151
async for chunk in cls.on_auth_async(proxy=proxy):
152
if isinstance(chunk, AuthResult):
153
auth_result = chunk
154
cookies = getattr(auth_result, "cookies", None)
155
break
156
cls.write_cache_file(cls.get_cache_file(), auth_result)
147
157
async with AsyncSession(
148
158
timeout=timeout,
149
159
proxy=proxy,
150
160
impersonate="chrome",
151
161
headers=headers,
152
cookies=auth_result.cookies
162
cookies=cookies
153
163
) as session:
154
164
if conversation is None:
155
165
# har_file = os.path.join(os.path.dirname(__file__), "copilot", "copilot.microsoft.com.har")
@@ -81,6 +81,13 @@ REQUEST_HEADERS = {
81
81
),
82
82
"x-same-domain": "1",
83
83
}
84
# Gemini responses occasionally include very large header values (e.g. Set-Cookie
85
# chains or x-goog-* metadata) that exceed aiohttp's default 8190-byte limit.
86
# Raise both the per-line and per-field limits so these responses parse cleanly.
87
RESPONSE_HEADER_LIMITS = {
88
"max_line_size": 64 * 1024,
89
"max_field_size": 64 * 1024,
90
}
84
91
REQUEST_BL_PARAM = "boq_assistant-bard-web-server_20260525.09_p0"
85
92
REQUEST_PATH = "/_/BardChatUi/data/assistant.lamda.BardFrontendService/StreamGenerate"
86
93
UPLOAD_IMAGE_URL = "https://content-push.googleapis.com/upload/"
@@ -409,7 +416,8 @@ class Gemini(AsyncGeneratorProvider, ProviderModelMixin):
409
416
if not cls._cookies:
410
417
raise MissingAuthError('Missing or invalid "__Secure-1PSID" cookie')
411
418
async with ClientSession(
412
headers=REQUEST_HEADERS
419
headers=REQUEST_HEADERS,
420
**RESPONSE_HEADER_LIMITS,
413
421
) as session:
414
422
await cls.fetch_snlm0e(session, cls._cookies)
415
423
return cls._snlm0e
@@ -472,7 +480,8 @@ class Gemini(AsyncGeneratorProvider, ProviderModelMixin):
472
480
473
481
async with ClientSession(
474
482
headers=REQUEST_HEADERS,
475
connector=base_connector
483
connector=base_connector,
484
**RESPONSE_HEADER_LIMITS,
476
485
) as session:
477
486
cookie_key = (
478
487
(cls._cookies or {}).get(GOOGLE_SID_COOKIE),
@@ -745,6 +754,7 @@ class Gemini(AsyncGeneratorProvider, ProviderModelMixin):
745
754
cookies=cls._cookies,
746
755
headers=REQUEST_HEADERS,
747
756
connector=get_connector(proxy=proxy),
757
**RESPONSE_HEADER_LIMITS,
748
758
) as session:
749
759
if not cls._snlm0e:
750
760
await cls.fetch_snlm0e(session, cls._cookies) if cls._cookies else None
@@ -968,7 +978,7 @@ async def rotate_1psidts(url, cookies: dict, proxy: str | None = None) -> str:
968
978
969
979
# Check if the cache file was modified in the last minute to avoid 429 Too Many Requests
970
980
if not (path.is_file() and time.time() - os.path.getmtime(path) <= 60):
971
async with ClientSession(proxy=proxy) as client:
981
async with ClientSession(proxy=proxy, **RESPONSE_HEADER_LIMITS) as client:
972
982
async with client.post(
973
983
url=ROTATE_COOKIES_URL,
974
984
headers={
@@ -411,6 +411,7 @@ class AnyModelProviderMixin(ProviderModelMixin):
411
411
class AnyProvider(AsyncGeneratorProvider, AnyModelProviderMixin):
412
412
working = True
413
413
active_by_default = True
414
supports_native_tools = True
414
415
415
416
@classmethod
416
417
async def create_async_generator(