summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/ChatgptFree.py
diff options
context:
space:
mode:
authorⲘrṨhส∂ow <71973368+MrShadowDev@users.noreply.github.com>2023-10-23 09:46:25 +0200
committerGitHub <noreply@github.com>2023-10-23 09:46:25 +0200
commit3982f39424ea037aca1086d45c6f657b4bfc457c (patch)
tree987290c5dc5822cb0197e789df68488536b1637c /g4f/Provider/ChatgptFree.py
parent~ | g4f `v-0.1.7.5` (diff)
downloadgpt4free-3982f39424ea037aca1086d45c6f657b4bfc457c.tar
gpt4free-3982f39424ea037aca1086d45c6f657b4bfc457c.tar.gz
gpt4free-3982f39424ea037aca1086d45c6f657b4bfc457c.tar.bz2
gpt4free-3982f39424ea037aca1086d45c6f657b4bfc457c.tar.lz
gpt4free-3982f39424ea037aca1086d45c6f657b4bfc457c.tar.xz
gpt4free-3982f39424ea037aca1086d45c6f657b4bfc457c.tar.zst
gpt4free-3982f39424ea037aca1086d45c6f657b4bfc457c.zip
Diffstat (limited to 'g4f/Provider/ChatgptFree.py')
-rw-r--r--g4f/Provider/ChatgptFree.py35
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