* 使用 AI 生成文本(简化的非流式调用)
( prompt: string, llmConfig: LLMConfig, modelConfig: ModelConfig | undefined )
| 144 | * 使用 AI 生成文本(简化的非流式调用) |
| 145 | */ |
| 146 | async function generateWithAI( |
| 147 | prompt: string, |
| 148 | llmConfig: LLMConfig, |
| 149 | modelConfig: ModelConfig | undefined |
| 150 | ): Promise<string> { |
| 151 | return new Promise((resolve, reject) => { |
| 152 | const aiService = createAIService(llmConfig, modelConfig) |
| 153 | |
| 154 | let fullResponse = '' |
| 155 | |
| 156 | aiService.sendMessage( |
| 157 | [{ id: 'system', role: 'user', content: prompt, createdAt: Date.now() }], |
| 158 | { |
| 159 | onChunk: (chunk) => { |
| 160 | fullResponse += chunk |
| 161 | }, |
| 162 | onComplete: () => { |
| 163 | resolve(fullResponse.trim()) |
| 164 | }, |
| 165 | onError: (error) => { |
| 166 | reject(error) |
| 167 | } |
| 168 | } |
| 169 | ) |
| 170 | }) |
| 171 | } |
| 172 | |
| 173 | // ==================== 导出函数 ==================== |
| 174 |
no test coverage detected