From 88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Thu, 5 Oct 2023 05:13:37 +0200 Subject: Add AiAsk, Chatgpt4Online, ChatgptDemo and ChatgptX Provider Fix Bing, Liaobots and ChatgptAi Provider Add "gpt_35_long" model and custom timeout --- g4f/Provider/You.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'g4f/Provider/You.py') diff --git a/g4f/Provider/You.py b/g4f/Provider/You.py index 4f49f15e..4afe1ef6 100644 --- a/g4f/Provider/You.py +++ b/g4f/Provider/You.py @@ -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]) \ 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 -- cgit v1.2.3 From 6401084fd0d23b75a883888f70cd705e4cacd202 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sun, 8 Oct 2023 13:59:56 +0200 Subject: Add Messages and AsyncResult typing Add system_message in Yqcloud --- g4f/Provider/You.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'g4f/Provider/You.py') diff --git a/g4f/Provider/You.py b/g4f/Provider/You.py index 4afe1ef6..1afd18be 100644 --- a/g4f/Provider/You.py +++ b/g4f/Provider/You.py @@ -3,7 +3,7 @@ from __future__ import annotations import json from ..requests import StreamSession -from ..typing import AsyncGenerator +from ..typing import AsyncGenerator, Messages from .base_provider import AsyncGeneratorProvider, format_prompt @@ -17,19 +17,20 @@ class You(AsyncGeneratorProvider): async def create_async_generator( cls, model: str, - messages: list[dict[str, str]], + messages: Messages, proxy: str = None, - timeout: int = 30, + timeout: int = 120, **kwargs, ) -> AsyncGenerator: 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", } + data = {"q": format_prompt(messages), "domain": "youchat", "chat": ""} async with session.get( - "https://you.com/api/streamingSearch", - params={"q": format_prompt(messages), "domain": "youchat", "chat": ""}, + f"{cls.url}/api/streamingSearch", + params=data, headers=headers ) as response: response.raise_for_status() -- cgit v1.2.3