From 62b2b279ab7f06b14aefb0b3ba09111e004a6003 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Tue, 21 May 2024 22:58:56 +0200 Subject: Fix image vision in You.com provider --- g4f/Provider/You.py | 12 ++++++++---- g4f/image.py | 7 +++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/g4f/Provider/You.py b/g4f/Provider/You.py index d549423e..162d6adb 100644 --- a/g4f/Provider/You.py +++ b/g4f/Provider/You.py @@ -8,7 +8,7 @@ import uuid from ..typing import AsyncResult, Messages, ImageType, Cookies from .base_provider import AsyncGeneratorProvider, ProviderModelMixin from .helper import format_prompt -from ..image import ImageResponse, ImagePreview, to_bytes, is_accepted_format +from ..image import ImageResponse, ImagePreview, EXTENSIONS_MAP, to_bytes, is_accepted_format from ..requests import StreamSession, FormData, raise_for_status from .you.har_file import get_telemetry_ids from .. import debug @@ -94,6 +94,8 @@ class You(AsyncGeneratorProvider, ProviderModelMixin): "q": format_prompt(messages), "domain": "youchat", "selectedChatMode": chat_mode, + "conversationTurnId": str(uuid.uuid4()), + "chatId": str(uuid.uuid4()), } params = { "userFiles": upload, @@ -106,8 +108,8 @@ class You(AsyncGeneratorProvider, ProviderModelMixin): async with (session.post if chat_mode == "default" else session.get)( f"{cls.url}/api/streamingSearch", - data=data, - params=params, + data=data if chat_mode == "default" else None, + params=params if chat_mode == "default" else data, headers=headers, cookies=cookies ) as response: @@ -142,7 +144,9 @@ class You(AsyncGeneratorProvider, ProviderModelMixin): await raise_for_status(response) upload_nonce = await response.text() data = FormData() - data.add_field('file', file, content_type=is_accepted_format(file), filename=filename) + content_type = is_accepted_format(file) + filename = f"image.{EXTENSIONS_MAP[content_type]}" if filename is None else filename + data.add_field('file', file, content_type=content_type, filename=filename) async with client.post( f"{cls.url}/api/upload", data=data, diff --git a/g4f/image.py b/g4f/image.py index a677e8df..6561b83a 100644 --- a/g4f/image.py +++ b/g4f/image.py @@ -16,6 +16,13 @@ from .errors import MissingRequirementsError ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif', 'webp', 'svg'} +EXTENSIONS_MAP: dict[str, str] = { + "image/png": "png", + "image/jpeg": "jpg", + "image/gif": "gif", + "image/webp": "webp", +} + def to_image(image: ImageType, is_svg: bool = False) -> Image: """ Converts the input image to a PIL Image object. -- cgit v1.2.3