From f1b6880f7e996481650cdd4ec1e5173804ddc083 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Mon, 25 Sep 2023 15:52:19 +0200 Subject: Add Myshell Provider Remove auto proxy prefix --- g4f/Provider/OpenaiChat.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'g4f/Provider/OpenaiChat.py') 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: -- cgit v1.2.3