| 109 | } |
| 110 | |
| 111 | function chatCompletion(model: string, content: string): Record<string, unknown> { |
| 112 | return { |
| 113 | id: `chatcmpl-e2e-${Date.now()}`, |
| 114 | object: "chat.completion", |
| 115 | created: Math.floor(Date.now() / 1000), |
| 116 | model, |
| 117 | choices: [ |
| 118 | { |
| 119 | index: 0, |
| 120 | message: { role: "assistant", content }, |
| 121 | finish_reason: "stop", |
| 122 | }, |
| 123 | ], |
| 124 | usage: { |
| 125 | prompt_tokens: 12, |
| 126 | completion_tokens: Math.max(1, Math.ceil(content.length / 4)), |
| 127 | total_tokens: Math.max(13, Math.ceil(content.length / 4) + 12), |
| 128 | }, |
| 129 | }; |
| 130 | } |
| 131 | |
| 132 | function writeSseCompletion(res: ServerResponse, model: string, content: string): void { |
| 133 | const id = `chatcmpl-e2e-stream-${Date.now()}`; |