From 3982f39424ea037aca1086d45c6f657b4bfc457c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=B2=98r=E1=B9=A8h=E0=B8=AA=E2=88=82ow?= <71973368+MrShadowDev@users.noreply.github.com> Date: Mon, 23 Oct 2023 09:46:25 +0200 Subject: 'Refactored by Sourcery' (#1125) Co-authored-by: Sourcery AI <> --- g4f/Provider/Aichat.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'g4f/Provider/Aichat.py') diff --git a/g4f/Provider/Aichat.py b/g4f/Provider/Aichat.py index d32c99e1..77ae4429 100644 --- a/g4f/Provider/Aichat.py +++ b/g4f/Provider/Aichat.py @@ -20,8 +20,10 @@ class Aichat(AsyncProvider): cookies = get_cookies('chat-gpt.org') if not kwargs.get('cookies') else kwargs.get('cookies') if not cookies: - raise RuntimeError(f"g4f.provider.Aichat requires cookies, [refresh https://chat-gpt.org on chrome]") - + raise RuntimeError( + "g4f.provider.Aichat requires cookies, [refresh https://chat-gpt.org on chrome]" + ) + headers = { 'authority': 'chat-gpt.org', 'accept': '*/*', @@ -37,13 +39,13 @@ class Aichat(AsyncProvider): 'sec-fetch-site': 'same-origin', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36', } - + async with StreamSession(headers=headers, cookies=cookies, timeout=6, proxies={"https": proxy} if proxy else None, impersonate="chrome110", verify=False) as session: - + json_data = { "message": format_prompt(messages), "temperature": kwargs.get('temperature', 0.5), @@ -51,14 +53,14 @@ class Aichat(AsyncProvider): "top_p": kwargs.get('top_p', 1), "frequency_penalty": 0, } - + async with session.post("https://chat-gpt.org/api/text", json=json_data) as response: - + response.raise_for_status() result = await response.json() - + if not result['response']: raise Exception(f"Error Response: {result}") - + return result["message"] -- cgit v1.2.3