diff options
author | AndPim4912 <52836885+AndPim4912@users.noreply.github.com> | 2023-10-23 14:10:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-23 14:10:28 +0200 |
commit | 8d7ad98fcb314453c01f6dcd4bfe59016efd78ce (patch) | |
tree | 4d39804e1aa1724560e1688f0b6d4c124b9771c7 /g4f/Provider/ChatgptFree.py | |
parent | Refactor API initialization to accept a list of ignored providers. (diff) | |
parent | Debug config in api (diff) | |
download | gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.gz gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.bz2 gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.lz gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.xz gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.zst gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.zip |
Diffstat (limited to 'g4f/Provider/ChatgptFree.py')
-rw-r--r-- | g4f/Provider/ChatgptFree.py | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/g4f/Provider/ChatgptFree.py b/g4f/Provider/ChatgptFree.py index 806ff7cc..1bc6181a 100644 --- a/g4f/Provider/ChatgptFree.py +++ b/g4f/Provider/ChatgptFree.py @@ -31,8 +31,8 @@ class ChatgptFree(AsyncProvider): if not cookies: cookies = get_cookies('chatgptfree.ai') - if not cookies: - raise RuntimeError(f"g4f.provider.{cls.__name__} requires cookies [refresh https://chatgptfree.ai on chrome]") + if not cookies: + raise RuntimeError(f"g4f.provider.{cls.__name__} requires cookies [refresh https://chatgptfree.ai on chrome]") headers = { 'authority': 'chatgptfree.ai', @@ -48,14 +48,14 @@ class ChatgptFree(AsyncProvider): 'sec-fetch-site': 'same-origin', 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36', } - + async with StreamSession( - headers=headers, - cookies=cookies, - impersonate="chrome107", - proxies={"https": proxy}, - timeout=timeout - ) as session: + headers=headers, + cookies=cookies, + impersonate="chrome107", + proxies={"https": proxy}, + timeout=timeout + ) as session: if not cls._nonce: async with session.get(f"{cls.url}/") as response: @@ -67,13 +67,13 @@ class ChatgptFree(AsyncProvider): if not result: raise RuntimeError("No post id found") cls._post_id = result.group(1) - - result = re.search(r'data-nonce="(.*?)"', response) - if not result: + + if result := re.search(r'data-nonce="(.*?)"', response): + cls._nonce = result.group(1) + + else: raise RuntimeError("No nonce found") - - cls._nonce = result.group(1) - + prompt = format_prompt(messages) data = { "_wpnonce": cls._nonce, @@ -83,8 +83,7 @@ class ChatgptFree(AsyncProvider): "message": prompt, "bot_id": "0" } - async with session.post(cls.url + "/wp-admin/admin-ajax.php", - data=data, cookies=cookies) as response: - + async with session.post(f"{cls.url}/wp-admin/admin-ajax.php", data=data, cookies=cookies) as response: + response.raise_for_status() return (await response.json())["data"]
\ No newline at end of file |