(controller)
| 126 | |
| 127 | const responseStream = new ReadableStream({ |
| 128 | async start(controller) { |
| 129 | for await (const chunk of stream) { |
| 130 | if (chunk.choices[0]?.delta?.content) { |
| 131 | controller.enqueue(encoder.encode(`data: ${JSON.stringify(chunk)}\n\n`)); |
| 132 | } |
| 133 | } |
| 134 | controller.enqueue(encoder.encode("data: [DONE]\n\n")); |
| 135 | controller.close(); |
| 136 | }, |
| 137 | cancel() { |
| 138 | // 当流被取消时,关闭 OpenAI 流 |
| 139 | if (stream.controller) { |
nothing calls this directly
no outgoing calls
no test coverage detected