summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/OpenaiChat.py
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner@lohaus.eu>2023-10-04 03:15:17 +0200
committerHeiner Lohaus <heiner@lohaus.eu>2023-10-04 03:15:17 +0200
commit136770e05b63fd1482665eac5f90eba5bd10e4c5 (patch)
treeaa6803462b92375703bc1189431f6831ccf15bc2 /g4f/Provider/OpenaiChat.py
parentFix fetch_access_token in openai (diff)
downloadgpt4free-136770e05b63fd1482665eac5f90eba5bd10e4c5.tar
gpt4free-136770e05b63fd1482665eac5f90eba5bd10e4c5.tar.gz
gpt4free-136770e05b63fd1482665eac5f90eba5bd10e4c5.tar.bz2
gpt4free-136770e05b63fd1482665eac5f90eba5bd10e4c5.tar.lz
gpt4free-136770e05b63fd1482665eac5f90eba5bd10e4c5.tar.xz
gpt4free-136770e05b63fd1482665eac5f90eba5bd10e4c5.tar.zst
gpt4free-136770e05b63fd1482665eac5f90eba5bd10e4c5.zip
Diffstat (limited to 'g4f/Provider/OpenaiChat.py')
-rw-r--r--g4f/Provider/OpenaiChat.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/g4f/Provider/OpenaiChat.py b/g4f/Provider/OpenaiChat.py
index ca148da2..8f183fb9 100644
--- a/g4f/Provider/OpenaiChat.py
+++ b/g4f/Provider/OpenaiChat.py
@@ -1,7 +1,6 @@
from __future__ import annotations
-import uuid
-import json
+import uuid, json, time
from .base_provider import AsyncGeneratorProvider
from .helper import get_browser, get_cookies, format_prompt
@@ -56,8 +55,13 @@ class OpenaiChat(AsyncGeneratorProvider):
line = line[6:]
if line == b"[DONE]":
break
- line = json.loads(line)
- if "message" in line and not line["message"]["end_turn"]:
+ try:
+ line = json.loads(line)
+ except:
+ continue
+ if "message" not in line or "message_type" not in line["message"]["metadata"]:
+ continue
+ if line["message"]["metadata"]["message_type"] == "next":
new_message = line["message"]["content"]["parts"][0]
yield new_message[len(last_message):]
last_message = new_message
@@ -68,11 +72,9 @@ class OpenaiChat(AsyncGeneratorProvider):
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
- except ImportError:
- return
- driver = get_browser()
- if not driver:
+ driver = get_browser()
+ except ImportError:
return
driver.get(f"{cls.url}/")
@@ -83,6 +85,7 @@ class OpenaiChat(AsyncGeneratorProvider):
javascript = "return (await (await fetch('/api/auth/session')).json())['accessToken']"
return driver.execute_script(javascript)
finally:
+ time.sleep(1)
driver.quit()
@classmethod