返回提交历史
Modified
.gitignore
+1
-1
Modified
g4f/Provider/Vercel.py
+2
-64
XFEstudio/gpt4free
~
bae9c432
代码差异
2 个文件
+3
-65
@@ -34,6 +34,6 @@ update.py
34
34
cookie.json
35
35
notes.txt
36
36
close_issues.py
37
Vercel.py
37
xxx.py
38
38
# Emacs crap
39
39
*~
@@ -9,7 +9,7 @@ from .base_provider import AsyncProvider
9
9
10
10
class Vercel(AsyncProvider):
11
11
url = "https://sdk.vercel.ai"
12
working = True
12
working = False
13
13
supports_gpt_35_turbo = True
14
14
model = "replicate:replicate/llama-2-70b-chat"
15
15
@@ -21,74 +21,12 @@ class Vercel(AsyncProvider):
21
21
proxy: str = None,
22
22
**kwargs
23
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
24
return
86
25
87
26
class ModelInfo(TypedDict):
88
27
id: str
89
28
default_params: dict[str, Any]
90
29
91
92
30
model_info: dict[str, ModelInfo] = {
93
31
"anthropic:claude-instant-v1": {
94
32
"id": "anthropic:claude-instant-v1",