返回提交历史
Modified
g4f/Provider/FreeChatgpt.py
+44
-32
Modified
g4f/models.py
+5
-7
XFEstudio/gpt4free
Improve FreeChatgpt Provider
c190d0ea
代码差异
2 个文件
+49
-39
@@ -7,13 +7,9 @@ from ..typing import AsyncResult, Messages
7
7
from .base_provider import AsyncGeneratorProvider
8
8
9
9
10
11
10
models = {
12
"claude-v1":"claude-2.1",
13
"claude-v2":"claude-2.0",
14
"gpt_35_turbo":"gpt-3.5-turbo-1106",
15
"gpt-4":"gpt-4",
16
"gemini-pro":"google-gemini-pro"
11
"claude-v2": "claude-2.0",
12
"gemini-pro": "google-gemini-pro"
17
13
}
18
14
19
15
class FreeChatgpt(AsyncGeneratorProvider):
@@ -31,31 +27,47 @@ class FreeChatgpt(AsyncGeneratorProvider):
31
27
proxy: str = None,
32
28
**kwargs
33
29
) -> AsyncResult:
34
model = models[model] if model in models else "gpt-3.5-turbo-1106"
30
if model in models:
31
model = models[model]
32
elif not model:
33
model = "gpt-3.5-turbo"
35
34
headers = {
36
"Accept": "application/json, text/event-stream",
37
"Content-Type":"application/json",
38
"Accept-Encoding": "gzip, deflate, br",
39
"Accept-Language": "en-US,en;q=0.5",
40
"Host":"free.chatgpt.org.uk",
41
"Referer":f"{cls.url}/",
42
"Origin":f"{cls.url}",
43
"Sec-Fetch-Dest": "empty",
44
"Sec-Fetch-Mode": "cors",
45
"Sec-Fetch-Site": "same-origin",
46
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
47
}
35
"Accept": "application/json, text/event-stream",
36
"Content-Type":"application/json",
37
"Accept-Encoding": "gzip, deflate, br",
38
"Accept-Language": "en-US,en;q=0.5",
39
"Host":"free.chatgpt.org.uk",
40
"Referer":f"{cls.url}/",
41
"Origin":f"{cls.url}",
42
"Sec-Fetch-Dest": "empty",
43
"Sec-Fetch-Mode": "cors",
44
"Sec-Fetch-Site": "same-origin",
45
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
46
}
48
47
async with ClientSession(headers=headers) as session:
49
data = {"messages":messages,"stream":True,"model":model,"temperature":0.5,"presence_penalty":0,"frequency_penalty":0,"top_p":1}
50
async with session.post(f'{cls.url}/api/openai/v1/chat/completions',json=data) as result:
51
async for chunk in result.content:
52
53
line = chunk.decode()
54
if line.startswith("data: [DONE]"):
55
break
56
elif line.startswith("data: "):
57
line = json.loads(line[6:])
58
if(line["choices"]==[]):
59
continue
60
if(line["choices"][0]["delta"].get("content") and line["choices"][0]["delta"]["content"]!=None):
61
yield line["choices"][0]["delta"]["content"]
48
data = {
49
"messages":messages,
50
"stream":True,
51
"model":model,
52
"temperature":0.5,
53
"presence_penalty":0,
54
"frequency_penalty":0,
55
"top_p":1,
56
**kwargs
57
}
58
async with session.post(f'{cls.url}/api/openai/v1/chat/completions', json=data, proxy=proxy) as response:
59
response.raise_for_status()
60
started = False
61
async for line in response.content:
62
if line.startswith(b"data: [DONE]"):
63
break
64
elif line.startswith(b"data: "):
65
line = json.loads(line[6:])
66
if(line["choices"]==[]):
67
continue
68
chunk = line["choices"][0]["delta"].get("content")
69
if chunk:
70
started = True
71
yield chunk
72
if not started:
73
raise RuntimeError("Empty response")
@@ -4,6 +4,7 @@ from .Provider import RetryProvider, ProviderType
4
4
from .Provider import (
5
5
Chatgpt4Online,
6
6
ChatgptDemoAi,
7
GeminiProChat,
7
8
ChatgptNext,
8
9
HuggingChat,
9
10
ChatgptDemo,
@@ -61,7 +62,6 @@ gpt_35_long = Model(
61
62
ChatgptNext,
62
63
ChatgptDemo,
63
64
Gpt6,
64
FreeChatgpt,
65
65
])
66
66
)
67
67
@@ -70,7 +70,6 @@ gpt_35_turbo = Model(
70
70
name = 'gpt-3.5-turbo',
71
71
base_provider = 'openai',
72
72
best_provider=RetryProvider([
73
FreeChatgpt,
74
73
GptGo, You,
75
74
GptForLove, ChatBase,
76
75
Chatgpt4Online,
@@ -81,7 +80,7 @@ gpt_4 = Model(
81
80
name = 'gpt-4',
82
81
base_provider = 'openai',
83
82
best_provider = RetryProvider([
84
Bing, FreeChatgpt, Phind, Liaobots,
83
Bing, Phind, Liaobots,
85
84
])
86
85
)
87
86
@@ -159,12 +158,12 @@ claude_instant_v1 = Model(
159
158
claude_v1 = Model(
160
159
name = 'claude-v1',
161
160
base_provider = 'anthropic',
162
best_provider = RetryProvider([FreeChatgpt,Vercel]))
161
best_provider = Vercel)
163
162
164
163
claude_v2 = Model(
165
164
name = 'claude-v2',
166
165
base_provider = 'anthropic',
167
best_provider = RetryProvider([FreeChatgpt,Vercel]))
166
best_provider = RetryProvider([FreeChatgpt, Vercel]))
168
167
169
168
command_light_nightly = Model(
170
169
name = 'command-light-nightly',
@@ -246,11 +245,10 @@ gpt_4_32k_0613 = Model(
246
245
best_provider = gpt_4.best_provider
247
246
)
248
247
249
#Gemini
250
248
gemini_pro = Model(
251
249
name = 'gemini-pro',
252
250
base_provider = 'google',
253
best_provider = FreeChatgpt
251
best_provider = RetryProvider([FreeChatgpt, GeminiProChat])
254
252
)
255
253
256
254
text_ada_001 = Model(