diff options
author | Heiner Lohaus <heiner@lohaus.eu> | 2023-09-25 15:52:19 +0200 |
---|---|---|
committer | Heiner Lohaus <heiner@lohaus.eu> | 2023-09-25 15:52:19 +0200 |
commit | f1b6880f7e996481650cdd4ec1e5173804ddc083 (patch) | |
tree | f5bab5bec2232e8b4ebc71213332e5614a940550 /g4f/Provider/OpenaiChat.py | |
parent | ~ (diff) | |
download | gpt4free-f1b6880f7e996481650cdd4ec1e5173804ddc083.tar gpt4free-f1b6880f7e996481650cdd4ec1e5173804ddc083.tar.gz gpt4free-f1b6880f7e996481650cdd4ec1e5173804ddc083.tar.bz2 gpt4free-f1b6880f7e996481650cdd4ec1e5173804ddc083.tar.lz gpt4free-f1b6880f7e996481650cdd4ec1e5173804ddc083.tar.xz gpt4free-f1b6880f7e996481650cdd4ec1e5173804ddc083.tar.zst gpt4free-f1b6880f7e996481650cdd4ec1e5173804ddc083.zip |
Diffstat (limited to '')
-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: |