Spaces:
Paused
Paused
Upload index.js
Browse files
index.js
CHANGED
|
@@ -428,6 +428,32 @@ app.use(cors({
|
|
| 428 |
methods: ['GET', 'POST', 'OPTIONS'],
|
| 429 |
allowedHeaders: ['Content-Type', 'Authorization']
|
| 430 |
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
// API路由
|
| 432 |
app.get('/hf/v1/models', (req, res) => {
|
| 433 |
res.json({
|
|
@@ -596,6 +622,30 @@ async function handleImageResponse(imageUrl) {
|
|
| 596 |
}
|
| 597 |
}
|
| 598 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 599 |
// 404处理
|
| 600 |
app.use((req, res) => {
|
| 601 |
res.status(404).send('请求路径不存在');
|
|
|
|
| 428 |
methods: ['GET', 'POST', 'OPTIONS'],
|
| 429 |
allowedHeaders: ['Content-Type', 'Authorization']
|
| 430 |
}));
|
| 431 |
+
|
| 432 |
+
// 添加请求日志中间件
|
| 433 |
+
app.use((req, res, next) => {
|
| 434 |
+
console.log(`[${new Date().toISOString()}] 收到请求:`, {
|
| 435 |
+
method: req.method,
|
| 436 |
+
path: req.path,
|
| 437 |
+
headers: req.headers,
|
| 438 |
+
body: req.body
|
| 439 |
+
});
|
| 440 |
+
next();
|
| 441 |
+
});
|
| 442 |
+
|
| 443 |
+
// 添加响应日志中间件
|
| 444 |
+
app.use((req, res, next) => {
|
| 445 |
+
const oldSend = res.send;
|
| 446 |
+
res.send = function (data) {
|
| 447 |
+
console.log(`[${new Date().toISOString()}] 发送响应:`, {
|
| 448 |
+
status: res.statusCode,
|
| 449 |
+
headers: res.getHeaders(),
|
| 450 |
+
body: data
|
| 451 |
+
});
|
| 452 |
+
oldSend.apply(res, arguments);
|
| 453 |
+
}
|
| 454 |
+
next();
|
| 455 |
+
});
|
| 456 |
+
|
| 457 |
// API路由
|
| 458 |
app.get('/hf/v1/models', (req, res) => {
|
| 459 |
res.json({
|
|
|
|
| 622 |
}
|
| 623 |
}
|
| 624 |
|
| 625 |
+
// 添加测试端点
|
| 626 |
+
app.post('/hf/v1/test', (req, res) => {
|
| 627 |
+
// 返回OpenAI标准格式示例
|
| 628 |
+
res.json({
|
| 629 |
+
"id": "chatcmpl-123",
|
| 630 |
+
"object": "chat.completion",
|
| 631 |
+
"created": 1677652288,
|
| 632 |
+
"model": "grok-latest-image",
|
| 633 |
+
"choices": [{
|
| 634 |
+
"index": 0,
|
| 635 |
+
"message": {
|
| 636 |
+
"role": "assistant",
|
| 637 |
+
"content": [{
|
| 638 |
+
"type": "image_url",
|
| 639 |
+
"image_url": {
|
| 640 |
+
"url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
|
| 641 |
+
}
|
| 642 |
+
}]
|
| 643 |
+
},
|
| 644 |
+
"finish_reason": "stop"
|
| 645 |
+
}]
|
| 646 |
+
});
|
| 647 |
+
});
|
| 648 |
+
|
| 649 |
// 404处理
|
| 650 |
app.use((req, res) => {
|
| 651 |
res.status(404).send('请求路径不存在');
|