XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Added support for more models: FreeChatgpt (#1456)

* Improved FreeChatgpt, added support for more models * Added new model: Gemini Pro

42c4a431
Debaditya Banerji <77636021+devAdityaa@users.noreply.github.com>
提交于

代码差异

2 个文件 +50 -47
Modified g4f/Provider/FreeChatgpt.py +35 -42
@@ -7,6 +7,15 @@ from ..typing import AsyncResult, Messages
7 7 from .base_provider import AsyncGeneratorProvider
8 8
9 9
10
11 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"
17 }
18
10 19 class FreeChatgpt(AsyncGeneratorProvider):
11 20 url = "https://free.chatgpt.org.uk"
12 21 working = True
@@ -22,47 +31,31 @@ class FreeChatgpt(AsyncGeneratorProvider):
22 31 proxy: str = None,
23 32 **kwargs
24 33 ) -> AsyncResult:
25 if not model:
26 model = "gpt-3.5-turbo"
34 model = models[model] if model in models else "gpt-3.5-turbo-1106"
27 35 headers = {
28 "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/119.0",
29 "Accept": "application/json, text/event-stream",
30 "Accept-Language": "de,en-US;q=0.7,en;q=0.3",
31 "Accept-Encoding": "gzip, deflate, br",
32 "Content-Type": "application/json",
33 "Referer": "https://free.chatgpt.org.uk/",
34 "x-requested-with": "XMLHttpRequest",
35 "Origin": "https://free.chatgpt.org.uk",
36 "Sec-Fetch-Dest": "empty",
37 "Sec-Fetch-Mode": "cors",
38 "Sec-Fetch-Site": "same-origin",
39 "Connection": "keep-alive",
40 "Alt-Used": "free.chatgpt.org.uk",
41 "Pragma": "no-cache",
42 "Cache-Control": "no-cache",
43 "TE": "trailers",
44 }
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 }
45 48 async with ClientSession(headers=headers) as session:
46 data = {
47 "messages": messages,
48 "isAzure": False,
49 "azureApiVersion": "2023-08-01-preview",
50 "stream": True,
51 "model": model,
52 "temperature": 0.5,
53 "presence_penalty": 0,
54 "frequency_penalty": 0,
55 "top_p": 1,
56 "baseUrl": "/api/openai",
57 "maxIterations": 10,
58 "returnIntermediateSteps": True,
59 "useTools": ["web-search", "calculator", "web-browser"],
60 **kwargs
61 }
62 async with session.post(f"{cls.url}/api/langchain/tool/agent/nodejs", json=data, proxy=proxy) as response:
63 response.raise_for_status()
64 async for line in response.content:
65 if line.startswith(b"data: "):
66 data = json.loads(line[6:])
67 if data["isSuccess"] and not data["isToolMessage"]:
68 yield data["message"]
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"]
Modified g4f/models.py +15 -5
@@ -69,8 +69,9 @@ gpt_35_long = Model(
69 69 gpt_35_turbo = Model(
70 70 name = 'gpt-3.5-turbo',
71 71 base_provider = 'openai',
72 best_provider=RetryProvider([
73 GptGo, You,
72 best_provider=RetryProvider([
73 FreeChatgpt,
74 GptGo, You,
74 75 GptForLove, ChatBase,
75 76 Chatgpt4Online,
76 77 ])
@@ -80,7 +81,7 @@ gpt_4 = Model(
80 81 name = 'gpt-4',
81 82 base_provider = 'openai',
82 83 best_provider = RetryProvider([
83 Bing, Phind, Liaobots
84 Bing, FreeChatgpt, Phind, Liaobots,
84 85 ])
85 86 )
86 87
@@ -158,12 +159,12 @@ claude_instant_v1 = Model(
158 159 claude_v1 = Model(
159 160 name = 'claude-v1',
160 161 base_provider = 'anthropic',
161 best_provider = Vercel)
162 best_provider = RetryProvider([FreeChatgpt,Vercel]))
162 163
163 164 claude_v2 = Model(
164 165 name = 'claude-v2',
165 166 base_provider = 'anthropic',
166 best_provider = Vercel)
167 best_provider = RetryProvider([FreeChatgpt,Vercel]))
167 168
168 169 command_light_nightly = Model(
169 170 name = 'command-light-nightly',
@@ -245,6 +246,13 @@ gpt_4_32k_0613 = Model(
245 246 best_provider = gpt_4.best_provider
246 247 )
247 248
249 #Gemini
250 gemini_pro = Model(
251 name = 'gemini-pro',
252 base_provider = 'google',
253 best_provider = FreeChatgpt
254 )
255
248 256 text_ada_001 = Model(
249 257 name = 'text-ada-001',
250 258 base_provider = 'openai',
@@ -318,6 +326,8 @@ class ModelUtils:
318 326 'mistral-7b': mistral_7b,
319 327 'openchat_3.5': openchat_35,
320 328
329 # Gemini Pro
330 'gemini-pro': gemini_pro,
321 331 # Bard
322 332 'palm2' : palm,
323 333 'palm' : palm,