summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/OpenaiChat.py
diff options
context:
space:
mode:
Diffstat (limited to 'g4f/Provider/OpenaiChat.py')
-rw-r--r--g4f/Provider/OpenaiChat.py20
1 files changed, 7 insertions, 13 deletions
diff --git a/g4f/Provider/OpenaiChat.py b/g4f/Provider/OpenaiChat.py
index cbe886f0..f7dc8298 100644
--- a/g4f/Provider/OpenaiChat.py
+++ b/g4f/Provider/OpenaiChat.py
@@ -25,14 +25,7 @@ class OpenaiChat(AsyncProvider):
cookies: dict = None,
**kwargs: dict
) -> AsyncGenerator:
- proxies = None
- if proxy:
- if "://" not in proxy:
- proxy = f"http://{proxy}"
- proxies = {
- "http": proxy,
- "https": proxy
- }
+ proxies = {"https": proxy}
if not access_token:
access_token = await cls.get_access_token(cookies, proxies)
headers = {
@@ -61,15 +54,16 @@ class OpenaiChat(AsyncProvider):
for line in response.content.decode().splitlines():
if line.startswith("data: "):
line = line[6:]
- if line != "[DONE]":
- line = json.loads(line)
- if "message" in line:
- last_message = line["message"]["content"]["parts"][0]
+ if line == "[DONE]":
+ break
+ line = json.loads(line)
+ if "message" in line:
+ last_message = line["message"]["content"]["parts"][0]
return last_message
@classmethod
- async def get_access_token(cls, cookies: dict = None, proxies: dict = None):
+ async def get_access_token(cls, cookies: dict = None, proxies: dict = None) -> str:
if not cls._access_token:
cookies = cookies if cookies else get_cookies("chat.openai.com")
async with AsyncSession(proxies=proxies, cookies=cookies, impersonate="chrome107") as session: