(controller)
| 130 | const decoder = new TextDecoder(); |
| 131 | const stream = new ReadableStream({ |
| 132 | async start(controller) { |
| 133 | const streamParser = (event: ParsedEvent | ReconnectInterval) => { |
| 134 | if (event.type === "event") { |
| 135 | const data = event.data; |
| 136 | if (data === "[DONE]") { |
| 137 | controller.close(); |
| 138 | return; |
| 139 | } |
| 140 | try { |
| 141 | const json = JSON.parse(data); |
| 142 | const text = json.choices[0].delta?.content; |
| 143 | const queue = encoder.encode(text); |
| 144 | controller.enqueue(queue); |
| 145 | } catch (e) { |
| 146 | controller.error(e); |
| 147 | } |
| 148 | } |
| 149 | }; |
| 150 | const parser = createParser(streamParser); |
| 151 | for await (const chunk of remoteRes.body as any) { |
| 152 | parser.feed(decoder.decode(chunk)); |
| 153 | } |
| 154 | }, |
| 155 | }); |
| 156 | |
| 157 | if (useServerKey && hasFeature("quota")) { |
nothing calls this directly
no outgoing calls
no test coverage detected