summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/You.py
diff options
context:
space:
mode:
authorCommenter123321 <36051603+Commenter123321@users.noreply.github.com>2023-10-09 18:02:06 +0200
committerCommenter123321 <36051603+Commenter123321@users.noreply.github.com>2023-10-09 18:02:06 +0200
commit119817c96349807efaf87ee432ce46446542b66a (patch)
tree1dbdf4d4dbf4f6c8a8247274ef500a2f1de765d1 /g4f/Provider/You.py
parentaivvm's no life creator keeps patching it, but I'm just better 😉 (diff)
parentMerge branch 'main' of https://github.com/xtekky/gpt4free (diff)
downloadgpt4free-119817c96349807efaf87ee432ce46446542b66a.tar
gpt4free-119817c96349807efaf87ee432ce46446542b66a.tar.gz
gpt4free-119817c96349807efaf87ee432ce46446542b66a.tar.bz2
gpt4free-119817c96349807efaf87ee432ce46446542b66a.tar.lz
gpt4free-119817c96349807efaf87ee432ce46446542b66a.tar.xz
gpt4free-119817c96349807efaf87ee432ce46446542b66a.tar.zst
gpt4free-119817c96349807efaf87ee432ce46446542b66a.zip
Diffstat (limited to 'g4f/Provider/You.py')
-rw-r--r--g4f/Provider/You.py32
1 files changed, 16 insertions, 16 deletions
diff --git a/g4f/Provider/You.py b/g4f/Provider/You.py
index 4f49f15e..1afd18be 100644
--- a/g4f/Provider/You.py
+++ b/g4f/Provider/You.py
@@ -2,9 +2,8 @@ from __future__ import annotations
import json
-from curl_cffi.requests import AsyncSession
-
-from ..typing import AsyncGenerator
+from ..requests import StreamSession
+from ..typing import AsyncGenerator, Messages
from .base_provider import AsyncGeneratorProvider, format_prompt
@@ -12,29 +11,30 @@ class You(AsyncGeneratorProvider):
url = "https://you.com"
working = True
supports_gpt_35_turbo = True
- supports_stream = False
@classmethod
async def create_async_generator(
cls,
model: str,
- messages: list[dict[str, str]],
+ messages: Messages,
proxy: str = None,
+ timeout: int = 120,
**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",
+ "Referer": f"{cls.url}/search?fromSearchBar=true&tbm=youchat",
}
- response = await session.get(
- "https://you.com/api/streamingSearch",
- params={"q": format_prompt(messages), "domain": "youchat", "chat": ""},
+ data = {"q": format_prompt(messages), "domain": "youchat", "chat": ""}
+ async with session.get(
+ f"{cls.url}/api/streamingSearch",
+ params=data,
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]) \ No newline at end of file
+ ) 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]) \ No newline at end of file