summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/ChatForAi.py
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-10-14 15:36:47 +0200
committerGitHub <noreply@github.com>2023-10-14 15:36:47 +0200
commit8bdbb9e9cda7901c3bfc23de2f9f44b3f2e3d1e5 (patch)
tree5f205c79c060098f056a9e1460b872696de5871c /g4f/Provider/ChatForAi.py
parentMerge branch 'main' of https://github.com/xtekky/gpt4free (diff)
parentFix Opchatgpts and ChatForAi Provider (diff)
downloadgpt4free-8bdbb9e9cda7901c3bfc23de2f9f44b3f2e3d1e5.tar
gpt4free-8bdbb9e9cda7901c3bfc23de2f9f44b3f2e3d1e5.tar.gz
gpt4free-8bdbb9e9cda7901c3bfc23de2f9f44b3f2e3d1e5.tar.bz2
gpt4free-8bdbb9e9cda7901c3bfc23de2f9f44b3f2e3d1e5.tar.lz
gpt4free-8bdbb9e9cda7901c3bfc23de2f9f44b3f2e3d1e5.tar.xz
gpt4free-8bdbb9e9cda7901c3bfc23de2f9f44b3f2e3d1e5.tar.zst
gpt4free-8bdbb9e9cda7901c3bfc23de2f9f44b3f2e3d1e5.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