isididiidid commited on
Commit
efaac78
·
verified ·
1 Parent(s): 7f5fe1b

Update hf.js

Browse files
Files changed (1) hide show
  1. hf.js +137 -291
hf.js CHANGED
@@ -1,318 +1,163 @@
1
  const express = require('express');
2
  const morgan = require('morgan');
3
  const { createProxyMiddleware } = require('http-proxy-middleware');
4
- const axios = require('axios');
5
- const fs = require('fs');
6
  const app = express();
7
 
8
  app.use(morgan('dev'));
9
 
10
- app.get('/hf/v1/models', (req, res) => {
11
- const models = {
12
- "object": "list",
13
- "data": [
14
- {
15
- "id": "claude-3.5-sonnet",
16
- "object": "model",
17
- "created": 1706745938,
18
- "owned_by": "cursor"
19
- },
20
- {
21
- "id": "gpt-4",
22
- "object": "model",
23
- "created": 1706745938,
24
- "owned_by": "cursor"
25
- },
26
- {
27
- "id": "gpt-4o",
28
- "object": "model",
29
- "created": 1706745938,
30
- "owned_by": "cursor"
31
- },
32
- {
33
- "id": "claude-3-opus",
34
- "object": "model",
35
- "created": 1706745938,
36
- "owned_by": "cursor"
37
- },
38
- {
39
- "id": "gpt-3.5-turbo",
40
- "object": "model",
41
- "created": 1706745938,
42
- "owned_by": "cursor"
43
- },
44
- {
45
- "id": "gpt-4-turbo-2024-04-09",
46
- "object": "model",
47
- "created": 1706745938,
48
- "owned_by": "cursor"
49
- },
50
- {
51
- "id": "gpt-4o-128k",
52
- "object": "model",
53
- "created": 1706745938,
54
- "owned_by": "cursor"
55
- },
56
- {
57
- "id": "gemini-1.5-flash-500k",
58
- "object": "model",
59
- "created": 1706745938,
60
- "owned_by": "cursor"
61
- },
62
- {
63
- "id": "claude-3-haiku-200k",
64
- "object": "model",
65
- "created": 1706745938,
66
- "owned_by": "cursor"
67
- },
68
- {
69
- "id": "claude-3-5-sonnet-200k",
70
- "object": "model",
71
- "created": 1706745938,
72
- "owned_by": "cursor"
73
- },
74
- {
75
- "id": "claude-3-5-sonnet-20241022",
76
- "object": "model",
77
- "created": 1706745938,
78
- "owned_by": "cursor"
79
- },
80
- {
81
- "id": "gpt-4o-mini",
82
- "object": "model",
83
- "created": 1706745938,
84
- "owned_by": "cursor"
85
- },
86
- {
87
- "id": "o1-mini",
88
- "object": "model",
89
- "created": 1706745938,
90
- "owned_by": "cursor"
91
- },
92
- {
93
- "id": "o1-preview",
94
- "object": "model",
95
- "created": 1706745938,
96
- "owned_by": "cursor"
97
- },
98
- {
99
- "id": "o1",
100
- "object": "model",
101
- "created": 1706745938,
102
- "owned_by": "cursor"
103
- },
104
- {
105
- "id": "claude-3.5-haiku",
106
- "object": "model",
107
- "created": 1706745938,
108
- "owned_by": "cursor"
109
- },
110
- {
111
- "id": "gemini-exp-1206",
112
- "object": "model",
113
- "created": 1706745938,
114
- "owned_by": "cursor"
115
- },
116
- {
117
- "id": "gemini-2.0-flash-thinking-exp",
118
- "object": "model",
119
- "created": 1706745938,
120
- "owned_by": "cursor"
121
- },
122
- {
123
- "id": "gemini-2.0-flash-exp",
124
- "object": "model",
125
- "created": 1706745938,
126
- "owned_by": "cursor"
127
- },
128
- {
129
- "id": "deepseek-v3",
130
- "object": "model",
131
- "created": 1706745938,
132
- "owned_by": "cursor"
133
- },
134
- {
135
- "id": "deepseek-r1",
136
- "object": "model",
137
- "created": 1706745938,
138
- "owned_by": "cursor"
139
- }
140
- ]
141
- };
142
- res.json(models);
143
- });
144
-
145
  app.use('/hf/v1/chat/completions', createProxyMiddleware({
146
  target: 'http://localhost:3010/v1/chat/completions',
147
- changeOrigin: true,
148
- onProxyReq: (proxyReq, req, res) => {
149
- // 将请求数据写回代理请求
150
- if (req.body) {
151
- const bodyData = req.body;
152
- proxyReq.write(bodyData);
153
- }
154
- }
155
  }));
