summaryrefslogtreecommitdiffstats
path: root/g4f
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-05-21 22:58:56 +0200
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-05-21 22:58:56 +0200
commit62b2b279ab7f06b14aefb0b3ba09111e004a6003 (patch)
tree30609eb68c513387bd616a14f9cec3b82db6eaff /g4f
parentAdd streaming and conversation support to gemini (diff)
downloadgpt4free-62b2b279ab7f06b14aefb0b3ba09111e004a6003.tar
gpt4free-62b2b279ab7f06b14aefb0b3ba09111e004a6003.tar.gz
gpt4free-62b2b279ab7f06b14aefb0b3ba09111e004a6003.tar.bz2
gpt4free-62b2b279ab7f06b14aefb0b3ba09111e004a6003.tar.lz
gpt4free-62b2b279ab7f06b14aefb0b3ba09111e004a6003.tar.xz
gpt4free-62b2b279ab7f06b14aefb0b3ba09111e004a6003.tar.zst
gpt4free-62b2b279ab7f06b14aefb0b3ba09111e004a6003.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/You.py12
-rw-r--r--g4f/image.py7
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.