mirror of
https://github.com/linshenkx/prompt-optimizer.git
synced 2026-06-06 22:49:53 +08:00
## 核心改进 ### 🏗️ 架构重构 - 实现ImageModelManager组件分离设计,关注点明确分离 - 重构ModelManager.vue为统一模型管理入口,支持文本/图像双模式 - 采用组件复用和扩展性设计,易于添加新模型类型 ### 🎨 界面优化 - 摒弃5步导航式编辑,改为一体化界面设计 - 优化ImageModelEditModal为单页滚动布局,提升操作效率 - 统一文本和图像模型管理的交互体验和视觉风格 ### 🔌 适配器扩展 - 新增OpenRouter和SiliconFlow图像适配器支持 - 完善AbstractImageProviderAdapter抽象基类设计 - 优化适配器注册表和动态模型发现机制 ### 💻 类型系统 - 完善ImageModelConfig和相关类型定义 - 增强TypeScript类型安全和智能提示 - 优化服务层接口设计和依赖注入架构 ### 🧪 测试覆盖 - 新增图像适配器单元测试和集成测试 - 添加E2E验收测试保证功能完整性 - 增强连接测试和参数验证测试覆盖 ### 📚 文档完善 - 新增图像模型管理架构设计文档 - 添加一体化界面改进方案文档 - 更新项目结构和开发指南 ## 技术特点 - **SOLID原则**:清晰的单一职责和开闭扩展设计 - **组合模式**:ImageModelManager + ModelManager.vue 组合架构 - **响应式设计**:基于Vue 3 Composition API的状态管理 - **依赖注入**:松耦合的服务架构和组件通信 这次重构显著提升了图像模型管理的用户体验和代码可维护性, 为后续音频、视频等多模态功能扩展奠定了坚实基础。
67 lines
2.2 KiB
JavaScript
67 lines
2.2 KiB
JavaScript
import { createLLMService, ModelManager, LocalStorageProvider } from '../../../src/index.js';
|
||
import { expect, describe, it, beforeEach, beforeAll } from 'vitest';
|
||
import dotenv from 'dotenv';
|
||
import path from 'path';
|
||
|
||
// 加载环境变量
|
||
beforeAll(() => {
|
||
dotenv.config({ path: path.resolve(process.cwd(), '.env.local') });
|
||
});
|
||
|
||
const RUN_REAL_API = process.env.RUN_REAL_API === '1'
|
||
|
||
describe.skipIf(!RUN_REAL_API)('Gemini API 测试', () => {
|
||
// 跳过没有设置 API 密钥的测试
|
||
const apiKey = process.env.VITE_GEMINI_API_KEY;
|
||
if (!apiKey) {
|
||
console.log('跳过 Gemini 测试:未设置 VITE_GEMINI_API_KEY 环境变量');
|
||
it.skip('应该能正确调用 Gemini API', () => {});
|
||
it.skip('应该能正确处理多轮对话', () => {});
|
||
return;
|
||
}
|
||
|
||
it('应该能正确调用 Gemini API', async () => {
|
||
const storage = new LocalStorageProvider();
|
||
const modelManager = new ModelManager(storage);
|
||
const llmService = createLLMService(modelManager);
|
||
|
||
// 更新 Gemini 配置
|
||
await modelManager.updateModel('gemini', {
|
||
apiKey,
|
||
enabled: true
|
||
});
|
||
|
||
const messages = [
|
||
{ role: 'user', content: '你好,请用一句话介绍你自己' }
|
||
];
|
||
|
||
const response = await llmService.sendMessage(messages, 'gemini');
|
||
expect(response).toBeDefined();
|
||
expect(typeof response).toBe('string');
|
||
expect(response.length).toBeGreaterThan(0);
|
||
}, 10000);
|
||
|
||
it('应该能正确处理多轮对话', async () => {
|
||
const storage = new LocalStorageProvider();
|
||
const modelManager = new ModelManager(storage);
|
||
const llmService = createLLMService(modelManager);
|
||
|
||
// 更新 Gemini 配置
|
||
await modelManager.updateModel('gemini', {
|
||
apiKey,
|
||
enabled: true
|
||
});
|
||
|
||
const messages = [
|
||
{ role: 'user', content: '你好,我们来玩个游戏' },
|
||
{ role: 'assistant', content: '好啊,你想玩什么游戏?' },
|
||
{ role: 'user', content: '我们来玩猜数字游戏,1到100之间' }
|
||
];
|
||
|
||
const response = await llmService.sendMessage(messages, 'gemini');
|
||
expect(response).toBeDefined();
|
||
expect(typeof response).toBe('string');
|
||
expect(response.length).toBeGreaterThan(0);
|
||
}, 10000);
|
||
});
|