summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/You.py
diff options
context:
space:
mode:
Diffstat (limited to 'g4f/Provider/You.py')
-rw-r--r--g4f/Provider/You.py37
1 files changed, 26 insertions, 11 deletions
diff --git a/g4f/Provider/You.py b/g4f/Provider/You.py
index e90365ce..a9e7834c 100644
--- a/g4f/Provider/You.py
+++ b/g4f/Provider/You.py
@@ -8,19 +8,22 @@ import uuid
from ..typing import AsyncResult, Messages, ImageType, Cookies
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
from .helper import format_prompt
-from ..image import ImageResponse, to_bytes, is_accepted_format
+from ..image import ImageResponse, ImagePreview, to_bytes, is_accepted_format
from ..requests import StreamSession, FormData, raise_for_status
from .you.har_file import get_telemetry_ids
from .. import debug
class You(AsyncGeneratorProvider, ProviderModelMixin):
+ label = "You.com"
url = "https://you.com"
working = True
supports_gpt_35_turbo = True
supports_gpt_4 = True
default_model = "gpt-3.5-turbo"
+ default_vision_model = "agent"
+ image_models = ["dall-e"]
models = [
- "gpt-3.5-turbo",
+ default_model,
"gpt-4",
"gpt-4-turbo",
"claude-instant",
@@ -29,7 +32,8 @@ class You(AsyncGeneratorProvider, ProviderModelMixin):
"claude-3-sonnet",
"gemini-pro",
"zephyr",
- "dall-e",
+ default_vision_model,
+ *image_models
]
model_aliases = {
"claude-v2": "claude-2"
@@ -51,7 +55,7 @@ class You(AsyncGeneratorProvider, ProviderModelMixin):
chat_mode: str = "default",
**kwargs,
) -> AsyncResult:
- if image is not None:
+ if image is not None or model == cls.default_vision_model:
chat_mode = "agent"
elif not model or model == cls.default_model:
...
@@ -62,13 +66,18 @@ class You(AsyncGeneratorProvider, ProviderModelMixin):
chat_mode = "custom"
model = cls.get_model(model)
async with StreamSession(
- proxies={"all": proxy},
+ proxy=proxy,
impersonate="chrome",
timeout=(30, timeout)
) as session:
cookies = await cls.get_cookies(session) if chat_mode != "default" else None
-
- upload = json.dumps([await cls.upload_file(session, cookies, to_bytes(image), image_name)]) if image else ""
+ upload = ""
+ if image is not None:
+ upload_file = await cls.upload_file(
+ session, cookies,
+ to_bytes(image), image_name
+ )
+ upload = json.dumps([upload_file])
headers = {
"Accept": "text/event-stream",
"Referer": f"{cls.url}/search?fromSearchBar=true&tbm=youchat",
@@ -102,11 +111,17 @@ class You(AsyncGeneratorProvider, ProviderModelMixin):
if event == "youChatToken" and event in data:
yield data[event]
elif event == "youChatUpdate" and "t" in data and data["t"] is not None:
- match = re.search(r"!\[fig\]\((.+?)\)", data["t"])
- if match:
- yield ImageResponse(match.group(1), messages[-1]["content"])
+ if chat_mode == "create":
+ match = re.search(r"!\[(.+?)\]\((.+?)\)", data["t"])
+ if match:
+ if match.group(1) == "fig":
+ yield ImagePreview(match.group(2), messages[-1]["content"])
+ else:
+ yield ImageResponse(match.group(2), match.group(1))
+ else:
+ yield data["t"]
else:
- yield data["t"]
+ yield data["t"]
@classmethod
async def upload_file(cls, client: StreamSession, cookies: Cookies, file: bytes, filename: str = None) -> dict: