返回提交历史
Deleted
g4f/Provider/ChatgptNext.py
+0
-66
XFEstudio/gpt4free
Delete g4f/Provider/ChatgptNext.py
8b8a0d93
代码差异
1 个文件
+0
-66
@@ -1,66 +0,0 @@
1
from __future__ import annotations
2
3
import json
4
from aiohttp import ClientSession
5
6
from ..typing import AsyncResult, Messages
7
from .base_provider import AsyncGeneratorProvider
8
9
class ChatgptNext(AsyncGeneratorProvider):
10
url = "https://www.chatgpt-free.cc"
11
working = True
12
supports_gpt_35_turbo = True
13
supports_message_history = True
14
supports_system_message = True
15
16
@classmethod
17
async def create_async_generator(
18
cls,
19
model: str,
20
messages: Messages,
21
proxy: str = None,
22
max_tokens: int = None,
23
temperature: float = 0.7,
24
top_p: float = 1,
25
presence_penalty: float = 0,
26
frequency_penalty: float = 0,
27
**kwargs
28
) -> AsyncResult:
29
if not model:
30
model = "gpt-3.5-turbo"
31
headers = {
32
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0",
33
"Accept": "text/event-stream",
34
"Accept-Language": "de,en-US;q=0.7,en;q=0.3",
35
"Accept-Encoding": "gzip, deflate, br",
36
"Content-Type": "application/json",
37
"Referer": "https://chat.fstha.com/",
38
"x-requested-with": "XMLHttpRequest",
39
"Origin": "https://chat.fstha.com",
40
"Sec-Fetch-Dest": "empty",
41
"Sec-Fetch-Mode": "cors",
42
"Sec-Fetch-Site": "same-origin",
43
"Authorization": "Bearer ak-chatgpt-nice",
44
"Connection": "keep-alive",
45
"Alt-Used": "chat.fstha.com",
46
}
47
async with ClientSession(headers=headers) as session:
48
data = {
49
"messages": messages,
50
"stream": True,
51
"model": model,
52
"temperature": temperature,
53
"presence_penalty": presence_penalty,
54
"frequency_penalty": frequency_penalty,
55
"top_p": top_p,
56
"max_tokens": max_tokens,
57
}
58
async with session.post(f"https://chat.fstha.com/api/openai/v1/chat/completions", json=data, proxy=proxy) as response:
59
response.raise_for_status()
60
async for chunk in response.content:
61
if chunk.startswith(b"data: [DONE]"):
62
break
63
if chunk.startswith(b"data: "):
64
content = json.loads(chunk[6:])["choices"][0]["delta"].get("content")
65
if content:
66
yield content