* 示例1: 直接使用 LLM 管理器
()
| 26 | * 示例1: 直接使用 LLM 管理器 |
| 27 | */ |
| 28 | async function demonstrateLLMManager() { |
| 29 | console.log('=== 示例1: 直接使用 LLM 管理器 ==='); |
| 30 | |
| 31 | try { |
| 32 | // 创建独立的 LLM 管理器 |
| 33 | const llmManager = new LLMManager(true); // 启用调试 |
| 34 | |
| 35 | // 配置 LLM |
| 36 | llmManager.configure({ |
| 37 | provider: 'qwen', |
| 38 | apiKey: process.env.QWEN_API_KEY || 'your-api-key', |
| 39 | model: 'qwen3-235b-a22b', |
| 40 | }); |
| 41 | |
| 42 | // 初始化 |
| 43 | await llmManager.init(); |
| 44 | |
| 45 | // 基础聊天 |
| 46 | const response = await llmManager.chat('你好,请介绍一下自己'); |
| 47 | console.log('LLM 回复:', response.substring(0, 100) + '...'); |
| 48 | |
| 49 | // 检查状态 |
| 50 | console.log('LLM 状态:', llmManager.getStatus()); |
| 51 | |
| 52 | // 销毁 |
| 53 | await llmManager.destroy(); |
| 54 | console.log('LLM 管理器已销毁\n'); |
| 55 | } catch (error) { |
| 56 | console.error('LLM 管理器示例失败:', error); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * 示例2: 直接使用组件管理器 |