summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/ChatForAi.py
diff options
context:
space:
mode:
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