feat: Add agent configuration and cleanup scripts for database migrations
This commit is contained in:
@@ -13,7 +13,7 @@ export const useMenuStore = defineStore('menuStore', {
|
||||
childrenPath: 'chat',
|
||||
children: reactive<object[]>([]),
|
||||
},
|
||||
{ title: '系统信息', icon: 'tenant', path: 'tenant' },
|
||||
{ title: '设置', icon: 'setting', path: 'settings' },
|
||||
{ title: '退出登录', icon: 'logout', path: 'logout' }
|
||||
]),
|
||||
isFirstSession: false,
|
||||
|
||||
@@ -5,6 +5,47 @@ interface Settings {
|
||||
endpoint: string;
|
||||
apiKey: string;
|
||||
knowledgeBaseId: string;
|
||||
isAgentEnabled: boolean;
|
||||
agentConfig: AgentConfig;
|
||||
selectedKnowledgeBases: string[]; // 当前选中的知识库ID列表
|
||||
modelConfig: ModelConfig; // 模型配置
|
||||
ollamaConfig: OllamaConfig; // Ollama配置
|
||||
}
|
||||
|
||||
// Agent 配置接口
|
||||
interface AgentConfig {
|
||||
maxIterations: number;
|
||||
temperature: number;
|
||||
thinkingModelId: string;
|
||||
rerankModelId: string;
|
||||
allowedTools: string[];
|
||||
}
|
||||
|
||||
// 单个模型项接口
|
||||
interface ModelItem {
|
||||
id: string; // 唯一ID
|
||||
name: string; // 显示名称
|
||||
source: 'local' | 'remote'; // 模型来源
|
||||
modelName: string; // 模型标识
|
||||
baseUrl?: string; // 远程API URL
|
||||
apiKey?: string; // 远程API Key
|
||||
dimension?: number; // Embedding专用:向量维度
|
||||
interfaceType?: 'ollama' | 'openai'; // VLLM专用:接口类型
|
||||
isDefault?: boolean; // 是否为默认模型
|
||||
}
|
||||
|
||||
// 模型配置接口 - 支持多模型
|
||||
interface ModelConfig {
|
||||
chatModels: ModelItem[];
|
||||
embeddingModels: ModelItem[];
|
||||
rerankModels: ModelItem[];
|
||||
vllmModels: ModelItem[]; // VLLM视觉模型
|
||||
}
|
||||
|
||||
// Ollama 配置接口
|
||||
interface OllamaConfig {
|
||||
baseUrl: string; // Ollama 服务地址
|
||||
enabled: boolean; // 是否启用
|
||||
}
|
||||
|
||||
// 默认设置
|
||||
@@ -12,6 +53,25 @@ const defaultSettings: Settings = {
|
||||
endpoint: import.meta.env.VITE_IS_DOCKER ? "" : "http://localhost:8080",
|
||||
apiKey: "",
|
||||
knowledgeBaseId: "",
|
||||
isAgentEnabled: false,
|
||||
agentConfig: {
|
||||
maxIterations: 5,
|
||||
temperature: 0.7,
|
||||
thinkingModelId: "",
|
||||
rerankModelId: "",
|
||||
allowedTools: ["knowledge_search", "multi_kb_search", "list_knowledge_bases"]
|
||||
},
|
||||
selectedKnowledgeBases: [], // 默认为空数组
|
||||
modelConfig: {
|
||||
chatModels: [],
|
||||
embeddingModels: [],
|
||||
rerankModels: [],
|
||||
vllmModels: []
|
||||
},
|
||||
ollamaConfig: {
|
||||
baseUrl: "http://localhost:11434",
|
||||
enabled: true
|
||||
}
|
||||
};
|
||||
|
||||
export const useSettingsStore = defineStore("settings", {
|
||||
@@ -20,6 +80,17 @@ export const useSettingsStore = defineStore("settings", {
|
||||
settings: JSON.parse(localStorage.getItem("WeKnora_settings") || JSON.stringify(defaultSettings)),
|
||||
}),
|
||||
|
||||
getters: {
|
||||
// Agent 是否启用
|
||||
isAgentEnabled: (state) => state.settings.isAgentEnabled || false,
|
||||
|
||||
// 获取 Agent 配置
|
||||
agentConfig: (state) => state.settings.agentConfig || defaultSettings.agentConfig,
|
||||
|
||||
// 获取模型配置
|
||||
modelConfig: (state) => state.settings.modelConfig || defaultSettings.modelConfig,
|
||||
},
|
||||
|
||||
actions: {
|
||||
// 保存设置
|
||||
saveSettings(settings: Settings) {
|
||||
@@ -47,5 +118,117 @@ export const useSettingsStore = defineStore("settings", {
|
||||
getKnowledgeBaseId(): string {
|
||||
return this.settings.knowledgeBaseId;
|
||||
},
|
||||
|
||||
// 启用/禁用 Agent
|
||||
toggleAgent(enabled: boolean) {
|
||||
this.settings.isAgentEnabled = enabled;
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 更新 Agent 配置
|
||||
updateAgentConfig(config: Partial<AgentConfig>) {
|
||||
this.settings.agentConfig = { ...this.settings.agentConfig, ...config };
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 更新模型配置
|
||||
updateModelConfig(config: Partial<ModelConfig>) {
|
||||
this.settings.modelConfig = { ...this.settings.modelConfig, ...config };
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 添加模型
|
||||
addModel(type: 'chat' | 'embedding' | 'rerank' | 'vllm', model: ModelItem) {
|
||||
const key = `${type}Models` as keyof ModelConfig;
|
||||
const models = [...this.settings.modelConfig[key]] as ModelItem[];
|
||||
// 如果设为默认,取消其他模型的默认状态
|
||||
if (model.isDefault) {
|
||||
models.forEach(m => m.isDefault = false);
|
||||
}
|
||||
// 如果是第一个模型,自动设为默认
|
||||
if (models.length === 0) {
|
||||
model.isDefault = true;
|
||||
}
|
||||
models.push(model);
|
||||
this.settings.modelConfig[key] = models as any;
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 更新模型
|
||||
updateModel(type: 'chat' | 'embedding' | 'rerank' | 'vllm', modelId: string, updates: Partial<ModelItem>) {
|
||||
const key = `${type}Models` as keyof ModelConfig;
|
||||
const models = [...this.settings.modelConfig[key]] as ModelItem[];
|
||||
const index = models.findIndex(m => m.id === modelId);
|
||||
if (index !== -1) {
|
||||
// 如果要设为默认,取消其他模型的默认状态
|
||||
if (updates.isDefault) {
|
||||
models.forEach(m => m.isDefault = false);
|
||||
}
|
||||
models[index] = { ...models[index], ...updates };
|
||||
this.settings.modelConfig[key] = models as any;
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
}
|
||||
},
|
||||
|
||||
// 删除模型
|
||||
deleteModel(type: 'chat' | 'embedding' | 'rerank' | 'vllm', modelId: string) {
|
||||
const key = `${type}Models` as keyof ModelConfig;
|
||||
let models = [...this.settings.modelConfig[key]] as ModelItem[];
|
||||
const deletedModel = models.find(m => m.id === modelId);
|
||||
models = models.filter(m => m.id !== modelId);
|
||||
// 如果删除的是默认模型,设置第一个为默认
|
||||
if (deletedModel?.isDefault && models.length > 0) {
|
||||
models[0].isDefault = true;
|
||||
}
|
||||
this.settings.modelConfig[key] = models as any;
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 设置默认模型
|
||||
setDefaultModel(type: 'chat' | 'embedding' | 'rerank' | 'vllm', modelId: string) {
|
||||
const key = `${type}Models` as keyof ModelConfig;
|
||||
const models = [...this.settings.modelConfig[key]] as ModelItem[];
|
||||
models.forEach(m => m.isDefault = (m.id === modelId));
|
||||
this.settings.modelConfig[key] = models as any;
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 更新 Ollama 配置
|
||||
updateOllamaConfig(config: Partial<OllamaConfig>) {
|
||||
this.settings.ollamaConfig = { ...this.settings.ollamaConfig, ...config };
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 选择知识库(替换整个列表)
|
||||
selectKnowledgeBases(kbIds: string[]) {
|
||||
this.settings.selectedKnowledgeBases = kbIds;
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 添加单个知识库
|
||||
addKnowledgeBase(kbId: string) {
|
||||
if (!this.settings.selectedKnowledgeBases.includes(kbId)) {
|
||||
this.settings.selectedKnowledgeBases.push(kbId);
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
}
|
||||
},
|
||||
|
||||
// 移除单个知识库
|
||||
removeKnowledgeBase(kbId: string) {
|
||||
this.settings.selectedKnowledgeBases =
|
||||
this.settings.selectedKnowledgeBases.filter(id => id !== kbId);
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 清空知识库选择
|
||||
clearKnowledgeBases() {
|
||||
this.settings.selectedKnowledgeBases = [];
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 获取选中的知识库列表
|
||||
getSelectedKnowledgeBases(): string[] {
|
||||
return this.settings.selectedKnowledgeBases || [];
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useUIStore = defineStore('ui', {
|
||||
state: () => ({
|
||||
showSettingsModal: false
|
||||
}),
|
||||
|
||||
actions: {
|
||||
openSettings() {
|
||||
this.showSettingsModal = true
|
||||
},
|
||||
|
||||
closeSettings() {
|
||||
this.showSettingsModal = false
|
||||
},
|
||||
|
||||
toggleSettings() {
|
||||
this.showSettingsModal = !this.showSettingsModal
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user