(sseStreamer: IServerSideEventStreamer, chatId: string, response: string)
| 14 | // is this the correct location for this function? |
| 15 | // should we have a utils files that all node components can use? |
| 16 | export const streamResponse = (sseStreamer: IServerSideEventStreamer, chatId: string, response: string) => { |
| 17 | const result = response.split(/(\s+)/) |
| 18 | result.forEach((token: string, index: number) => { |
| 19 | if (index === 0) { |
| 20 | sseStreamer.streamStartEvent(chatId, token) |
| 21 | } |
| 22 | sseStreamer.streamTokenEvent(chatId, token) |
| 23 | }) |
| 24 | sseStreamer.streamEndEvent(chatId) |
| 25 | } |