From a338ed588397737d3c1be66ee4f15d51c84f1770 Mon Sep 17 00:00:00 2001 From: zukixa <56563509+zukixa@users.noreply.github.com> Date: Sun, 25 Aug 2024 01:00:06 -0700 Subject: 8 providers improved --- g4f/Provider/ChatgptFree.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'g4f/Provider/ChatgptFree.py') 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 -- cgit v1.2.3