forked from xtekky/gpt4free
-
Notifications
You must be signed in to change notification settings - Fork 0
/
You.py
40 lines (34 loc) · 1.29 KB
/
You.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from __future__ import annotations
import json
from ..requests import StreamSession
from ..typing import AsyncGenerator, Messages
from .base_provider import AsyncGeneratorProvider, format_prompt
class You(AsyncGeneratorProvider):
url = "https://you.com"
working = True
supports_gpt_35_turbo = True
@classmethod
async def create_async_generator(
cls,
model: str,
messages: Messages,
proxy: str = None,
timeout: int = 120,
**kwargs,
) -> AsyncGenerator:
async with StreamSession(proxies={"https": proxy}, impersonate="chrome107", timeout=timeout) as session:
headers = {
"Accept": "text/event-stream",
"Referer": f"{cls.url}/search?fromSearchBar=true&tbm=youchat",
}
data = {"q": format_prompt(messages), "domain": "youchat", "chat": ""}
async with session.get(
f"{cls.url}/api/streamingSearch",
params=data,
headers=headers
) 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])