diff options
author | zukixa <56563509+zukixa@users.noreply.github.com> | 2024-08-25 10:00:06 +0200 |
---|---|---|
committer | zukixa <56563509+zukixa@users.noreply.github.com> | 2024-08-25 10:00:06 +0200 |
commit | a338ed588397737d3c1be66ee4f15d51c84f1770 (patch) | |
tree | 0de45ef57733bfb8c3c38e74dddabeb697ee445a /g4f/Provider/ChatgptFree.py | |
parent | . (diff) | |
download | gpt4free-a338ed588397737d3c1be66ee4f15d51c84f1770.tar gpt4free-a338ed588397737d3c1be66ee4f15d51c84f1770.tar.gz gpt4free-a338ed588397737d3c1be66ee4f15d51c84f1770.tar.bz2 gpt4free-a338ed588397737d3c1be66ee4f15d51c84f1770.tar.lz gpt4free-a338ed588397737d3c1be66ee4f15d51c84f1770.tar.xz gpt4free-a338ed588397737d3c1be66ee4f15d51c84f1770.tar.zst gpt4free-a338ed588397737d3c1be66ee4f15d51c84f1770.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/Provider/ChatgptFree.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/g4f/Provider/ChatgptFree.py b/g4f/Provider/ChatgptFree.py index b1e00a22..11b2e5f5 100644 --- a/g4f/Provider/ChatgptFree.py +++ b/g4f/Provider/ChatgptFree.py @@ -1,6 +1,7 @@ from __future__ import annotations import re +import json from ..requests import StreamSession, raise_for_status from ..typing import Messages @@ -74,6 +75,10 @@ class ChatgptFree(AsyncProvider): "message": prompt, "bot_id": "0" } - async with session.post(f"{cls.url}/wp-admin/admin-ajax.php", data=data, cookies=cookies) as response: + async with session.get(f"{cls.url}/wp-admin/admin-ajax.php", params=data, cookies=cookies) as response: await raise_for_status(response) - return (await response.json())["data"]
\ No newline at end of file + full_answer = "" + for line in ((await response.text()).splitlines())[:-1]: + if line.startswith("data:") and "[DONE]" not in line: + full_answer += json.loads(line[5:])['choices'][0]['delta'].get('content', "") + return full_answer
\ No newline at end of file |