2023-09-03 11:26:26 +03:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2023-08-28 02:43:45 +03:00
|
|
|
import json
|
2023-07-28 13:07:17 +03:00
|
|
|
|
2023-09-12 01:47:03 +03:00
|
|
|
from curl_cffi.requests import AsyncSession
|
2023-09-03 11:26:26 +03:00
|
|
|
|
2023-08-28 02:43:45 +03:00
|
|
|
from ..typing import AsyncGenerator
|
2023-09-12 01:47:03 +03:00
|
|
|
from .base_provider import AsyncGeneratorProvider, format_prompt
|
2023-07-28 13:07:17 +03:00
|
|
|
|
|
|
|
|
2023-08-28 02:43:45 +03:00
|
|
|
class You(AsyncGeneratorProvider):
|
|
|
|
url = "https://you.com"
|
|
|
|
working = True
|
2023-07-28 13:07:17 +03:00
|
|
|
supports_gpt_35_turbo = True
|
2023-09-12 01:47:03 +03:00
|
|
|
supports_stream = False
|
2023-07-28 13:07:17 +03:00
|
|
|
|
2023-09-12 01:47:03 +03:00
|
|
|
|
|
|
|
@classmethod
|
2023-08-28 02:43:45 +03:00
|
|
|
async def create_async_generator(
|
2023-09-12 01:47:03 +03:00
|
|
|
cls,
|
2023-07-28 13:07:17 +03:00
|
|
|
model: str,
|
|
|
|
messages: list[dict[str, str]],
|
2023-09-12 01:47:03 +03:00
|
|
|
proxy: str = None,
|
2023-08-28 02:43:45 +03:00
|
|
|
**kwargs,
|
|
|
|
) -> AsyncGenerator:
|
2023-09-12 01:47:03 +03:00
|
|
|
async with AsyncSession(proxies={"https": proxy}, impersonate="chrome107") as session:
|
|
|
|
headers = {
|
|
|
|
"Accept": "text/event-stream",
|
|
|
|
"Referer": "https://you.com/search?fromSearchBar=true&tbm=youchat",
|
|
|
|
}
|
|
|
|
response = await session.get(
|
2023-08-28 02:43:45 +03:00
|
|
|
"https://you.com/api/streamingSearch",
|
|
|
|
params={"q": format_prompt(messages), "domain": "youchat", "chat": ""},
|
2023-09-12 01:47:03 +03:00
|
|
|
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])
|