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

XFEstudio/gpt4free

~

73ec30a3
Tekky <98614666+xtekky@users.noreply.github.com>
提交于

代码差异

1 个文件 +0 -353
Deleted g4f/Provider/Vercel.py +0 -353
@@ -1,353 +0,0 @@
1 from __future__ import annotations
2
3 import base64, json, uuid, quickjs, random
4 from curl_cffi.requests import AsyncSession
5
6 from ..typing import Any, TypedDict
7 from .base_provider import AsyncProvider
8
9
10 class Vercel(AsyncProvider):
11 url = "https://sdk.vercel.ai"
12 working = True
13 supports_gpt_35_turbo = True
14 model = "replicate:replicate/llama-2-70b-chat"
15
16 @classmethod
17 async def create_async(
18 cls,
19 model: str,
20 messages: list[dict[str, str]],
21 proxy: str = None,
22 **kwargs
23 ) -> str:
24 if model in ["gpt-3.5-turbo", "gpt-4"]:
25 model = "openai:" + model
26 model = model if model else cls.model
27 proxies = None
28 if proxy:
29 if "://" not in proxy:
30 proxy = "http://" + proxy
31 proxies = {"http": proxy, "https": proxy}
32 headers = {
33 "User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.{rand1}.{rand2} Safari/537.36".format(
34 rand1=random.randint(0,9999),
35 rand2=random.randint(0,9999)
36 ),
37 "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
38 "Accept-Encoding": "gzip, deflate, br",
39 "Accept-Language": "en-US,en;q=0.5",
40 "TE": "trailers",
41 }
42 async with AsyncSession(headers=headers, proxies=proxies, impersonate="chrome107") as session:
43 response = await session.get(cls.url + "/openai.jpeg")
44 response.raise_for_status()
45 custom_encoding = _get_custom_encoding(response.text)
46 headers = {
47 "Content-Type": "application/json",
48 "Custom-Encoding": custom_encoding,
49 }
50 data = _create_payload(model, messages)
51 response = await session.post(cls.url + "/api/generate", json=data, headers=headers)
52 response.raise_for_status()
53 return response.text
54
55
56 def _create_payload(model: str, messages: list[dict[str, str]]) -> dict[str, Any]:
57 if model not in model_info:
58 raise ValueError(f'Model are not supported: {model}')
59 default_params = model_info[model]["default_params"]
60 return {
61 "messages": messages,
62 "playgroundId": str(uuid.uuid4()),
63 "chatIndex": 0,
64 "model": model
65 } | default_params
66
67 # based on https://github.com/ading2210/vercel-llm-api
68 def _get_custom_encoding(text: str) -> str:
69 data = json.loads(base64.b64decode(text, validate=True))
70 script = """
71 String.prototype.fontcolor = function() {{
72 return `<font>${{this}}</font>`
73 }}
74 var globalThis = {{marker: "mark"}};
75 ({script})({key})
76 """.format(
77 script=data["c"], key=data["a"]
78 )
79 context = quickjs.Context() # type: ignore
80 token_data = json.loads(context.eval(script).json()) # type: ignore
81 token_data[2] = "mark"
82 token = {"r": token_data, "t": data["t"]}
83 token_str = json.dumps(token, separators=(",", ":")).encode("utf-16le")
84 return base64.b64encode(token_str).decode()
85
86
87 class ModelInfo(TypedDict):
88 id: str
89 default_params: dict[str, Any]
90
91
92 model_info: dict[str, ModelInfo] = {
93 "anthropic:claude-instant-v1": {
94 "id": "anthropic:claude-instant-v1",
95 "default_params": {
96 "temperature": 1,
97 "maxTokens": 200,
98 "topP": 1,
99 "topK": 1,
100 "presencePenalty": 1,
101 "frequencyPenalty": 1,
102 "stopSequences": ["\n\nHuman:"],
103 },
104 },
105 "anthropic:claude-v1": {
106 "id": "anthropic:claude-v1",
107 "default_params": {
108 "temperature": 1,
109 "maxTokens": 200,
110 "topP": 1,
111 "topK": 1,
112 "presencePenalty": 1,
113 "frequencyPenalty": 1,
114 "stopSequences": ["\n\nHuman:"],
115 },
116 },
117 "anthropic:claude-v2": {
118 "id": "anthropic:claude-v2",
119 "default_params": {
120 "temperature": 1,
121 "maxTokens": 200,
122 "topP": 1,
123 "topK": 1,
124 "presencePenalty": 1,
125 "frequencyPenalty": 1,
126 "stopSequences": ["\n\nHuman:"],
127 },
128 },
129 "replicate:a16z-infra/llama7b-v2-chat": {
130 "id": "replicate:a16z-infra/llama7b-v2-chat",
131 "default_params": {
132 "temperature": 0.75,
133 "maxTokens": 500,
134 "topP": 1,
135 "repetitionPenalty": 1,
136 },
137 },
138 "replicate:a16z-infra/llama13b-v2-chat": {
139 "id": "replicate:a16z-infra/llama13b-v2-chat",
140 "default_params": {
141 "temperature": 0.75,
142 "maxTokens": 500,
143 "topP": 1,
144 "repetitionPenalty": 1,
145 },
146 },
147 "replicate:replicate/llama-2-70b-chat": {
148 "id": "replicate:replicate/llama-2-70b-chat",
149 "default_params": {
150 "temperature": 0.75,
151 "maxTokens": 1000,
152 "topP": 1,
153 "repetitionPenalty": 1,
154 },
155 },
156 "huggingface:bigscience/bloom": {
157 "id": "huggingface:bigscience/bloom",
158 "default_params": {
159 "temperature": 0.5,
160 "maxTokens": 200,
161 "topP": 0.95,
162 "topK": 4,
163 "repetitionPenalty": 1.03,
164 },
165 },
166 "huggingface:google/flan-t5-xxl": {
167 "id": "huggingface:google/flan-t5-xxl",
168 "default_params": {
169 "temperature": 0.5,
170 "maxTokens": 200,
171 "topP": 0.95,
172 "topK": 4,
173 "repetitionPenalty": 1.03,
174 },
175 },
176 "huggingface:EleutherAI/gpt-neox-20b": {
177 "id": "huggingface:EleutherAI/gpt-neox-20b",
178 "default_params": {
179 "temperature": 0.5,
180 "maxTokens": 200,
181 "topP": 0.95,
182 "topK": 4,
183 "repetitionPenalty": 1.03,
184 "stopSequences": [],
185 },
186 },
187 "huggingface:OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5": {
188 "id": "huggingface:OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5",
189 "default_params": {"maxTokens": 200, "typicalP": 0.2, "repetitionPenalty": 1},
190 },
191 "huggingface:OpenAssistant/oasst-sft-1-pythia-12b": {
192 "id": "huggingface:OpenAssistant/oasst-sft-1-pythia-12b",
193 "default_params": {"maxTokens": 200, "typicalP": 0.2, "repetitionPenalty": 1},
194 },
195 "huggingface:bigcode/santacoder": {
196 "id": "huggingface:bigcode/santacoder",
197 "default_params": {
198 "temperature": 0.5,
199 "maxTokens": 200,
200 "topP": 0.95,
201 "topK": 4,
202 "repetitionPenalty": 1.03,
203 },
204 },
205 "cohere:command-light-nightly": {
206 "id": "cohere:command-light-nightly",
207 "default_params": {
208 "temperature": 0.9,
209 "maxTokens": 200,
210 "topP": 1,
211 "topK": 0,
212 "presencePenalty": 0,
213 "frequencyPenalty": 0,
214 "stopSequences": [],
215 },
216 },
217 "cohere:command-nightly": {
218 "id": "cohere:command-nightly",
219 "default_params": {
220 "temperature": 0.9,
221 "maxTokens": 200,
222 "topP": 1,
223 "topK": 0,
224 "presencePenalty": 0,
225 "frequencyPenalty": 0,
226 "stopSequences": [],
227 },
228 },
229 "openai:gpt-4": {
230 "id": "openai:gpt-4",
231 "default_params": {
232 "temperature": 0.7,
233 "maxTokens": 500,
234 "topP": 1,
235 "presencePenalty": 0,
236 "frequencyPenalty": 0,
237 "stopSequences": [],
238 },
239 },
240 "openai:gpt-4-0613": {
241 "id": "openai:gpt-4-0613",
242 "default_params": {
243 "temperature": 0.7,
244 "maxTokens": 500,
245 "topP": 1,
246 "presencePenalty": 0,
247 "frequencyPenalty": 0,
248 "stopSequences": [],
249 },
250 },
251 "openai:code-davinci-002": {
252 "id": "openai:code-davinci-002",
253 "default_params": {
254 "temperature": 0.5,
255 "maxTokens": 200,
256 "topP": 1,
257 "presencePenalty": 0,
258 "frequencyPenalty": 0,
259 "stopSequences": [],
260 },
261 },
262 "openai:gpt-3.5-turbo": {
263 "id": "openai:gpt-3.5-turbo",
264 "default_params": {
265 "temperature": 0.7,
266 "maxTokens": 500,
267 "topP": 1,
268 "topK": 1,
269 "presencePenalty": 1,
270 "frequencyPenalty": 1,
271 "stopSequences": [],
272 },
273 },
274 "openai:gpt-3.5-turbo-16k": {
275 "id": "openai:gpt-3.5-turbo-16k",
276 "default_params": {
277 "temperature": 0.7,
278 "maxTokens": 500,
279 "topP": 1,
280 "topK": 1,
281 "presencePenalty": 1,
282 "frequencyPenalty": 1,
283 "stopSequences": [],
284 },
285 },
286 "openai:gpt-3.5-turbo-16k-0613": {
287 "id": "openai:gpt-3.5-turbo-16k-0613",
288 "default_params": {
289 "temperature": 0.7,
290 "maxTokens": 500,
291 "topP": 1,
292 "topK": 1,
293 "presencePenalty": 1,
294 "frequencyPenalty": 1,
295 "stopSequences": [],
296 },
297 },
298 "openai:text-ada-001": {
299 "id": "openai:text-ada-001",
300 "default_params": {
301 "temperature": 0.5,
302 "maxTokens": 200,
303 "topP": 1,
304 "presencePenalty": 0,
305 "frequencyPenalty": 0,
306 "stopSequences": [],
307 },
308 },
309 "openai:text-babbage-001": {
310 "id": "openai:text-babbage-001",
311 "default_params": {
312 "temperature": 0.5,
313 "maxTokens": 200,
314 "topP": 1,
315 "presencePenalty": 0,
316 "frequencyPenalty": 0,
317 "stopSequences": [],
318 },
319 },
320 "openai:text-curie-001": {
321 "id": "openai:text-curie-001",
322 "default_params": {
323 "temperature": 0.5,
324 "maxTokens": 200,
325 "topP": 1,
326 "presencePenalty": 0,
327 "frequencyPenalty": 0,
328 "stopSequences": [],
329 },
330 },
331 "openai:text-davinci-002": {
332 "id": "openai:text-davinci-002",
333 "default_params": {
334 "temperature": 0.5,
335 "maxTokens": 200,
336 "topP": 1,
337 "presencePenalty": 0,
338 "frequencyPenalty": 0,
339 "stopSequences": [],
340 },
341 },
342 "openai:text-davinci-003": {
343 "id": "openai:text-davinci-003",
344 "default_params": {
345 "temperature": 0.5,
346 "maxTokens": 200,
347 "topP": 1,
348 "presencePenalty": 0,
349 "frequencyPenalty": 0,
350 "stopSequences": [],
351 },
352 },
353 }