summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/ChatForAi.py
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner@lohaus.eu>2023-10-14 00:31:48 +0200
committerHeiner Lohaus <heiner@lohaus.eu>2023-10-14 00:31:48 +0200
commit13ffdcd61a5c5cabb1fe293e873a80af8328ea35 (patch)
treee0cd97a0d91073b807e8b599a3e9b83393329064 /g4f/Provider/ChatForAi.py
parentg4f `v-0.1.6.3` (diff)
downloadgpt4free-13ffdcd61a5c5cabb1fe293e873a80af8328ea35.tar
gpt4free-13ffdcd61a5c5cabb1fe293e873a80af8328ea35.tar.gz
gpt4free-13ffdcd61a5c5cabb1fe293e873a80af8328ea35.tar.bz2
gpt4free-13ffdcd61a5c5cabb1fe293e873a80af8328ea35.tar.lz
gpt4free-13ffdcd61a5c5cabb1fe293e873a80af8328ea35.tar.xz
gpt4free-13ffdcd61a5c5cabb1fe293e873a80af8328ea35.tar.zst
gpt4free-13ffdcd61a5c5cabb1fe293e873a80af8328ea35.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/ChatForAi.py (renamed from g4f/Provider/deprecated/ChatForAi.py)33
1 files changed, 25 insertions, 8 deletions
diff --git a/g4f/Provider/deprecated/ChatForAi.py b/g4f/Provider/ChatForAi.py
index ab4cd89c..c93e76ee 100644
--- a/g4f/Provider/deprecated/ChatForAi.py
+++ b/g4f/Provider/ChatForAi.py
@@ -1,12 +1,16 @@
from __future__ import annotations
-from ...typing import AsyncResult, Messages
-from ...requests import StreamSession
-from ..base_provider import AsyncGeneratorProvider
+import time
+import hashlib
+
+from ..typing import AsyncResult, Messages
+from ..requests import StreamSession
+from .base_provider import AsyncGeneratorProvider
class ChatForAi(AsyncGeneratorProvider):
- url = "https://chatforai.com"
+ url = "https://chatforai.store"
+ working = True
supports_gpt_35_turbo = True
@classmethod
@@ -18,10 +22,17 @@ class ChatForAi(AsyncGeneratorProvider):
timeout: int = 120,
**kwargs
) -> AsyncResult:
- async with StreamSession(impersonate="chrome107", proxies={"https": proxy}, timeout=timeout) as session:
+ headers = {
+ "Content-Type": "text/plain;charset=UTF-8",
+ "Origin": cls.url,
+ "Referer": f"{cls.url}/?r=b",
+ }
+ async with StreamSession(impersonate="chrome107", headers=headers, proxies={"https": proxy}, timeout=timeout) as session:
prompt = messages[-1]["content"]
+ timestamp = int(time.time() * 1e3)
+ conversation_id = f"id_{timestamp-123}"
data = {
- "conversationId": "temp",
+ "conversationId": conversation_id,
"conversationType": "chat_continuous",
"botId": "chat_continuous",
"globalSettings":{
@@ -33,8 +44,10 @@ class ChatForAi(AsyncGeneratorProvider):
**kwargs
},
"botSettings": {},
- "prompt": prompt,
+ "prompt": prompt,
"messages": messages,
+ "timestamp": timestamp,
+ "sign": generate_signature(timestamp, prompt, conversation_id)
}
async with session.post(f"{cls.url}/api/handle/provider-openai", json=data) as response:
response.raise_for_status()
@@ -52,4 +65,8 @@ class ChatForAi(AsyncGeneratorProvider):
("stream", "bool"),
]
param = ", ".join([": ".join(p) for p in params])
- return f"g4f.provider.{cls.__name__} supports: ({param})" \ No newline at end of file
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
+
+def generate_signature(timestamp: int, message: str, id: str):
+ buffer = f"{timestamp}:{id}:{message}:7YN8z6d6"
+ return hashlib.sha256(buffer.encode()).hexdigest() \ No newline at end of file