mirror of
https://github.com/linshenkx/prompt-optimizer.git
synced 2026-05-06 21:50:27 +08:00
feat: 更新Gemini模型名称并统一异步调用逻辑,修复GoogleGenerativeAI实例创建
- 更新Gemini模型名称从`gemini-2.0-flash-exp`到`gemini-2.0-flash`,确保一致性。 - 统一测试文件中异步方法调用,使用`await`关键字提升代码可读性和稳定性。 - 修复GoogleGenerativeAI实例创建逻辑,直接传入API key。
This commit is contained in:
@@ -108,12 +108,8 @@ export class LLMService implements ILLMService {
|
||||
private getGeminiModel(modelConfig: ModelConfig, systemInstruction?: string, isStream: boolean = false): GenerativeModel {
|
||||
const apiKey = modelConfig.apiKey || '';
|
||||
|
||||
// 创建GoogleGenerativeAI实例配置
|
||||
const genAIConfig: any = {
|
||||
apiKey: apiKey
|
||||
};
|
||||
|
||||
const genAI = new GoogleGenerativeAI(genAIConfig);
|
||||
// 创建GoogleGenerativeAI实例 - 旧版本直接传入字符串API key
|
||||
const genAI = new GoogleGenerativeAI(apiKey);
|
||||
|
||||
// 创建模型配置
|
||||
const modelOptions: any = {
|
||||
|
||||
@@ -56,8 +56,8 @@ describe('PromptService Integration Tests', () => {
|
||||
provider: 'gemini',
|
||||
apiKey: process.env.VITE_GEMINI_API_KEY!,
|
||||
baseURL: 'https://generativelanguage.googleapis.com/v1beta',
|
||||
defaultModel: 'gemini-2.0-flash-exp',
|
||||
models: ['gemini-2.0-flash-exp'],
|
||||
defaultModel: 'gemini-2.0-flash',
|
||||
models: ['gemini-2.0-flash'],
|
||||
enabled: true,
|
||||
llmParams: {
|
||||
temperature: 0.7,
|
||||
|
||||
@@ -158,8 +158,8 @@ describe('Real API Integration Tests', () => {
|
||||
name: 'Google Gemini',
|
||||
baseURL: 'https://generativelanguage.googleapis.com/v1beta',
|
||||
apiKey: process.env.VITE_GEMINI_API_KEY!,
|
||||
models: ['gemini-2.0-flash-exp'],
|
||||
defaultModel: 'gemini-2.0-flash-exp',
|
||||
models: ['gemini-2.0-flash'],
|
||||
defaultModel: 'gemini-2.0-flash',
|
||||
enabled: true,
|
||||
provider: 'gemini' as const
|
||||
}
|
||||
|
||||
@@ -243,9 +243,11 @@ describe('存储实现通用测试', () => {
|
||||
|
||||
describe('HistoryManager 集成测试', () => {
|
||||
let historyManager: HistoryManager;
|
||||
let modelManager: ModelManager;
|
||||
|
||||
beforeEach(() => {
|
||||
historyManager = new HistoryManager(storageProvider);
|
||||
modelManager = createModelManager(storageProvider);
|
||||
historyManager = new HistoryManager(storageProvider, modelManager);
|
||||
});
|
||||
|
||||
it('应该能够添加和获取历史记录', async () => {
|
||||
@@ -341,7 +343,7 @@ describe('存储实现通用测试', () => {
|
||||
};
|
||||
|
||||
await templateManager.saveTemplate(template);
|
||||
const retrieved = templateManager.getTemplate('test-template');
|
||||
const retrieved = await templateManager.getTemplate('test-template');
|
||||
|
||||
expect(retrieved.id).toBe('test-template');
|
||||
expect(retrieved.name).toBe('Test Template');
|
||||
@@ -377,7 +379,7 @@ describe('存储实现通用测试', () => {
|
||||
await templateManager.saveTemplate(template1);
|
||||
await templateManager.saveTemplate(template2);
|
||||
|
||||
const templates = templateManager.listTemplates();
|
||||
const templates = await templateManager.listTemplates();
|
||||
const userTemplates = templates.filter(t => !t.isBuiltin);
|
||||
|
||||
expect(userTemplates).toHaveLength(2);
|
||||
|
||||
Reference in New Issue
Block a user