update test

This commit is contained in:
duanfuxiang 2025-02-18 13:39:50 +08:00
parent 0c9589f380
commit 2eb86db028
5 changed files with 163 additions and 42 deletions

View File

@ -1,5 +1,5 @@
export type { FewShotExample } from "./shared"; export type { FewShotExample } from "./shared";
export { DEFAULT_AUTOCOMPLETE_SETTINGS as DEFAULT_SETTINGS, settingsSchema, pluginDataSchema } from "./v1/v1"; export { DEFAULT_SETTINGS as DEFAULT_SETTINGS, settingsSchema, pluginDataSchema } from "./v1/v1";
export type { Settings, Trigger, PluginData } from "./v1/v1"; export type { Settings, Trigger, PluginData } from "./v1/v1";
export { export {
MAX_DELAY, MAX_FREQUENCY_PENALTY, MAX_DELAY, MAX_FREQUENCY_PENALTY,

View File

@ -9,7 +9,7 @@ import {
settingsSchema as settingsSchemaV0 settingsSchema as settingsSchemaV0
} from "./v0/v0"; } from "./v0/v0";
import { import {
DEFAULT_AUTOCOMPLETE_SETTINGS as DEFAULT_SETTINGS_V1, DEFAULT_SETTINGS as DEFAULT_SETTINGS_V1,
Settings as SettingsV1, Settings as SettingsV1,
settingsSchema as settingsSchemaV1 settingsSchema as settingsSchemaV1
} from "./v1/v1"; } from "./v1/v1";

View File

@ -95,7 +95,7 @@ export const pluginDataSchema = z.object({
}).strict(); }).strict();
export const DEFAULT_AUTOCOMPLETE_SETTINGS = { export const DEFAULT_SETTINGS = {
// version: "1", // version: "1",
// General settings // General settings

View File

@ -1,7 +1,7 @@
import { DEFAULT_MODELS } from '../constants' import { DEFAULT_MODELS } from '../constants'
import { DEFAULT_AUTOCOMPLETE_SETTINGS } from '../settings/versions/v1/v1' import { DEFAULT_SETTINGS } from '../settings/versions/v1/v1'
import { SETTINGS_SCHEMA_VERSION, parseInfioSettings } from './settings' import { parseInfioSettings } from './settings'
describe('parseSmartCopilotSettings', () => { describe('parseSmartCopilotSettings', () => {
it('should return default values for empty input', () => { it('should return default values for empty input', () => {
@ -15,7 +15,25 @@ describe('parseSmartCopilotSettings', () => {
geminiApiKey: '', geminiApiKey: '',
groqApiKey: '', groqApiKey: '',
deepseekApiKey: '', deepseekApiKey: '',
chatModelId: 'deepseek-chat', chatModelId: '',
chatModelProvider: 'OpenRouter',
applyModelId: '',
applyModelProvider: 'OpenRouter',
embeddingModelId: '',
embeddingModelProvider: 'Google',
defaultProvider: 'OpenRouter',
alibabaQwenProvider: {
name: 'AlibabaQwen',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
anthropicProvider: {
name: 'Anthropic',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
ollamaChatModel: { ollamaChatModel: {
baseUrl: '', baseUrl: '',
model: '', model: '',
@ -25,7 +43,6 @@ describe('parseSmartCopilotSettings', () => {
apiKey: '', apiKey: '',
model: '', model: '',
}, },
applyModelId: 'deepseek-chat',
ollamaApplyModel: { ollamaApplyModel: {
baseUrl: '', baseUrl: '',
model: '', model: '',
@ -35,7 +52,6 @@ describe('parseSmartCopilotSettings', () => {
apiKey: '', apiKey: '',
model: '', model: '',
}, },
embeddingModelId: 'text-embedding-004',
ollamaEmbeddingModel: { ollamaEmbeddingModel: {
baseUrl: '', baseUrl: '',
model: '', model: '',
@ -55,7 +71,7 @@ describe('parseSmartCopilotSettings', () => {
azureOAIApiSettings: '', azureOAIApiSettings: '',
openAIApiSettings: '', openAIApiSettings: '',
ollamaApiSettings: '', ollamaApiSettings: '',
triggers: DEFAULT_AUTOCOMPLETE_SETTINGS.triggers, triggers: DEFAULT_SETTINGS.triggers,
delay: 500, delay: 500,
modelOptions: { modelOptions: {
temperature: 1, temperature: 1,
@ -64,8 +80,8 @@ describe('parseSmartCopilotSettings', () => {
presence_penalty: 0, presence_penalty: 0,
max_tokens: 800, max_tokens: 800,
}, },
systemMessage: DEFAULT_AUTOCOMPLETE_SETTINGS.systemMessage, systemMessage: DEFAULT_SETTINGS.systemMessage,
fewShotExamples: DEFAULT_AUTOCOMPLETE_SETTINGS.fewShotExamples, fewShotExamples: DEFAULT_SETTINGS.fewShotExamples,
userMessageTemplate: '{{prefix}}<mask/>{{suffix}}', userMessageTemplate: '{{prefix}}<mask/>{{suffix}}',
chainOfThoughRemovalRegex: '(.|\\n)*ANSWER:', chainOfThoughRemovalRegex: '(.|\\n)*ANSWER:',
dontIncludeDataviews: true, dontIncludeDataviews: true,
@ -77,6 +93,60 @@ describe('parseSmartCopilotSettings', () => {
ignoredTags: '', ignoredTags: '',
cacheSuggestions: true, cacheSuggestions: true,
debugMode: false, debugMode: false,
deepseekProvider: {
name: 'DeepSeek',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
googleProvider: {
name: 'Google',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
groqProvider: {
name: 'Groq',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
infioProvider: {
name: 'Infio',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
ollamaProvider: {
name: 'Ollama',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
openaiProvider: {
name: 'OpenAI',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
openaicompatibleProvider: {
name: 'OpenAICompatible',
apiKey: '',
baseUrl: '',
useCustomUrl: true,
},
openrouterProvider: {
name: 'OpenRouter',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
siliconflowProvider: {
name: 'SiliconFlow',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
}) })
}) })
}) })
@ -110,7 +180,25 @@ describe('settings migration', () => {
geminiApiKey: '', geminiApiKey: '',
groqApiKey: '', groqApiKey: '',
deepseekApiKey: '', deepseekApiKey: '',
chatModelId: 'deepseek-chat', chatModelId: '',
chatModelProvider: 'OpenRouter',
applyModelId: '',
applyModelProvider: 'OpenRouter',
embeddingModelId: '',
embeddingModelProvider: 'Google',
defaultProvider: 'OpenRouter',
alibabaQwenProvider: {
name: 'AlibabaQwen',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
anthropicProvider: {
name: 'Anthropic',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
ollamaChatModel: { ollamaChatModel: {
baseUrl: '', baseUrl: '',
model: '', model: '',
@ -120,7 +208,6 @@ describe('settings migration', () => {
apiKey: '', apiKey: '',
model: '', model: '',
}, },
applyModelId: 'deepseek-chat',
ollamaApplyModel: { ollamaApplyModel: {
baseUrl: '', baseUrl: '',
model: '', model: '',
@ -130,7 +217,6 @@ describe('settings migration', () => {
apiKey: '', apiKey: '',
model: '', model: '',
}, },
embeddingModelId: 'text-embedding-004',
ollamaEmbeddingModel: { ollamaEmbeddingModel: {
baseUrl: '', baseUrl: '',
model: '', model: '',
@ -150,7 +236,7 @@ describe('settings migration', () => {
azureOAIApiSettings: '', azureOAIApiSettings: '',
openAIApiSettings: '', openAIApiSettings: '',
ollamaApiSettings: '', ollamaApiSettings: '',
triggers: DEFAULT_AUTOCOMPLETE_SETTINGS.triggers, triggers: DEFAULT_SETTINGS.triggers,
delay: 500, delay: 500,
modelOptions: { modelOptions: {
temperature: 1, temperature: 1,
@ -159,8 +245,8 @@ describe('settings migration', () => {
presence_penalty: 0, presence_penalty: 0,
max_tokens: 800, max_tokens: 800,
}, },
systemMessage: DEFAULT_AUTOCOMPLETE_SETTINGS.systemMessage, systemMessage: DEFAULT_SETTINGS.systemMessage,
fewShotExamples: DEFAULT_AUTOCOMPLETE_SETTINGS.fewShotExamples, fewShotExamples: DEFAULT_SETTINGS.fewShotExamples,
userMessageTemplate: '{{prefix}}<mask/>{{suffix}}', userMessageTemplate: '{{prefix}}<mask/>{{suffix}}',
chainOfThoughRemovalRegex: '(.|\\n)*ANSWER:', chainOfThoughRemovalRegex: '(.|\\n)*ANSWER:',
dontIncludeDataviews: true, dontIncludeDataviews: true,
@ -172,6 +258,60 @@ describe('settings migration', () => {
ignoredTags: '', ignoredTags: '',
cacheSuggestions: true, cacheSuggestions: true,
debugMode: false, debugMode: false,
deepseekProvider: {
name: 'DeepSeek',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
googleProvider: {
name: 'Google',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
groqProvider: {
name: 'Groq',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
infioProvider: {
name: 'Infio',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
ollamaProvider: {
name: 'Ollama',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
openaiProvider: {
name: 'OpenAI',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
openaicompatibleProvider: {
name: 'OpenAICompatible',
apiKey: '',
baseUrl: '',
useCustomUrl: true,
},
openrouterProvider: {
name: 'OpenRouter',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
siliconflowProvider: {
name: 'SiliconFlow',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
}) })
}) })
}) })

View File

@ -9,11 +9,11 @@ import {
fewShotExampleSchema, fewShotExampleSchema,
modelOptionsSchema modelOptionsSchema
} from '../settings/versions/shared'; } from '../settings/versions/shared';
import { DEFAULT_AUTOCOMPLETE_SETTINGS } from "../settings/versions/v1/v1"; import { DEFAULT_SETTINGS } from "../settings/versions/v1/v1";
import { ApiProvider } from '../types/llm/model'; import { ApiProvider } from '../types/llm/model';
import { isRegexValid, isValidIgnorePattern } from '../utils/auto-complete'; import { isRegexValid, isValidIgnorePattern } from '../utils/auto-complete';
export const SETTINGS_SCHEMA_VERSION = 0.1 export const SETTINGS_SCHEMA_VERSION = 0.4
const InfioProviderSchema = z.object({ const InfioProviderSchema = z.object({
name: z.literal('Infio'), name: z.literal('Infio'),
@ -328,29 +328,11 @@ type Migration = {
const MIGRATIONS: Migration[] = [ const MIGRATIONS: Migration[] = [
{ {
fromVersion: 0, fromVersion: 0.1,
toVersion: 1, toVersion: 0.4,
migrate: (data) => { migrate: (data) => {
const newData = { ...data } const newData = { ...data }
if ( newData.version = SETTINGS_SCHEMA_VERSION
'ollamaBaseUrl' in newData &&
typeof newData.ollamaBaseUrl === 'string'
) {
newData.ollamaChatModel = {
baseUrl: newData.ollamaBaseUrl,
model: '',
}
newData.ollamaApplyModel = {
baseUrl: newData.ollamaBaseUrl,
model: '',
}
newData.ollamaEmbeddingModel = {
baseUrl: newData.ollamaBaseUrl,
model: '',
}
delete newData.ollamaBaseUrl
}
return newData return newData
}, },
}, },
@ -383,7 +365,6 @@ export function parseInfioSettings(data: unknown): InfioSettings {
const migratedData = migrateSettings(data as Record<string, unknown>) const migratedData = migrateSettings(data as Record<string, unknown>)
return InfioSettingsSchema.parse(migratedData) return InfioSettingsSchema.parse(migratedData)
} catch (error) { } catch (error) {
// console.warn('Invalid settings provided, using defaults:', error) return InfioSettingsSchema.parse({ ...DEFAULT_SETTINGS })
return InfioSettingsSchema.parse({ ...DEFAULT_AUTOCOMPLETE_SETTINGS })
} }
} }