* 流式聊天
(
messages: LLMMessage[],
onChunk: (chunk: string) => void
)
| 159 | * 流式聊天 |
| 160 | */ |
| 161 | public async streamChat( |
| 162 | messages: LLMMessage[], |
| 163 | onChunk: (chunk: string) => void |
| 164 | ): Promise<string> { |
| 165 | this.ensureLLMAvailable(); |
| 166 | |
| 167 | if (this.llm instanceof QwenLLM && this.llm.streamChat) { |
| 168 | this.log('开始流式对话...'); |
| 169 | const response = await this.llm.streamChat({ messages }, onChunk); |
| 170 | this.log('流式对话完成'); |
| 171 | return response.content; |
| 172 | } else { |
| 173 | // 降级到普通聊天 |
| 174 | this.log('流式聊天不支持,降级到普通聊天'); |
| 175 | const request: LLMRequest = { messages }; |
| 176 | const response = await this.llm!.chat(request); |
| 177 | onChunk(response.content); |
| 178 | return response.content; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * 系统提示词聊天 |
nothing calls this directly
no test coverage detected