返回提交历史
Deleted
g4f/Provider/ChatForAi.py
+0
-66
XFEstudio/gpt4free
Delete g4f/Provider/ChatForAi.py
a857e502
代码差异
1 个文件
+0
-66
@@ -1,66 +0,0 @@
1
from __future__ import annotations
2
3
import time
4
import hashlib
5
import uuid
6
7
from ..typing import AsyncResult, Messages
8
from ..requests import StreamSession, raise_for_status
9
from ..errors import RateLimitError
10
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
11
12
class ChatForAi(AsyncGeneratorProvider, ProviderModelMixin):
13
url = "https://chatforai.store"
14
working = True
15
default_model = "gpt-3.5-turbo"
16
supports_message_history = True
17
supports_gpt_35_turbo = True
18
19
@classmethod
20
async def create_async_generator(
21
cls,
22
model: str,
23
messages: Messages,
24
proxy: str = None,
25
timeout: int = 120,
26
temperature: float = 0.7,
27
top_p: float = 1,
28
**kwargs
29
) -> AsyncResult:
30
model = cls.get_model(model)
31
headers = {
32
"Content-Type": "text/plain;charset=UTF-8",
33
"Origin": cls.url,
34
"Referer": f"{cls.url}/?r=b",
35
}
36
async with StreamSession(impersonate="chrome", headers=headers, proxies={"https": proxy}, timeout=timeout) as session:
37
timestamp = int(time.time() * 1e3)
38
conversation_id = str(uuid.uuid4())
39
data = {
40
"conversationId": conversation_id,
41
"conversationType": "chat_continuous",
42
"botId": "chat_continuous",
43
"globalSettings":{
44
"baseUrl": "https://api.openai.com",
45
"model": model,
46
"messageHistorySize": 5,
47
"temperature": temperature,
48
"top_p": top_p,
49
**kwargs
50
},
51
"prompt": "",
52
"messages": messages,
53
"timestamp": timestamp,
54
"sign": generate_signature(timestamp, "", conversation_id)
55
}
56
async with session.post(f"{cls.url}/api/handle/provider-openai", json=data) as response:
57
await raise_for_status(response)
58
async for chunk in response.iter_content():
59
if b"https://chatforai.store" in chunk:
60
raise RuntimeError(f"Response: {chunk.decode(errors='ignore')}")
61
yield chunk.decode(errors="ignore")
62
63
64
def generate_signature(timestamp: int, message: str, id: str):
65
buffer = f"{id}:{timestamp}:{message}:h496Jd6b"
66
return hashlib.sha256(buffer.encode()).hexdigest()