Delete models/vercel
Browse files
models/vercel/__pycache__/main.cpython-312.pyc
DELETED
Binary file (9.64 kB)
|
|
models/vercel/main.py
DELETED
@@ -1,210 +0,0 @@
|
|
1 |
-
import httpx
|
2 |
-
import asyncio
|
3 |
-
import random
|
4 |
-
import json
|
5 |
-
|
6 |
-
class XaiAPI:
|
7 |
-
|
8 |
-
headers = {
|
9 |
-
'accept': '*/*',
|
10 |
-
'accept-language': 'en-US,en;q=0.9,ja;q=0.8',
|
11 |
-
'content-type': 'application/json',
|
12 |
-
'origin': 'https://ai-sdk-starter-xai.vercel.app',
|
13 |
-
'referer': 'https://ai-sdk-starter-xai.vercel.app/',
|
14 |
-
'sec-ch-ua': '"Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135"',
|
15 |
-
'sec-ch-ua-mobile': '?0',
|
16 |
-
'sec-ch-ua-platform': '"macOS"',
|
17 |
-
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36'
|
18 |
-
}
|
19 |
-
|
20 |
-
|
21 |
-
def __init__(self):
|
22 |
-
self.base_url = "https://ai-sdk-starter-xai.vercel.app/api/chat"
|
23 |
-
|
24 |
-
def get_model_list(self):
|
25 |
-
models = ["grok-3-mini", "grok-2-1212", "grok-3", "grok-3-fast", "grok-3-mini-fast"]
|
26 |
-
return models
|
27 |
-
|
28 |
-
def convert(messages):
|
29 |
-
converted = []
|
30 |
-
for message in messages:
|
31 |
-
role = message.get("role", "user")
|
32 |
-
content = message.get("content", "")
|
33 |
-
|
34 |
-
if isinstance(content, list):
|
35 |
-
parts = content
|
36 |
-
text_content = "\n".join([p.get("text", "") for p in content if p.get("type") == "text"])
|
37 |
-
else:
|
38 |
-
text_content = str(content)
|
39 |
-
parts = [{"type": "text", "text": text_content}]
|
40 |
-
if role == "assistant":
|
41 |
-
parts.insert(0, {"type": "step-start"})
|
42 |
-
|
43 |
-
converted.append({
|
44 |
-
"role": role,
|
45 |
-
"content": text_content,
|
46 |
-
"parts": parts
|
47 |
-
})
|
48 |
-
return converted
|
49 |
-
|
50 |
-
async def generate(self, json_data: dict):
|
51 |
-
messages = XaiAPI.convert(json_data["messages"])
|
52 |
-
|
53 |
-
request_data = {
|
54 |
-
"id": "".join(random.choices("0123456789abcdef", k=16)),
|
55 |
-
"messages": messages,
|
56 |
-
"selectedModel": json_data.get("model", "grok-2-1212"),
|
57 |
-
}
|
58 |
-
|
59 |
-
chunk_id = "chipling-xai-" + "".join(random.choices("0123456789abcdef", k=32))
|
60 |
-
created = int(asyncio.get_event_loop().time())
|
61 |
-
total_tokens = 0
|
62 |
-
|
63 |
-
try:
|
64 |
-
async with httpx.AsyncClient(timeout=None) as client:
|
65 |
-
async with client.stream(
|
66 |
-
"POST",
|
67 |
-
"https://ai-sdk-starter-xai.vercel.app/api/chat",
|
68 |
-
headers=XaiAPI.headers,
|
69 |
-
json=request_data
|
70 |
-
) as request_ctx:
|
71 |
-
if request_ctx.status_code == 200:
|
72 |
-
async for line in request_ctx.aiter_lines():
|
73 |
-
if line:
|
74 |
-
if line.startswith('0:'):
|
75 |
-
# Clean up the text and properly escape JSON characters
|
76 |
-
text = line[2:].strip()
|
77 |
-
if text.startswith('"') and text.endswith('"'):
|
78 |
-
text = text[1:-1]
|
79 |
-
text = text.replace('\\n', '\n').replace('\\', '')
|
80 |
-
|
81 |
-
response = {
|
82 |
-
"id": chunk_id,
|
83 |
-
"object": "chat.completion.chunk",
|
84 |
-
"created": created,
|
85 |
-
"model": json_data.get("model", "grok-2-1212"),
|
86 |
-
"choices": [{
|
87 |
-
"index": 0,
|
88 |
-
"text": text,
|
89 |
-
"logprobs": None,
|
90 |
-
"finish_reason": None
|
91 |
-
}],
|
92 |
-
"usage": None
|
93 |
-
}
|
94 |
-
yield f"data: {json.dumps(response)}\n\n"
|
95 |
-
total_tokens += 1
|
96 |
-
elif line.startswith('d:'):
|
97 |
-
final = {
|
98 |
-
"id": chunk_id,
|
99 |
-
"object": "chat.completion.chunk",
|
100 |
-
"created": created,
|
101 |
-
"model": json_data.get("model", "grok-2-1212"),
|
102 |
-
"choices": [],
|
103 |
-
"usage": {
|
104 |
-
"prompt_tokens": len(messages),
|
105 |
-
"completion_tokens": total_tokens,
|
106 |
-
"total_tokens": len(messages) + total_tokens
|
107 |
-
}
|
108 |
-
}
|
109 |
-
yield f"data: {json.dumps(final)}\n\n"
|
110 |
-
yield "data: [DONE]\n\n"
|
111 |
-
return
|
112 |
-
else:
|
113 |
-
yield f"data: [Unexpected status code: {request_ctx.status_code}]\n\n"
|
114 |
-
except Exception as e:
|
115 |
-
yield f"data: [Connection error: {str(e)}]\n\n"
|
116 |
-
|
117 |
-
|
118 |
-
class GroqAPI:
|
119 |
-
|
120 |
-
headers = {
|
121 |
-
'accept': '*/*',
|
122 |
-
'accept-language': 'en-US,en;q=0.9,ja;q=0.8',
|
123 |
-
'content-type': 'application/json',
|
124 |
-
'origin': 'https://ai-sdk-starter-groq.vercel.app',
|
125 |
-
'priority': 'u=1, i',
|
126 |
-
'referer': 'https://ai-sdk-starter-groq.vercel.app/',
|
127 |
-
'sec-ch-ua': '"Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135"',
|
128 |
-
'sec-ch-ua-mobile': '?0',
|
129 |
-
'sec-ch-ua-platform': '"macOS"',
|
130 |
-
'sec-fetch-dest': 'empty',
|
131 |
-
'sec-fetch-mode': 'cors',
|
132 |
-
'sec-fetch-site': 'same-origin',
|
133 |
-
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36',
|
134 |
-
}
|
135 |
-
|
136 |
-
def __init__(self):
|
137 |
-
self.base_url = "https://ai-sdk-starter-groq.vercel.app/api/chat"
|
138 |
-
|
139 |
-
def get_model_list(self):
|
140 |
-
models = ['meta-llama/llama-4-scout-17b-16e-instruct', 'llama-3.1-8b-instant', 'llama-3.3-70b-versatile', 'deepseek-r1-distill-llama-70b']
|
141 |
-
return models
|
142 |
-
|
143 |
-
|
144 |
-
async def generate(self, json_data: dict):
|
145 |
-
messages = XaiAPI.convert(json_data["messages"])
|
146 |
-
|
147 |
-
request_data = {
|
148 |
-
"id": "".join(random.choices("0123456789abcdef", k=16)),
|
149 |
-
"messages": messages,
|
150 |
-
"selectedModel": json_data.get("model", "deepseek-r1-distill-llama-70b"),
|
151 |
-
}
|
152 |
-
|
153 |
-
chunk_id = "chipling-groq-" + "".join(random.choices("0123456789abcdef", k=32))
|
154 |
-
created = int(asyncio.get_event_loop().time())
|
155 |
-
total_tokens = 0
|
156 |
-
|
157 |
-
try:
|
158 |
-
async with httpx.AsyncClient(timeout=None) as client:
|
159 |
-
async with client.stream(
|
160 |
-
"POST",
|
161 |
-
"https://ai-sdk-starter-groq.vercel.app/api/chat",
|
162 |
-
headers=GroqAPI.headers,
|
163 |
-
json=request_data
|
164 |
-
) as request_ctx:
|
165 |
-
print(request_ctx.status_code)
|
166 |
-
if request_ctx.status_code == 200:
|
167 |
-
async for line in request_ctx.aiter_lines():
|
168 |
-
if line:
|
169 |
-
if line.startswith('0:'):
|
170 |
-
# Clean up the text and properly escape JSON characters
|
171 |
-
text = line[2:].strip()
|
172 |
-
if text.startswith('"') and text.endswith('"'):
|
173 |
-
text = text[1:-1]
|
174 |
-
text = text.replace('\\n', '\n').replace('\\', '')
|
175 |
-
|
176 |
-
response = {
|
177 |
-
"id": chunk_id,
|
178 |
-
"object": "chat.completion.chunk",
|
179 |
-
"created": created,
|
180 |
-
"model": json_data.get("model", "deepseek-r1-distill-llama-70b"),
|
181 |
-
"choices": [{
|
182 |
-
"index": 0,
|
183 |
-
"text": text,
|
184 |
-
"logprobs": None,
|
185 |
-
"finish_reason": None
|
186 |
-
}],
|
187 |
-
"usage": None
|
188 |
-
}
|
189 |
-
yield f"data: {json.dumps(response)}\n\n"
|
190 |
-
total_tokens += 1
|
191 |
-
elif line.startswith('d:'):
|
192 |
-
final = {
|
193 |
-
"id": chunk_id,
|
194 |
-
"object": "chat.completion.chunk",
|
195 |
-
"created": created,
|
196 |
-
"model": json_data.get("model", "deepseek-r1-distill-llama-70b"),
|
197 |
-
"choices": [],
|
198 |
-
"usage": {
|
199 |
-
"prompt_tokens": len(messages),
|
200 |
-
"completion_tokens": total_tokens,
|
201 |
-
"total_tokens": len(messages) + total_tokens
|
202 |
-
}
|
203 |
-
}
|
204 |
-
yield f"data: {json.dumps(final)}\n\n"
|
205 |
-
yield "data: [DONE]\n\n"
|
206 |
-
return
|
207 |
-
else:
|
208 |
-
yield f"data: [Unexpected status code: {request_ctx.status_code}]\n\n"
|
209 |
-
except Exception as e:
|
210 |
-
yield f"data: [Connection error: {str(e)}]\n\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|