diff options
author | kqlio67 <kqlio67@users.noreply.github.com> | 2024-08-31 08:47:39 +0200 |
---|---|---|
committer | kqlio67 <kqlio67@users.noreply.github.com> | 2024-08-31 08:47:39 +0200 |
commit | f1683c8db83cee5805a6e103fca2c2551aae5086 (patch) | |
tree | 44712b453191566e7ce0877d43a3ed2f807d78b6 /g4f/Provider/ChatgptFree.py | |
parent | Merge pull request #2206 from Parthsadaria/patch-1 (diff) | |
download | gpt4free-f1683c8db83cee5805a6e103fca2c2551aae5086.tar gpt4free-f1683c8db83cee5805a6e103fca2c2551aae5086.tar.gz gpt4free-f1683c8db83cee5805a6e103fca2c2551aae5086.tar.bz2 gpt4free-f1683c8db83cee5805a6e103fca2c2551aae5086.tar.lz gpt4free-f1683c8db83cee5805a6e103fca2c2551aae5086.tar.xz gpt4free-f1683c8db83cee5805a6e103fca2c2551aae5086.tar.zst gpt4free-f1683c8db83cee5805a6e103fca2c2551aae5086.zip |
Diffstat (limited to 'g4f/Provider/ChatgptFree.py')
-rw-r--r-- | g4f/Provider/ChatgptFree.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/g4f/Provider/ChatgptFree.py b/g4f/Provider/ChatgptFree.py index 3cf363a5..95efa865 100644 --- a/g4f/Provider/ChatgptFree.py +++ b/g4f/Provider/ChatgptFree.py @@ -43,6 +43,7 @@ class ChatgptFree(AsyncGeneratorProvider, ProviderModelMixin): '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, @@ -55,6 +56,12 @@ class ChatgptFree(AsyncGeneratorProvider, ProviderModelMixin): async with session.get(f"{cls.url}/") as response: await raise_for_status(response) response = await response.text() + + result = re.search(r'data-post-id="([0-9]+)"', response) + if not result: + raise RuntimeError("No post id found") + cls._post_id = result.group(1) + result = re.search(r'data-nonce="(.*?)"', response) if result: cls._nonce = result.group(1) @@ -70,7 +77,7 @@ class ChatgptFree(AsyncGeneratorProvider, ProviderModelMixin): "message": prompt, "bot_id": "0" } - + async with session.post(f"{cls.url}/wp-admin/admin-ajax.php", data=data, cookies=cookies) as response: await raise_for_status(response) buffer = "" @@ -96,4 +103,4 @@ class ChatgptFree(AsyncGeneratorProvider, ProviderModelMixin): if 'data' in json_response: yield json_response['data'] except json.JSONDecodeError: - print(f"Failed to decode final JSON. Buffer content: {buffer}")
\ No newline at end of file + print(f"Failed to decode final JSON. Buffer content: {buffer}") |