MCPcopy Index your code
hub / github.com/anomalyco/opencode / createChatStream

Function createChatStream

packages/opencode/test/session/llm.test.ts:671–699  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

669})
670
671function createChatStream(text: string) {
672 const payload =
673 [
674 `data: ${JSON.stringify({
675 id: "chatcmpl-1",
676 object: "chat.completion.chunk",
677 choices: [{ delta: { role: "assistant" } }],
678 })}`,
679 `data: ${JSON.stringify({
680 id: "chatcmpl-1",
681 object: "chat.completion.chunk",
682 choices: [{ delta: { content: text } }],
683 })}`,
684 `data: ${JSON.stringify({
685 id: "chatcmpl-1",
686 object: "chat.completion.chunk",
687 choices: [{ delta: {}, finish_reason: "stop" }],
688 })}`,
689 "data: [DONE]",
690 ].join("\n\n") + "\n\n"
691
692 const encoder = new TextEncoder()
693 return new ReadableStream<Uint8Array>({
694 start(controller) {
695 controller.enqueue(encoder.encode(payload))
696 controller.close()
697 },
698 })
699}
700
701const MODELS_FIXTURE = JSON.parse(
702 await Bun.file(path.join(import.meta.dir, "../tool/fixtures/models-api.json")).text(),

Callers 1

llm.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected