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-10-05 06:13:37 +03:00
|
|
|
from ..requests import StreamSession
|
2023-10-08 14:59:56 +03:00
|
|
|
from ..typing import AsyncGenerator, Messages
|
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
|
|
|
|
|
|
|
@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,
|
2023-10-08 14:59:56 +03:00
|
|
|
messages: Messages,
|
2023-09-12 01:47:03 +03:00
|
|
|
proxy: str = None,
|
2023-10-08 14:59:56 +03:00
|
|
|
timeout: int = 120,
|
2023-08-28 02:43:45 +03:00
|
|
|
**kwargs,
|
|
|
|
) -> AsyncGenerator:
|
2023-10-05 06:13:37 +03:00
|
|
|
async with StreamSession(proxies={"https": proxy}, impersonate="chrome107", timeout=timeout) as session:
|
2023-09-12 01:47:03 +03:00
|
|
|
headers = {
|
|
|
|
"Accept": "text/event-stream",
|
2023-10-08 14:59:56 +03:00
|
|
|
"Referer": f"{cls.url}/search?fromSearchBar=true&tbm=youchat",
|
2023-09-12 01:47:03 +03:00
|
|
|
}
|
2023-10-08 14:59:56 +03:00
|
|
|
data = {"q": format_prompt(messages), "domain": "youchat", "chat": ""}
|
2023-10-05 06:13:37 +03:00
|
|
|
async with session.get(
|
2023-10-08 14:59:56 +03:00
|
|
|
f"{cls.url}/api/streamingSearch",
|
|
|
|
params=data,
|
2023-09-12 01:47:03 +03:00
|
|
|
headers=headers
|
2023-10-05 06:13:37 +03:00
|
|
|
) 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])
|