mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-11-03 10:30:57 +08:00
* **Provider/Blackbox.py**
* Raise `RateLimitError` when `"You have reached your request limit for the hour"` substring is detected
* **Provider/Copilot.py**
* Convert class to `AsyncGeneratorProvider`; rename `create_completion` → `create_async_generator`
* Swap `curl_cffi.requests.Session` for `AsyncSession`; reduce default timeout to **30 s**
* Fully async websocket flow (`await session.ws_connect`, `await wss.send/recv/close`)
* Emit new response types: `TitleGeneration`, `SourceLink`, aggregated `Sources`
* Track request completion with `done` flag; collect citations in `sources` dict
* **Provider/DuckDuckGo.py**
* Replace `duckduckgo_search.DDGS` with `duckai.DuckAI`
* Change base class to `AbstractProvider`; drop nodriver‑based auth
* **Provider/PollinationsAI.py**
* Re‑build text/audio model lists ensuring uniqueness; remove unused `extra_text_models`
* Fix image seed logic (`i==1` for first retry); propagate streaming `error` field via `ResponseError`
* **Provider/hf_space**
* **New file** `LMArenaProvider.py` implementing async queue/stream client
* Register `LMArenaProvider` in `hf_space/__init__.py`; delete `G4F` import
* **Provider/needs_auth/CopilotAccount.py**
* Inherit order changed to `Copilot, AsyncAuthedProvider`
* Refactor token & cookie propagation; add `cookies_to_dict` helper
* **Provider/needs_auth/OpenaiChat.py**
* Parse reasoning thoughts/summary; yield `Reasoning` responses
* Tighten access‑token validation and nodriver JS evaluations (`return_by_value`)
* Extend `Conversation` with `p` and `thoughts_summary`
* **providers/response.py**
* Add `SourceLink` response class returning single formatted citation link
* **providers/base_provider.py**
* Serialize `AuthResult` with custom `json.dump` to handle non‑serializable fields
* Gracefully skip empty cache files when loading auth data
* **image/copy_images.py**
* Ignore file extensions longer than 4 chars when inferring type
* **requests/__init__.py**
* Use `return_by_value=True` for `navigator.userAgent` extraction
* **models.py**
* Remove `G4F` from model provider lists; update `janus_pro_7b` best providers
* **GUI server/api.py**
* Stream `SuggestedFollowups` to client (`"suggestions"` event)
* **GUI static assets**
* **style.css**: bold chat title, add `.suggestions` styles, remove padding from `.chat-body`
* **chat.v1.js**
* Capture `suggestions` packets, render buttons, and send as quick replies
* Re‑order finish‑reason logic; adjust token count placement and system‑prompt toggling
* **chat-top-panel / footer** interactions updated accordingly
* **gui/client/static/js/chat.v1.js** & **css** further UI refinements (scroll handling, token counting, hide prompt toggle)
* Minor updates across multiple files to match new async interfaces and headers (`userAgent`, `raise_for_status`)
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from typing import AsyncIterator
|
|
|
|
from ..base_provider import AsyncAuthedProvider
|
|
from ..Copilot import Copilot, readHAR, has_nodriver, get_access_token_and_cookies
|
|
from ...providers.response import AuthResult, RequestLogin
|
|
from ...typing import AsyncResult, Messages
|
|
from ...errors import NoValidHarFileError
|
|
from ... import debug
|
|
|
|
class CopilotAccount(Copilot, AsyncAuthedProvider):
|
|
needs_auth = True
|
|
use_nodriver = True
|
|
parent = "Copilot"
|
|
default_model = "Copilot"
|
|
default_vision_model = default_model
|
|
|
|
@classmethod
|
|
async def on_auth_async(cls, proxy: str = None, **kwargs) -> AsyncIterator:
|
|
try:
|
|
cls._access_token, cls._cookies = readHAR(cls.url)
|
|
except NoValidHarFileError as h:
|
|
debug.log(f"Copilot: {h}")
|
|
if has_nodriver:
|
|
yield RequestLogin(cls.label, os.environ.get("G4F_LOGIN_URL", ""))
|
|
cls._access_token, cls._cookies = await get_access_token_and_cookies(cls.url, proxy)
|
|
else:
|
|
raise h
|
|
yield AuthResult(
|
|
api_key=cls._access_token,
|
|
cookies=cls.cookies_to_dict()
|
|
)
|
|
|
|
@classmethod
|
|
async def create_authed(
|
|
cls,
|
|
model: str,
|
|
messages: Messages,
|
|
auth_result: AuthResult,
|
|
**kwargs
|
|
) -> AsyncResult:
|
|
cls._access_token = getattr(auth_result, "api_key")
|
|
cls._cookies = getattr(auth_result, "cookies")
|
|
async for chunk in cls.create_async_generator(model, messages, **kwargs):
|
|
yield chunk
|
|
auth_result.cookies = cls.cookies_to_dict()
|
|
|
|
@classmethod
|
|
def cookies_to_dict(cls):
|
|
return cls._cookies if isinstance(cls._cookies, dict) else {c.name: c.value for c in cls._cookies} |