156
 
157
  app.get('/', (req, res) => {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  const htmlContent = `
159
  <!DOCTYPE html>
160
  <html lang="en">
161
  <head>
162
  <meta charset="UTF-8">
163
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
164
- <title>Cursor To OpenAI</title>
165
- <style>
166
- :root {
167
- --primary-color: #2563eb;
168
- --bg-color: #f8fafc;
169
- --card-bg: #ffffff;
170
- }
171
-
172
- body {
173
- padding: 20px;
174
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
175
- max-width: 1000px;
176
- margin: 0 auto;
177
- line-height: 1.6;
178
- background: var(--bg-color);
179
- color: #1a1a1a;
180
- }
181
- .container {
182
- padding: 20px;
183
- }
184
- .header {
185
- text-align: center;
186
- margin-bottom: 40px;
187
- }
188
- .header h1 {
189
- color: var(--primary-color);
190
- font-size: 2.5em;
191
- margin-bottom: 10px;
192
- }
193
- .info {
194
- background: #fff;
195
- padding: 25px;
196
- border-radius: 12px;
197
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
198
- margin-bottom: 30px;
199
- border: 1px solid #e5e7eb;
200
- }
201
- .info-item {
202
- margin: 15px 0;
203
- padding: 10px;
204
- background: #f8fafc;
205
- border-radius: 8px;
206
- border: 1px solid #e5e7eb;
207
- }
208
- .info-label {
209
- color: #4b5563;
210
- font-size: 0.9em;
211
- margin-bottom: 5px;
212
- }
213
- .info-value {
214
- color: var(--primary-color);
215
- font-weight: 500;
216
- }
217
- .models {
218
- background: var(--card-bg);
219
- padding: 25px;
220
- border-radius: 12px;
221
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
222
- border: 1px solid #e5e7eb;
223
- }
224
- .models h3 {
225
- color: #1a1a1a;
226
- margin-bottom: 20px;
227
- font-size: 1.5em;
228
- border-bottom: 2px solid #e5e7eb;
229
- padding-bottom: 10px;
230
- }
231
- .model-item {
232
- margin: 12px 0;
233
- padding: 15px;
234
- background: #f8fafc;
235
- border-radius: 8px;
236
- border: 1px solid #e5e7eb;
237
- transition: all 0.3s ease;
238
- display: flex;
239
- justify-content: space-between;
240
- align-items: center;
241
- }
242
- .model-item:hover {
243
- transform: translateY(-2px);
244
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
245
- }
246
- .model-name {
247
- font-weight: 500;
248
- color: #1a1a1a;
249
- }
250
- .model-provider {
251
- color: #6b7280;
252
- font-size: 0.9em;
253
- padding: 4px 8px;
254
- background: #f1f5f9;
255
- border-radius: 4px;
256
- }
257
- @media (max-width: 768px) {
258
- body {
259
- padding: 10px;
260
- }
261
-
262
- .container {
263
- padding: 10px;
264
- }
265
- }
266
- </style>
267
  </head>
268
  <body>
269
- <div class="container">
270
- <div class="header">
271
- <h1>Cursor To OpenAI Server</h1>
272
- <p>高性能 AI 模型代理服务</p>
273
- </div>
274
- <div class="info">
275
- <h2>配置信息</h2>
276
- <div class="info-item">
277
- <div class="info-label">聊天来源</div>
278
- <div class="info-value">自定义(兼容 OpenAI)</div>
279
- </div>
280
- <div class="info-item">
281
- <div class="info-label">自定义端点(基本URL)</div>
282
- <div class="info-value" id="endpoint-url"></div>
283
- </div>
284
- <div class="info-item">
285
- <div class="info-label">自定义API密钥</div>
286
- <div class="info-value">抓取的Cursor Cookie,格式为user_...</div>
287
- </div>
288
- </div>
289
- <div class="models">
290
- <h3>支持的模型列表</h3>
291
- <div id="model-list"></div>
292
- </div>
293
- </div>
294
  <script>
295
  const url = new URL(window.location.href);
296
  const link = url.protocol + '//' + url.host + '/hf/v1';
297
  document.getElementById('endpoint-url').textContent = link;
298
- fetch(link + '/models')
299
- .then(response => response.json())
300
- .then(data => {
301
- const modelList = document.getElementById('model-list');
302
- data.data.forEach(model => {
303
- const div = document.createElement('div');
304
- div.className = 'model-item';
305
- div.innerHTML = \`
306
- <span class="model-name">\${model.id}</span>
307
- <span class="model-provider">\${model.owned_by}</span>
308
- \`;
309
- modelList.appendChild(div);
310
- });
311
- })
312
- .catch(error => {
313
- console.error('Error fetching models:', error);
314
- document.getElementById('model-list').textContent = '获取模型列表失败';
315
- });
316
  </script>
317
  </body>
318
  </html>
@@ -325,3 +170,4 @@ app.listen(port, () => {
325
  console.log(`HF Proxy server is running at PORT: ${port}`);
326
  });
327
 
 
 
1
  const express = require('express');
2
  const morgan = require('morgan');
3
  const { createProxyMiddleware } = require('http-proxy-middleware');
 
 
4
  const app = express();
5
 
6
  app.use(morgan('dev'));
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  app.use('/hf/v1/chat/completions', createProxyMiddleware({
9
  target: 'http://localhost:3010/v1/chat/completions',
10
+ changeOrigin: true
 
 
 
 
 
 
 
11
  }));
12
 
13
  app.get('/', (req, res) => {
14
+ // 模型列表的 HTML (已手动列出每个模型的 JSON)
15
+ const modelListHTML = `
16
+ <ul>
17
+ <li><pre>{
18
+ "id": "claude-3.5-sonnet",
19
+ "object": "model",
20
+ "created": 1706745938,
21
+ "owned_by": "cursor"
22
+ }</pre></li>
23
+ <li><pre>{
24
+ "id": "gpt-4",
25
+ "object": "model",
26
+ "created": 1706745938,
27
+ "owned_by": "cursor"
28
+ }</pre></li>
29
+ <li><pre>{
30
+ "id": "gpt-4o",
31
+ "object": "model",
32
+ "created": 1706745938,
33
+ "owned_by": "cursor"
34
+ }</pre></li>
35
+ <li><pre>{
36
+ "id": "claude-3-opus",
37
+ "object": "model",
38
+ "created": 1706745938,
39
+ "owned_by": "cursor"
40
+ }</pre></li>
41
+ <li><pre>{
42
+ "id": "gpt-3.5-turbo",
43
+ "object": "model",
44
+ "created": 1706745938,
45
+ "owned_by": "cursor"
46
+ }</pre></li>
47
+ <li><pre>{
48
+ "id": "gpt-4-turbo-2024-04-09",
49
+ "object": "model",
50
+ "created": 1706745938,
51
+ "owned_by": "cursor"
52
+ }</pre></li>
53
+ <li><pre>{
54
+ "id": "gpt-4o-128k",
55
+ "object": "model",
56
+ "created": 1706745938,
57
+ "owned_by": "cursor"
58
+ }</pre></li>
59
+ <li><pre>{
60
+ "id": "gemini-1.5-flash-500k",
61
+ "object": "model",
62
+ "created": 1706745938,
63
+ "owned_by": "cursor"
64
+ }</pre></li>
65
+ <li><pre>{
66
+ "id": "claude-3-haiku-200k",
67
+ "object": "model",
68
+ "created": 1706745938,
69
+ "owned_by": "cursor"
70
+ }</pre></li>
71
+ <li><pre>{
72
+ "id": "claude-3-5-sonnet-200k",
73
+ "object": "model",
74
+ "created": 1706745938,
75
+ "owned_by": "cursor"
76
+ }</pre></li>
77
+ <li><pre>{
78
+ "id": "claude-3-5-sonnet-20241022",
79
+ "object": "model",
80
+ "created": 1706745938,
81
+ "owned_by": "cursor"
82
+ }</pre></li>
83
+ <li><pre>{
84
+ "id": "gpt-4o-mini",
85
+ "object": "model",
86
+ "created": 1706745938,
87
+ "owned_by": "cursor"
88
+ }</pre></li>
89
+ <li><pre>{
90
+ "id": "o1-mini",
91
+ "object": "model",
92
+ "created": 1706745938,
93
+ "owned_by": "cursor"
94
+ }</pre></li>
95
+ <li><pre>{
96
+ "id": "o1-preview",
97
+ "object": "model",
98
+ "created": 1706745938,
99
+ "owned_by": "cursor"
100
+ }</pre></li>
101
+ <li><pre>{
102
+ "id": "claude-3.5-haiku",
103
+ "object": "model",
104
+ "created": 1706745938,
105
+ "owned_by": "cursor"
106
+ }</pre></li>
107
+ <li><pre>{
108
+ "id": "gemini-exp-1206",
109
+ "object": "model",
110
+ "created": 1706745938,
111
+ "owned_by": "cursor"
112
+ }</pre></li>
113
+ <li><pre>{
114
+ "id": "gemini-2.0-flash-thinking-exp",
115
+ "object": "model",
116
+ "created": 1706745938,
117
+ "owned_by": "cursor"
118
+ }</pre></li>
119
+ <li><pre>{
120
+ "id": "gemini-2.0-flash-exp",
121
+ "object": "model",
122
+ "created": 1706745938,
123
+ "owned_by": "cursor"
124
+ }</pre></li>
125
+ <li><pre>{
126
+ "id": "deepseek-v3",
127
+ "object": "model",
128
+ "created": 1706745938,
129
+ "owned_by": "cursor"
130
+ }</pre></li>
131
+ <li><pre>{
132
+ "id": "deepseek-r1",
133
+ "object": "model",
134
+ "created": 1706745938,
135
+ "owned_by": "cursor"
136
+ }</pre></li>
137
+ </ul>
138
+ `;
139
+
140
  const htmlContent = `
141
  <!DOCTYPE html>
142
  <html lang="en">
143
  <head>
144
  <meta charset="UTF-8">
145
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
146
+ <title>My Static Page</title>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  </head>
148
  <body>
149
+ <p>
150
+ Cursor To OpenAI Server <br />
151
+ 聊天来源: 自定义(兼容 OpenAI) <br />
152
+ 自定义端点(基本URL):<span id="endpoint-url"></span> <br />
153
+ 自定义API密钥:[抓取的Cursor Cookie,格式为user_...] <br />
154
+ </p>
155
+ <h3>支持的模型:</h3>
156
+ ${modelListHTML}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  <script>
158
  const url = new URL(window.location.href);
159
  const link = url.protocol + '//' + url.host + '/hf/v1';
160
  document.getElementById('endpoint-url').textContent = link;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  </script>
162
  </body>
163
  </html>
 
170
  console.log(`HF Proxy server is running at PORT: ${port}`);
171
  });
172
 
173
+