mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-06 02:30:41 -08:00
Add AiAsk, Chatgpt4Online, ChatgptDemo
and ChatgptX Provider Fix Bing, Liaobots and ChatgptAi Provider Add "gpt_35_long" model and custom timeout
This commit is contained in:
parent
0bd5730bcd
commit
88d2cbff09
34 changed files with 717 additions and 177 deletions
|
|
@ -2,8 +2,7 @@ from __future__ import annotations
|
|||
|
||||
import json
|
||||
|
||||
from curl_cffi.requests import AsyncSession
|
||||
|
||||
from ..requests import StreamSession
|
||||
from ..typing import AsyncGenerator
|
||||
from .base_provider import AsyncGeneratorProvider, format_prompt
|
||||
|
||||
|
|
@ -12,7 +11,6 @@ class You(AsyncGeneratorProvider):
|
|||
url = "https://you.com"
|
||||
working = True
|
||||
supports_gpt_35_turbo = True
|
||||
supports_stream = False
|
||||
|
||||
|
||||
@classmethod
|
||||
|
|
@ -21,20 +19,21 @@ class You(AsyncGeneratorProvider):
|
|||
model: str,
|
||||
messages: list[dict[str, str]],
|
||||
proxy: str = None,
|
||||
timeout: int = 30,
|
||||
**kwargs,
|
||||
) -> AsyncGenerator:
|
||||
async with AsyncSession(proxies={"https": proxy}, impersonate="chrome107") as session:
|
||||
async with StreamSession(proxies={"https": proxy}, impersonate="chrome107", timeout=timeout) as session:
|
||||
headers = {
|
||||
"Accept": "text/event-stream",
|
||||
"Referer": "https://you.com/search?fromSearchBar=true&tbm=youchat",
|
||||
}
|
||||
response = await session.get(
|
||||
async with session.get(
|
||||
"https://you.com/api/streamingSearch",
|
||||
params={"q": format_prompt(messages), "domain": "youchat", "chat": ""},
|
||||
headers=headers
|
||||
)
|
||||
response.raise_for_status()
|
||||
start = 'data: {"youChatToken": '
|
||||
for line in response.text.splitlines():
|
||||
if line.startswith(start):
|
||||
yield json.loads(line[len(start): -1])
|
||||
) as response:
|
||||
response.raise_for_status()
|
||||
start = b'data: {"youChatToken": '
|
||||
async for line in response.iter_lines():
|
||||
if line.startswith(start):
|
||||
yield json.loads(line[len(start):-1])
|
||||
Loading…
Add table
Add a link
Reference in a new issue