MCPcopy Create free account
hub / github.com/Writesonic/GPTRouter / linesToMessages

Function linesToMessages

src/utils/streamCompletion.ts:27–37  ·  view source on GitHub ↗

* Asynchronously converts a stream of lines into messages. * @param {AsyncIterable } linesAsync - Stream of lines to convert into messages. * @returns {AsyncIterable } - An asynchronous iterable that yields parsed messages from the input lines.

(linesAsync: any)

Source from the content-addressed store, hash-verified

25 * @returns {AsyncIterable<any>} - An asynchronous iterable that yields parsed messages from the input lines.
26 */
27async function* linesToMessages(linesAsync: any) {
28 for await (const line of linesAsync) {
29 const message = line.substring("data :".length);
30 try {
31 const parsedMessage = JSON.parse(message);
32 yield parsedMessage;
33 } catch (error) {
34 console.error("Could not JSON parse stream message", message, error);
35 }
36 }
37}
38
39/**
40 * Asynchronously completes the stream by converting chunks to lines and then to messages.

Callers 1

streamCompletionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected