diff options
author | Tekky <98614666+xtekky@users.noreply.github.com> | 2023-09-25 20:23:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-25 20:23:47 +0200 |
commit | 5bcc82ce1a59901c0be01d96fb049c7f589e7ec5 (patch) | |
tree | 440509180b2c0acda712e0c34d4d0b30617144a5 /g4f/Provider/OpenaiChat.py | |
parent | ~ | Merge pull request #936 from r1di/patch-1 (diff) | |
parent | Add Myshell Provider (diff) | |
download | gpt4free-5bcc82ce1a59901c0be01d96fb049c7f589e7ec5.tar gpt4free-5bcc82ce1a59901c0be01d96fb049c7f589e7ec5.tar.gz gpt4free-5bcc82ce1a59901c0be01d96fb049c7f589e7ec5.tar.bz2 gpt4free-5bcc82ce1a59901c0be01d96fb049c7f589e7ec5.tar.lz gpt4free-5bcc82ce1a59901c0be01d96fb049c7f589e7ec5.tar.xz gpt4free-5bcc82ce1a59901c0be01d96fb049c7f589e7ec5.tar.zst gpt4free-5bcc82ce1a59901c0be01d96fb049c7f589e7ec5.zip |
Diffstat (limited to 'g4f/Provider/OpenaiChat.py')
-rw-r--r-- | g4f/Provider/OpenaiChat.py | 20 |
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: |