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.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/g4f/Provider/You.py b/g4f/Provider/You.py
index 6256cda9..cfa2c7bf 100644
--- a/g4f/Provider/You.py
+++ b/g4f/Provider/You.py
@@ -8,8 +8,9 @@ import uuid
from ..typing import AsyncResult, Messages, ImageType, Cookies
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
from .helper import format_prompt
-from ..image import to_bytes, ImageResponse
+from ..image import ImageResponse, to_bytes, is_accepted_format
from ..requests import StreamSession, FormData, raise_for_status
+from ..errors import MissingRequirementsError
from .you.har_file import get_dfp_telemetry_id
@@ -46,6 +47,7 @@ class You(AsyncGeneratorProvider, ProviderModelMixin):
image: ImageType = None,
image_name: str = None,
proxy: str = None,
+ timeout: int = 240,
chat_mode: str = "default",
**kwargs,
) -> AsyncResult:
@@ -55,12 +57,14 @@ class You(AsyncGeneratorProvider, ProviderModelMixin):
...
elif model.startswith("dall-e"):
chat_mode = "create"
+ messages = [messages[-1]]
else:
chat_mode = "custom"
model = cls.get_model(model)
async with StreamSession(
proxies={"all": proxy},
- impersonate="chrome"
+ 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 ""
@@ -73,7 +77,6 @@ class You(AsyncGeneratorProvider, ProviderModelMixin):
"q": format_prompt(messages),
"domain": "youchat",
"selectedChatMode": chat_mode,
- #"chat": json.dumps(chat),
}
params = {
"userFiles": upload,
@@ -113,7 +116,7 @@ class You(AsyncGeneratorProvider, ProviderModelMixin):
await raise_for_status(response)
upload_nonce = await response.text()
data = FormData()
- data.add_field('file', file, filename=filename)
+ data.add_field('file', file, content_type=is_accepted_format(file), filename=filename)
async with client.post(
f"{cls.url}/api/upload",
data=data,