(res: Response, body: OpenAIChatRequest, mockText: string)
| 514 | // ==================== 身份探针模拟响应 ==================== |
| 515 | |
| 516 | function handleOpenAIMockStream(res: Response, body: OpenAIChatRequest, mockText: string): void { |
| 517 | res.writeHead(200, { |
| 518 | 'Content-Type': 'text/event-stream', |
| 519 | 'Cache-Control': 'no-cache', |
| 520 | 'Connection': 'keep-alive', |
| 521 | 'X-Accel-Buffering': 'no', |
| 522 | }); |
| 523 | const id = chatId(); |
| 524 | const created = Math.floor(Date.now() / 1000); |
| 525 | writeOpenAISSE(res, { |
| 526 | id, object: 'chat.completion.chunk', created, model: body.model, |
| 527 | choices: [{ index: 0, delta: { role: 'assistant', content: mockText }, finish_reason: null }], |
| 528 | }); |
| 529 | writeOpenAISSE(res, { |
| 530 | id, object: 'chat.completion.chunk', created, model: body.model, |
| 531 | choices: [{ index: 0, delta: {}, finish_reason: 'stop' }], |
| 532 | }); |
| 533 | res.write('data: [DONE]\n\n'); |
| 534 | res.end(); |
| 535 | } |
| 536 | |
| 537 | function handleOpenAIMockNonStream(res: Response, body: OpenAIChatRequest, mockText: string): void { |
| 538 | res.json({ |
no test coverage detected