From 2360cc3330df821711637c9274b4ae154d2f7cc5 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Tue, 7 Jan 2025 00:26:01 +0100 Subject: Fix issue with old conversations --- g4f/Provider/needs_auth/OpenaiChat.py | 4 ++-- g4f/tools/files.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'g4f') diff --git a/g4f/Provider/needs_auth/OpenaiChat.py b/g4f/Provider/needs_auth/OpenaiChat.py index 72465ec2..79aac591 100644 --- a/g4f/Provider/needs_auth/OpenaiChat.py +++ b/g4f/Provider/needs_auth/OpenaiChat.py @@ -351,7 +351,7 @@ class OpenaiChat(AsyncAuthedProvider, ProviderModelMixin): conversation = Conversation(conversation_id, str(uuid.uuid4()), getattr(auth_result, "cookies", {}).get("oai-did")) else: conversation = copy(conversation) - if getattr(auth_result, "cookies", {}).get("oai-did") != conversation.user_id: + if getattr(auth_result, "cookies", {}).get("oai-did") != getattr(conversation, "user_id", None): conversation = Conversation(None, str(uuid.uuid4())) if cls._api_key is None: auto_continue = False @@ -587,7 +587,7 @@ class OpenaiChat(AsyncAuthedProvider, ProviderModelMixin): cookies: Cookies = None, headers: dict = None, **kwargs - ) -> AsyncIterator[str]: + ) -> AsyncIterator: if cls._expires is not None and (cls._expires - 60*10) < time.time(): cls._headers = cls._api_key = None if cls._headers is None or headers is not None: diff --git a/g4f/tools/files.py b/g4f/tools/files.py index 8f10c4b7..d1d45e13 100644 --- a/g4f/tools/files.py +++ b/g4f/tools/files.py @@ -353,7 +353,7 @@ async def get_filename(response: ClientResponse) -> str: sha256_hash = hashlib.sha256(url.encode()).digest() base32_encoded = base64.b32encode(sha256_hash).decode() url_hash = base32_encoded[:24].lower() - return f"{parsed_url.netloc} {parsed_url.path[1:].replace('/', '_')} {url_hash}{extension}" + return f"{parsed_url.netloc}+{parsed_url.path[1:].replace('/', '_')}+{url_hash}{extension}" return None @@ -494,7 +494,7 @@ def read_and_download_urls(bucket_dir: Path, event_stream: bool = False) -> Iter count += 1 yield f'data: {json.dumps({"action": "download", "count": count})}\n\n' -async def async_read_and_download_urls(bucket_dir: Path, event_stream: bool = False) -> Iterator[str]: +async def async_read_and_download_urls(bucket_dir: Path, event_stream: bool = False) -> AsyncIterator[str]: urls = get_downloads_urls(bucket_dir) if urls: count = 0 -- cgit v1.2.3