| 28 | } |
| 29 | |
| 30 | protected async *_streamChat( |
| 31 | messages: ChatMessage[], |
| 32 | signal: AbortSignal, |
| 33 | options: CompletionOptions, |
| 34 | ): AsyncGenerator<ChatMessage> { |
| 35 | if (this.customStreamChat) { |
| 36 | for await (const content of this.customStreamChat( |
| 37 | messages, |
| 38 | signal, |
| 39 | options, |
| 40 | (...args) => this.fetch(...args), |
| 41 | )) { |
| 42 | if (typeof content === "string") { |
| 43 | yield { role: "assistant", content }; |
| 44 | } else { |
| 45 | yield content; |
| 46 | } |
| 47 | } |
| 48 | } else { |
| 49 | for await (const update of super._streamChat(messages, signal, options)) { |
| 50 | yield update; |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | protected async *_streamComplete( |
| 56 | prompt: string, |