返回提交历史
Deleted
g4f/Provider/Vercel.py
+0
-387
XFEstudio/gpt4free
Delete g4f/Provider/Vercel.py
1215d30b
代码差异
1 个文件
+0
-387
@@ -1,387 +0,0 @@
1
from __future__ import annotations
2
3
import json, base64, requests, execjs, random, uuid
4
from aiohttp import ClientSession
5
6
from ..typing import Any, TypedDict, AsyncGenerator
7
from .base_provider import AsyncGeneratorProvider
8
9
10
class Vercel(AsyncGeneratorProvider):
11
url = 'https://sdk.vercel.ai'
12
working = True
13
supports_gpt_35_turbo = True
14
supports_stream = True
15
_anti_bot_token = None
16
17
@classmethod
18
async def create_async_generator(
19
cls,
20
model: str,
21
messages: list[dict[str, str]],
22
stream: bool,
23
proxy: str = None,
24
**kwargs
25
) -> AsyncGenerator:
26
if not model:
27
model = "gpt-3.5-turbo"
28
elif model not in model_info:
29
raise ValueError(f"Model are not supported: {model}")
30
31
if not cls._anti_bot_token:
32
cls._anti_bot_token = get_anti_bot_token(proxy)
33
34
json_data = {
35
'model' : model_info[model]['id'],
36
'messages' : messages,
37
'playgroundId': str(uuid.uuid4()),
38
'chatIndex' : 0
39
} | model_info[model]['default_params']
40
41
for tries in range(100):
42
headers = {
43
'authority' : 'sdk.vercel.ai',
44
'accept' : '*/*',
45
'accept-language' : 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
46
'cache-control' : 'no-cache',
47
'content-type' : 'application/json',
48
'custom-encoding' : cls._anti_bot_token,
49
'origin' : 'https://sdk.vercel.ai',
50
'pragma' : 'no-cache',
51
'referer' : 'https://sdk.vercel.ai/',
52
'sec-ch-ua' : '"Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"',
53
'sec-ch-ua-mobile' : '?0',
54
'sec-ch-ua-platform': '"macOS"',
55
'sec-fetch-dest' : 'empty',
56
'sec-fetch-mode' : 'cors',
57
'sec-fetch-site' : 'same-origin',
58
'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.%s.%s Safari/537.36' % (
59
random.randint(99, 999),
60
random.randint(99, 999)
61
)
62
}
63
async with ClientSession(
64
headers=headers
65
) as session:
66
async with session.post(f"{cls.url}/api/generate", proxy=proxy, json=json_data) as response:
67
try:
68
response.raise_for_status()
69
except Exception as e:
70
if tries >= 99:
71
raise e
72
# Maybe the token is the reason for failing
73
cls._anti_bot_token = get_anti_bot_token(proxy)
74
continue
75
async for token in response.content.iter_any():
76
yield token.decode()
77
break
78
79
def get_anti_bot_token(proxy: str = None) -> str:
80
headers = {
81
'authority' : 'sdk.vercel.ai',
82
'accept' : '*/*',
83
'accept-language' : 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
84
'cache-control' : 'no-cache',
85
'pragma' : 'no-cache',
86
'referer' : 'https://sdk.vercel.ai/',
87
'sec-ch-ua' : '"Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"',
88
'sec-ch-ua-mobile' : '?0',
89
'sec-ch-ua-platform': '"macOS"',
90
'sec-fetch-dest' : 'empty',
91
'sec-fetch-mode' : 'cors',
92
'sec-fetch-site' : 'same-origin',
93
'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.%s.%s Safari/537.36' % (
94
random.randint(99, 999),
95
random.randint(99, 999)
96
)
97
}
98
99
# Does not work with async requests
100
response = requests.get('https://sdk.vercel.ai/openai.jpeg',
101
headers=headers, proxies={"https": proxy}).text
102
103
raw_data = json.loads(base64.b64decode(response,
104
validate=True))
105
106
js_script = '''const globalThis={marker:"mark"};String.prototype.fontcolor=function(){return `<font>${this}</font>`};
107
return (%s)(%s)''' % (raw_data['c'], raw_data['a'])
108
109
raw_token = json.dumps({'r': execjs.compile(js_script).call(''), 't': raw_data['t']},
110
separators = (",", ":"))
111
112
return base64.b64encode(raw_token.encode('utf-16le')).decode()
113
114
class ModelInfo(TypedDict):
115
id: str
116
default_params: dict[str, Any]
117
118
model_info: dict[str, ModelInfo] = {
119
'claude-instant-v1': {
120
'id': 'anthropic:claude-instant-v1',
121
'default_params': {
122
'temperature': 1,
123
'maximumLength': 1024,
124
'topP': 1,
125
'topK': 1,
126
'presencePenalty': 1,
127
'frequencyPenalty': 1,
128
'stopSequences': ['\n\nHuman:'],
129
},
130
},
131
'claude-v1': {
132
'id': 'anthropic:claude-v1',
133
'default_params': {
134
'temperature': 1,
135
'maximumLength': 1024,
136
'topP': 1,
137
'topK': 1,
138
'presencePenalty': 1,
139
'frequencyPenalty': 1,
140
'stopSequences': ['\n\nHuman:'],
141
},
142
},
143
'claude-v2': {
144
'id': 'anthropic:claude-v2',
145
'default_params': {
146
'temperature': 1,
147
'maximumLength': 1024,
148
'topP': 1,
149
'topK': 1,
150
'presencePenalty': 1,
151
'frequencyPenalty': 1,
152
'stopSequences': ['\n\nHuman:'],
153
},
154
},
155
'a16z-infra/llama7b-v2-chat': {
156
'id': 'replicate:a16z-infra/llama7b-v2-chat',
157
'default_params': {
158
'temperature': 0.75,
159
'maximumLength': 3000,
160
'topP': 1,
161
'repetitionPenalty': 1,
162
},
163
},
164
'a16z-infra/llama13b-v2-chat': {
165
'id': 'replicate:a16z-infra/llama13b-v2-chat',
166
'default_params': {
167
'temperature': 0.75,
168
'maximumLength': 3000,
169
'topP': 1,
170
'repetitionPenalty': 1,
171
},
172
},
173
'replicate/llama-2-70b-chat': {
174
'id': 'replicate:replicate/llama-2-70b-chat',
175
'default_params': {
176
'temperature': 0.75,
177
'maximumLength': 3000,
178
'topP': 1,
179
'repetitionPenalty': 1,
180
},
181
},
182
'bigscience/bloom': {
183
'id': 'huggingface:bigscience/bloom',
184
'default_params': {
185
'temperature': 0.5,
186
'maximumLength': 1024,
187
'topP': 0.95,
188
'topK': 4,
189
'repetitionPenalty': 1.03,
190
},
191
},
192
'google/flan-t5-xxl': {
193
'id': 'huggingface:google/flan-t5-xxl',
194
'default_params': {
195
'temperature': 0.5,
196
'maximumLength': 1024,
197
'topP': 0.95,
198
'topK': 4,
199
'repetitionPenalty': 1.03,
200
},
201
},
202
'EleutherAI/gpt-neox-20b': {
203
'id': 'huggingface:EleutherAI/gpt-neox-20b',
204
'default_params': {
205
'temperature': 0.5,
206
'maximumLength': 1024,
207
'topP': 0.95,
208
'topK': 4,
209
'repetitionPenalty': 1.03,
210
'stopSequences': [],
211
},
212
},
213
'OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5': {
214
'id': 'huggingface:OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5',
215
'default_params': {
216
'maximumLength': 1024,
217
'typicalP': 0.2,
218
'repetitionPenalty': 1,
219
},
220
},
221
'OpenAssistant/oasst-sft-1-pythia-12b': {
222
'id': 'huggingface:OpenAssistant/oasst-sft-1-pythia-12b',
223
'default_params': {
224
'maximumLength': 1024,
225
'typicalP': 0.2,
226
'repetitionPenalty': 1,
227
},
228
},
229
'bigcode/santacoder': {
230
'id': 'huggingface:bigcode/santacoder',
231
'default_params': {
232
'temperature': 0.5,
233
'maximumLength': 1024,
234
'topP': 0.95,
235
'topK': 4,
236
'repetitionPenalty': 1.03,
237
},
238
},
239
'command-light-nightly': {
240
'id': 'cohere:command-light-nightly',
241
'default_params': {
242
'temperature': 0.9,
243
'maximumLength': 1024,
244
'topP': 1,
245
'topK': 0,
246
'presencePenalty': 0,
247
'frequencyPenalty': 0,
248
'stopSequences': [],
249
},
250
},
251
'command-nightly': {
252
'id': 'cohere:command-nightly',
253
'default_params': {
254
'temperature': 0.9,
255
'maximumLength': 1024,
256
'topP': 1,
257
'topK': 0,
258
'presencePenalty': 0,
259
'frequencyPenalty': 0,
260
'stopSequences': [],
261
},
262
},
263
'gpt-4': {
264
'id': 'openai:gpt-4',
265
'default_params': {
266
'temperature': 0.7,
267
'maximumLength': 8192,
268
'topP': 1,
269
'presencePenalty': 0,
270
'frequencyPenalty': 0,
271
'stopSequences': [],
272
},
273
},
274
'gpt-4-0613': {
275
'id': 'openai:gpt-4-0613',
276
'default_params': {
277
'temperature': 0.7,
278
'maximumLength': 8192,
279
'topP': 1,
280
'presencePenalty': 0,
281
'frequencyPenalty': 0,
282
'stopSequences': [],
283
},
284
},
285
'code-davinci-002': {
286
'id': 'openai:code-davinci-002',
287
'default_params': {
288
'temperature': 0.5,
289
'maximumLength': 1024,
290
'topP': 1,
291
'presencePenalty': 0,
292
'frequencyPenalty': 0,
293
'stopSequences': [],
294
},
295
},
296
'gpt-3.5-turbo': {
297
'id': 'openai:gpt-3.5-turbo',
298
'default_params': {
299
'temperature': 0.7,
300
'maximumLength': 4096,
301
'topP': 1,
302
'topK': 1,
303
'presencePenalty': 1,
304
'frequencyPenalty': 1,
305
'stopSequences': [],
306
},
307
},
308
'gpt-3.5-turbo-16k': {
309
'id': 'openai:gpt-3.5-turbo-16k',
310
'default_params': {
311
'temperature': 0.7,
312
'maximumLength': 16280,
313
'topP': 1,
314
'topK': 1,
315
'presencePenalty': 1,
316
'frequencyPenalty': 1,
317
'stopSequences': [],
318
},
319
},
320
'gpt-3.5-turbo-16k-0613': {
321
'id': 'openai:gpt-3.5-turbo-16k-0613',
322
'default_params': {
323
'temperature': 0.7,
324
'maximumLength': 16280,
325
'topP': 1,
326
'topK': 1,
327
'presencePenalty': 1,
328
'frequencyPenalty': 1,
329
'stopSequences': [],
330
},
331
},
332
'text-ada-001': {
333
'id': 'openai:text-ada-001',
334
'default_params': {
335
'temperature': 0.5,
336
'maximumLength': 1024,
337
'topP': 1,
338
'presencePenalty': 0,
339
'frequencyPenalty': 0,
340
'stopSequences': [],
341
},
342
},
343
'text-babbage-001': {
344
'id': 'openai:text-babbage-001',
345
'default_params': {
346
'temperature': 0.5,
347
'maximumLength': 1024,
348
'topP': 1,
349
'presencePenalty': 0,
350
'frequencyPenalty': 0,
351
'stopSequences': [],
352
},
353
},
354
'text-curie-001': {
355
'id': 'openai:text-curie-001',
356
'default_params': {
357
'temperature': 0.5,
358
'maximumLength': 1024,
359
'topP': 1,
360
'presencePenalty': 0,
361
'frequencyPenalty': 0,
362
'stopSequences': [],
363
},
364
},
365
'text-davinci-002': {
366
'id': 'openai:text-davinci-002',
367
'default_params': {
368
'temperature': 0.5,
369
'maximumLength': 1024,
370
'topP': 1,
371
'presencePenalty': 0,
372
'frequencyPenalty': 0,
373
'stopSequences': [],
374
},
375
},
376
'text-davinci-003': {
377
'id': 'openai:text-davinci-003',
378
'default_params': {
379
'temperature': 0.5,
380
'maximumLength': 4097,
381
'topP': 1,
382
'presencePenalty': 0,
383
'frequencyPenalty': 0,
384
'stopSequences': [],
385
},
386
},
387
}