| 669 | }) |
| 670 | |
| 671 | function 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 | |
| 701 | const MODELS_FIXTURE = JSON.parse( |
| 702 | await Bun.file(path.join(import.meta.dir, "../tool/fixtures/models-api.json")).text(), |