summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/ChatgptDemo.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-03-12 02:06:06 +0100
committerGitHub <noreply@github.com>2024-03-12 02:06:06 +0100
commit6ef282de3a3245acbfecd08ae48dba85ff91d031 (patch)
tree0236c9678eea8f9c78ed7c09f3d86eaf3d7c691c /g4f/Provider/ChatgptDemo.py
parentUpdate .gitignore (diff)
downloadgpt4free-6ef282de3a3245acbfecd08ae48dba85ff91d031.tar
gpt4free-6ef282de3a3245acbfecd08ae48dba85ff91d031.tar.gz
gpt4free-6ef282de3a3245acbfecd08ae48dba85ff91d031.tar.bz2
gpt4free-6ef282de3a3245acbfecd08ae48dba85ff91d031.tar.lz
gpt4free-6ef282de3a3245acbfecd08ae48dba85ff91d031.tar.xz
gpt4free-6ef282de3a3245acbfecd08ae48dba85ff91d031.tar.zst
gpt4free-6ef282de3a3245acbfecd08ae48dba85ff91d031.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/not_working/ChatgptDemo.py (renamed from g4f/Provider/ChatgptDemo.py)50
1 files changed, 26 insertions, 24 deletions
diff --git a/g4f/Provider/ChatgptDemo.py b/g4f/Provider/not_working/ChatgptDemo.py
index 666b5753..593a2d29 100644
--- a/g4f/Provider/ChatgptDemo.py
+++ b/g4f/Provider/not_working/ChatgptDemo.py
@@ -1,16 +1,17 @@
from __future__ import annotations
-import time, json, re
+import time, json, re, asyncio
from aiohttp import ClientSession
-from ..typing import AsyncResult, Messages
-from .base_provider import AsyncGeneratorProvider
-from .helper import format_prompt
+from ...typing import AsyncResult, Messages
+from ...errors import RateLimitError
+from ..base_provider import AsyncGeneratorProvider
+from ..helper import format_prompt
class ChatgptDemo(AsyncGeneratorProvider):
- url = "https://chat.chatgptdemo.net"
- supports_gpt_35_turbo = True
+ url = "https://chatgptdemo.info/chat"
working = False
+ supports_gpt_35_turbo = True
@classmethod
async def create_async_generator(
@@ -21,10 +22,10 @@ class ChatgptDemo(AsyncGeneratorProvider):
**kwargs
) -> AsyncResult:
headers = {
- "authority": "chat.chatgptdemo.net",
- "accept-language": "de-DE,de;q=0.9,en-DE;q=0.8,en;q=0.7,en-US",
- "origin": "https://chat.chatgptdemo.net",
- "referer": "https://chat.chatgptdemo.net/",
+ "authority": "chatgptdemo.info",
+ "accept-language": "en-US",
+ "origin": "https://chatgptdemo.info",
+ "referer": "https://chatgptdemo.info/chat/",
"sec-ch-ua": '"Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Linux"',
@@ -36,28 +37,29 @@ class ChatgptDemo(AsyncGeneratorProvider):
async with ClientSession(headers=headers) as session:
async with session.get(f"{cls.url}/", proxy=proxy) as response:
response.raise_for_status()
- response = await response.text()
-
- result = re.search(
- r'<div id="USERID" style="display: none">(.*?)<\/div>',
- response,
- )
-
- if result:
- user_id = result.group(1)
- else:
- raise RuntimeError("No user id found")
- async with session.post(f"{cls.url}/new_chat", json={"user_id": user_id}, proxy=proxy) as response:
+ text = await response.text()
+ result = re.search(
+ r'<div id="USERID" style="display: none">(.*?)<\/div>',
+ text,
+ )
+ if result:
+ user_id = result.group(1)
+ else:
+ raise RuntimeError("No user id found")
+ async with session.post(f"https://chatgptdemo.info/chat/new_chat", json={"user_id": user_id}, proxy=proxy) as response:
response.raise_for_status()
chat_id = (await response.json())["id_"]
if not chat_id:
raise RuntimeError("Could not create new chat")
+ await asyncio.sleep(10)
data = {
"question": format_prompt(messages),
"chat_id": chat_id,
- "timestamp": int(time.time()*1000),
+ "timestamp": int((time.time())*1e3),
}
- async with session.post(f"{cls.url}/chat_api_stream", json=data, proxy=proxy) as response:
+ async with session.post(f"https://chatgptdemo.info/chat/chat_api_stream", json=data, proxy=proxy) as response:
+ if response.status == 429:
+ raise RateLimitError("Rate limit reached")
response.raise_for_status()
async for line in response.content:
if line.startswith(b"data: "):