From 91e65d6445a959cb1586d1e296d8f1307e10c888 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Wed, 17 Sep 2025 16:02:08 +0800 Subject: [PATCH] feat(ui): Support multi knowledgebases operation --- .github/workflows/docker-image.yml | 28 +- Makefile | 17 +- config/config.yaml | 2 +- docker/Dockerfile.app | 14 +- frontend/src/api/auth/index.ts | 4 +- frontend/src/api/chat/index.ts | 7 - frontend/src/api/chat/streame.ts | 18 +- frontend/src/api/initialization/index.ts | 41 +- frontend/src/api/knowledge-base/index.ts | 59 +- frontend/src/api/system/index.ts | 12 + frontend/src/api/test-data/index.ts | 64 - frontend/src/components/menu.vue | 528 ++- frontend/src/hooks/useKnowledgeBase.ts | 69 +- frontend/src/router/index.ts | 67 +- frontend/src/stores/auth.ts | 5 - frontend/src/stores/knowledge.ts | 4 +- frontend/src/stores/menu.ts | 5 +- frontend/src/utils/index.ts | 14 +- frontend/src/utils/request.ts | 22 - frontend/src/views/auth/Login.vue | 6 - frontend/src/views/chat/index.vue | 11 +- frontend/src/views/creatChat/creatChat.vue | 86 +- .../initialization/InitializationConfig.vue | 3498 ----------------- .../initialization/InitializationContent.vue | 171 +- .../src/views/knowledge/KnowledgeBase.vue | 143 +- .../src/views/knowledge/KnowledgeBaseList.vue | 234 ++ .../src/views/settings/SystemSettings.vue | 96 +- frontend/src/views/tenant/TenantInfo.vue | 57 +- internal/application/service/evaluation.go | 63 +- internal/application/service/test_data.go | 444 --- internal/container/container.go | 3 +- internal/handler/initialization.go | 471 +-- internal/handler/session.go | 4 - internal/handler/system.go | 49 + internal/handler/test_data.go | 87 - internal/models/chat/remote_api.go | 8 + internal/router/router.go | 21 +- scripts/build_images.sh | 39 + scripts/get_version.sh | 86 + 39 files changed, 1718 insertions(+), 4839 deletions(-) create mode 100644 frontend/src/api/system/index.ts delete mode 100644 frontend/src/api/test-data/index.ts delete mode 100644 frontend/src/views/initialization/InitializationConfig.vue create mode 100644 frontend/src/views/knowledge/KnowledgeBaseList.vue delete mode 100644 internal/application/service/test_data.go create mode 100644 internal/handler/system.go delete mode 100644 internal/handler/test_data.go create mode 100755 scripts/get_version.sh diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index d7c121d..aef205f 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -42,8 +42,25 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} - - name: Read VERSION file - run: echo "VERSION=$(cat VERSION)" >> $GITHUB_ENV + - name: Set up Go + if: matrix.service_name == 'app' + uses: actions/setup-go@v4 + with: + go-version: '1.24' + + - name: Prepare version info + id: version + run: | + # 使用统一的版本管理脚本 + eval $(./scripts/get_version.sh env) + + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "commit_id=$COMMIT_ID" >> $GITHUB_OUTPUT + echo "build_time=$BUILD_TIME" >> $GITHUB_OUTPUT + echo "go_version=$GO_VERSION" >> $GITHUB_OUTPUT + + # 显示版本信息 + ./scripts/get_version.sh info - name: Build ${{ matrix.service_name }} Image uses: docker/build-push-action@v3 @@ -52,8 +69,13 @@ jobs: platforms: ${{ matrix.platform }} file: ${{ matrix.file }} context: ${{ matrix.context }} + build-args: | + ${{ matrix.service_name == 'app' && format('VERSION_ARG={0}', steps.version.outputs.version) || '' }} + ${{ matrix.service_name == 'app' && format('COMMIT_ID_ARG={0}', steps.version.outputs.commit_id) || '' }} + ${{ matrix.service_name == 'app' && format('BUILD_TIME_ARG={0}', steps.version.outputs.build_time) || '' }} + ${{ matrix.service_name == 'app' && format('GO_VERSION_ARG={0}', steps.version.outputs.go_version) || '' }} tags: | ${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:latest - ${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:${{ env.VERSION }} + ${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:${{ steps.version.outputs.version }} cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:cache cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:cache,mode=max \ No newline at end of file diff --git a/Makefile b/Makefile index b8d414a..dde85f4 100644 --- a/Makefile +++ b/Makefile @@ -85,7 +85,15 @@ clean: # Build Docker image docker-build-app: - docker build --platform $(PLATFORM) -f docker/Dockerfile.app -t $(DOCKER_IMAGE):$(DOCKER_TAG) . + @echo "获取版本信息..." + @eval $$(./scripts/get_version.sh env); \ + ./scripts/get_version.sh info; \ + docker build --platform $(PLATFORM) \ + --build-arg VERSION_ARG="$$VERSION" \ + --build-arg COMMIT_ID_ARG="$$COMMIT_ID" \ + --build-arg BUILD_TIME_ARG="$$BUILD_TIME" \ + --build-arg GO_VERSION_ARG="$$GO_VERSION" \ + -f docker/Dockerfile.app -t $(DOCKER_IMAGE):$(DOCKER_TAG) . # Build docreader Docker image docker-build-docreader: @@ -168,7 +176,12 @@ deps: # Build for production build-prod: - GOOS=linux go build -installsuffix cgo -ldflags="-w -s" -o $(BINARY_NAME) $(MAIN_PATH) + @VERSION=$${VERSION:-unknown}; \ + COMMIT_ID=$${COMMIT_ID:-unknown}; \ + BUILD_TIME=$${BUILD_TIME:-unknown}; \ + GO_VERSION=$${GO_VERSION:-unknown}; \ + LDFLAGS="-X 'github.com/Tencent/WeKnora/internal/handler.Version=$$VERSION' -X 'github.com/Tencent/WeKnora/internal/handler.CommitID=$$COMMIT_ID' -X 'github.com/Tencent/WeKnora/internal/handler.BuildTime=$$BUILD_TIME' -X 'github.com/Tencent/WeKnora/internal/handler.GoVersion=$$GO_VERSION'"; \ + GOOS=linux go build -installsuffix cgo -ldflags="-w -s $$LDFLAGS" -o $(BINARY_NAME) $(MAIN_PATH) clean-db: @echo "Cleaning database..." diff --git a/config/config.yaml b/config/config.yaml index d739a83..4caa32c 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -9,7 +9,7 @@ conversation: keyword_threshold: 0.3 embedding_top_k: 10 vector_threshold: 0.5 - rerank_threshold: 0.7 + rerank_threshold: 0.5 rerank_top_k: 5 fallback_strategy: "fixed" fallback_response: "抱歉,我无法回答这个问题。" diff --git a/docker/Dockerfile.app b/docker/Dockerfile.app index 5a9c93b..7cdc149 100644 --- a/docker/Dockerfile.app +++ b/docker/Dockerfile.app @@ -28,7 +28,19 @@ RUN go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate # Copy source code COPY . . -# Build the application +# Get version and commit info for build injection +ARG VERSION_ARG +ARG COMMIT_ID_ARG +ARG BUILD_TIME_ARG +ARG GO_VERSION_ARG + +# Set build-time variables +ENV VERSION=${VERSION_ARG} +ENV COMMIT_ID=${COMMIT_ID_ARG} +ENV BUILD_TIME=${BUILD_TIME_ARG} +ENV GO_VERSION=${GO_VERSION_ARG} + +# Build the application with version info RUN make build-prod # Final stage diff --git a/frontend/src/api/auth/index.ts b/frontend/src/api/auth/index.ts index 4fe4767..85efb6a 100644 --- a/frontend/src/api/auth/index.ts +++ b/frontend/src/api/auth/index.ts @@ -143,10 +143,10 @@ export async function register(data: RegisterRequest): Promise /** * 获取当前用户信息 */ -export async function getCurrentUser(): Promise<{ success: boolean; data?: UserInfo; message?: string }> { +export async function getCurrentUser(): Promise<{ success: boolean; data?: { user: UserInfo; tenant: TenantInfo }; message?: string }> { try { const response = await get('/api/v1/auth/me') - return response as unknown as { success: boolean; data?: UserInfo; message?: string } + return response as unknown as { success: boolean; data?: { user: UserInfo; tenant: TenantInfo }; message?: string } } catch (error: any) { return { success: false, diff --git a/frontend/src/api/chat/index.ts b/frontend/src/api/chat/index.ts index 32f0b17..2d5fe31 100644 --- a/frontend/src/api/chat/index.ts +++ b/frontend/src/api/chat/index.ts @@ -1,30 +1,24 @@ import { get, post, put, del, postChat } from "../../utils/request"; -import { loadTestData } from "../test-data"; export async function createSessions(data = {}) { - await loadTestData(); return post("/api/v1/sessions", data); } export async function getSessionsList(page: number, page_size: number) { - await loadTestData(); return get(`/api/v1/sessions?page=${page}&page_size=${page_size}`); } export async function generateSessionsTitle(session_id: string, data: any) { - await loadTestData(); return post(`/api/v1/sessions/${session_id}/generate_title`, data); } export async function knowledgeChat(data: { session_id: string; query: string; }) { - await loadTestData(); return postChat(`/api/v1/knowledge-chat/${data.session_id}`, { query: data.query }); } export async function getMessageList(data: { session_id: string; limit: number, created_at: string }) { - await loadTestData(); if (data.created_at) { return get(`/api/v1/messages/${data.session_id}/load?before_time=${encodeURIComponent(data.created_at)}&limit=${data.limit}`); } else { @@ -33,6 +27,5 @@ export async function getMessageList(data: { session_id: string; limit: number, } export async function delSession(session_id: string) { - await loadTestData(); return del(`/api/v1/sessions/${session_id}`); } \ No newline at end of file diff --git a/frontend/src/api/chat/streame.ts b/frontend/src/api/chat/streame.ts index f7d8dae..26cb490 100644 --- a/frontend/src/api/chat/streame.ts +++ b/frontend/src/api/chat/streame.ts @@ -1,8 +1,6 @@ import { fetchEventSource } from '@microsoft/fetch-event-source' import { ref, type Ref, onUnmounted, nextTick } from 'vue' import { generateRandomString } from '@/utils/index'; -import { getTestData } from '@/utils/request'; -import { loadTestData } from "../test-data"; @@ -37,16 +35,16 @@ export function useStream() { isStreaming.value = true; isLoading.value = true; - // 使用默认配置 - await loadTestData(); - const testData = getTestData(); - if (!testData) { - error.value = "测试数据未初始化,无法进行聊天"; + // 获取API配置 + const apiUrl = import.meta.env.VITE_IS_DOCKER ? "" : "http://localhost:8080"; + + // 获取JWT Token + const token = localStorage.getItem('weknora_token'); + if (!token) { + error.value = "未找到登录令牌,请重新登录"; stopStream(); return; } - const apiUrl = import.meta.env.VITE_IS_DOCKER ? "" : "http://localhost:8080"; - const apiKey = testData.tenant.api_key; try { let url = @@ -57,7 +55,7 @@ export function useStream() { method: params.method, headers: { "Content-Type": "application/json", - "X-API-Key": apiKey, + "Authorization": `Bearer ${token}`, "X-Request-ID": `${generateRandomString(12)}`, }, body: diff --git a/frontend/src/api/initialization/index.ts b/frontend/src/api/initialization/index.ts index c42f148..4231cdb 100644 --- a/frontend/src/api/initialization/index.ts +++ b/frontend/src/api/initialization/index.ts @@ -63,38 +63,19 @@ export interface DownloadTask { endTime?: string; } -// 系统初始化状态检查 -export function checkInitializationStatus(): Promise<{ initialized: boolean }> { - return new Promise((resolve, reject) => { - get('/api/v1/initialization/status') - .then((response: any) => { - resolve(response.data || { initialized: false }); - }) - .catch((error: any) => { - // 如果是401,交给全局拦截器去处理(重定向登录),这里不要把它当成未初始化 - if (error && error.status === 401) { - reject(error); - return; - } - console.warn('检查初始化状态失败,假设需要初始化:', error); - resolve({ initialized: false }); - }); - }); -} -// 执行系统初始化 -export function initializeSystem(config: InitializationConfig): Promise { + +// 根据知识库ID执行配置更新 +export function initializeSystemByKB(kbId: string, config: InitializationConfig): Promise { return new Promise((resolve, reject) => { - console.log('开始系统初始化...', config); - post('/api/v1/initialization/initialize', config) + console.log('开始知识库配置更新...', kbId, config); + post(`/api/v1/initialization/initialize/${kbId}`, config) .then((response: any) => { - console.log('系统初始化完成', response); - // 设置本地初始化状态标记 - localStorage.setItem('system_initialized', 'true'); + console.log('知识库配置更新完成', response); resolve(response); }) .catch((error: any) => { - console.error('系统初始化失败:', error); + console.error('知识库配置更新失败:', error); reject(error); }); }); @@ -184,15 +165,15 @@ export function listDownloadTasks(): Promise { }); } -// 获取当前系统配置 -export function getCurrentConfig(): Promise { + +export function getCurrentConfigByKB(kbId: string): Promise { return new Promise((resolve, reject) => { - get('/api/v1/initialization/config') + get(`/api/v1/initialization/config/${kbId}`) .then((response: any) => { resolve(response.data || {}); }) .catch((error: any) => { - console.error('获取当前配置失败:', error); + console.error('获取知识库配置失败:', error); reject(error); }); }); diff --git a/frontend/src/api/knowledge-base/index.ts b/frontend/src/api/knowledge-base/index.ts index 557a209..e507d33 100644 --- a/frontend/src/api/knowledge-base/index.ts +++ b/frontend/src/api/knowledge-base/index.ts @@ -1,44 +1,55 @@ -import { get, post, put, del, postUpload, getDown, getTestData } from "../../utils/request"; -import { loadTestData } from "../test-data"; -export async function getDefaultKnowledgeBaseId(): Promise { - // 如果设置中没有知识库ID,则使用测试数据 - await loadTestData(); - const testData = getTestData(); - if (!testData || testData.knowledge_bases.length === 0) { - throw new Error('没有可用的知识库'); - } - - return testData.knowledge_bases[0].id; +import { get, post, put, del, postUpload, getDown } from "../../utils/request"; + +// 知识库管理 API(列表、创建、获取、更新、删除、复制) +export function listKnowledgeBases() { + return get(`/api/v1/knowledge-bases`); } -export async function uploadKnowledgeBase(data = {}) { - const kbId = await getDefaultKnowledgeBaseId(); +export function createKnowledgeBase(data: { name: string; description?: string; chunking_config?: any }) { + return post(`/api/v1/knowledge-bases`, data); +} + +export function getKnowledgeBaseById(id: string) { + return get(`/api/v1/knowledge-bases/${id}`); +} + +export function updateKnowledgeBase(id: string, data: { name: string; description?: string; config: any }) { + return put(`/api/v1/knowledge-bases/${id}` , data); +} + +export function deleteKnowledgeBase(id: string) { + return del(`/api/v1/knowledge-bases/${id}`); +} + +export function copyKnowledgeBase(data: { source_id: string; target_id?: string }) { + return post(`/api/v1/knowledge-bases/copy`, data); +} + +// 知识文件 API(基于具体知识库) +export function uploadKnowledgeFile(kbId: string, data = {}) { return postUpload(`/api/v1/knowledge-bases/${kbId}/knowledge/file`, data); } -export async function getKnowledgeBase({page, page_size}: {page: number, page_size: number}) { - const kbId = await getDefaultKnowledgeBaseId(); - return get( - `/api/v1/knowledge-bases/${kbId}/knowledge?page=${page}&page_size=${page_size}` - ); +export function listKnowledgeFiles(kbId: string, { page, page_size }: { page: number; page_size: number }) { + return get(`/api/v1/knowledge-bases/${kbId}/knowledge?page=${page}&page_size=${page_size}`); } -export function getKnowledgeDetails(id: any) { +export function getKnowledgeDetails(id: string) { return get(`/api/v1/knowledge/${id}`); } -export function delKnowledgeDetails(id: any) { +export function delKnowledgeDetails(id: string) { return del(`/api/v1/knowledge/${id}`); } -export function downKnowledgeDetails(id: any) { +export function downKnowledgeDetails(id: string) { return getDown(`/api/v1/knowledge/${id}/download`); } -export function batchQueryKnowledge(ids: any) { - return get(`/api/v1/knowledge/batch?${ids}`); +export function batchQueryKnowledge(idsQueryString: string) { + return get(`/api/v1/knowledge/batch?${idsQueryString}`); } -export function getKnowledgeDetailsCon(id: any, page: number) { +export function getKnowledgeDetailsCon(id: string, page: number) { return get(`/api/v1/chunks/${id}?page=${page}&page_size=25`); } \ No newline at end of file diff --git a/frontend/src/api/system/index.ts b/frontend/src/api/system/index.ts new file mode 100644 index 0000000..4101101 --- /dev/null +++ b/frontend/src/api/system/index.ts @@ -0,0 +1,12 @@ +import { get } from '@/utils/request' + +export interface SystemInfo { + version: string + commit_id?: string + build_time?: string + go_version?: string +} + +export function getSystemInfo(): Promise<{ data: SystemInfo }> { + return get('/api/v1/system/info') +} diff --git a/frontend/src/api/test-data/index.ts b/frontend/src/api/test-data/index.ts deleted file mode 100644 index ef99e45..0000000 --- a/frontend/src/api/test-data/index.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { get, setTestData } from '../../utils/request'; - -export interface TestDataResponse { - success: boolean; - data: { - tenant: { - id: number; - name: string; - api_key: string; - }; - knowledge_bases: Array<{ - id: string; - name: string; - description: string; - }>; - } -} - -// 是否已加载测试数据 -let isTestDataLoaded = false; - -/** - * 加载测试数据 - * 在API调用前调用此函数以确保测试数据已加载 - * @returns Promise 是否成功加载 - */ -export async function loadTestData(): Promise { - // 如果已经加载过,直接返回 - if (isTestDataLoaded) { - return true; - } - - try { - console.log('开始加载测试数据...'); - const response = await get('/api/v1/test-data'); - console.log('测试数据', response); - - if (response && response.data) { - // 设置测试数据 - setTestData({ - tenant: response.data.tenant, - knowledge_bases: response.data.knowledge_bases - }); - isTestDataLoaded = true; - console.log('测试数据加载成功'); - return true; - } else { - console.warn('测试数据响应为空'); - return false; - } - } catch (error) { - console.error('加载测试数据失败:', error); - return false; - } -} - -/** - * 重置测试数据加载状态,在重新登录或需要强制刷新时调用 - */ -export function resetTestDataLoaded() { - isTestDataLoaded = false; - // 清空已缓存的测试数据,确保下次调用会重新获取 - setTestData(null); -} diff --git a/frontend/src/components/menu.vue b/frontend/src/components/menu.vue index afb55ca..d5ca73b 100644 --- a/frontend/src/components/menu.vue +++ b/frontend/src/components/menu.vue @@ -1,25 +1,48 @@ - \ No newline at end of file diff --git a/frontend/src/views/initialization/InitializationContent.vue b/frontend/src/views/initialization/InitializationContent.vue index 1cd8b63..5552a37 100644 --- a/frontend/src/views/initialization/InitializationContent.vue +++ b/frontend/src/views/initialization/InitializationContent.vue @@ -1,5 +1,6 @@ @@ -733,15 +750,15 @@ * 导入必要的 Vue 组合式 API 和外部依赖 */ import { ref, reactive, computed, watch, onMounted, onUnmounted, nextTick } from 'vue'; -import { useRouter } from 'vue-router'; +import { useRouter, useRoute } from 'vue-router'; import { MessagePlugin } from 'tdesign-vue-next'; import { - initializeSystem, + initializeSystemByKB, checkOllamaStatus, checkOllamaModels, downloadOllamaModel, getDownloadProgress, - getCurrentConfig, + getCurrentConfigByKB, checkRemoteModel, type DownloadTask, checkRerankModel, @@ -749,10 +766,22 @@ import { listOllamaModels, testEmbeddingModel } from '@/api/initialization'; +import { getKnowledgeBaseById } from '@/api/knowledge-base'; import { useAuthStore } from '@/stores/auth'; const router = useRouter(); +const route = useRoute(); const authStore = useAuthStore(); + +// 接收props,判断是否为知识库设置模式 +const props = defineProps<{ + isKbSettings?: boolean; +}>(); + +// 获取当前知识库ID(如果是知识库设置模式) +const currentKbId = computed(() => { + return props.isKbSettings ? (route.params.kbId as string) : null; +}); type TFormRef = { validate: (fields?: string[] | undefined) => Promise; clearValidate?: (fields?: string | string[]) => void; @@ -824,6 +853,9 @@ const modelStatus = reactive({ // 表单数据 const formData = reactive({ + // 知识库基本信息 (仅在知识库设置模式下使用) + kbName: '', + kbDescription: '', llm: { source: 'local', modelName: '', @@ -867,8 +899,8 @@ const formData = reactive({ } }, documentSplitting: { - chunkSize: 1000, - chunkOverlap: 200, + chunkSize: 512, + chunkOverlap: 100, separators: ['\n\n', '\n', '。', '!', '?', ';', ';'] } }); @@ -880,7 +912,7 @@ const inputDebounceTimers = reactive>({}); const embeddingDimDetecting = ref(false); // 预设配置选择 -const selectedPreset = ref('balanced'); +const selectedPreset = ref('precision'); // 分隔符选项 const separatorOptions = [ @@ -1011,6 +1043,14 @@ const validateEmbeddingDimension = (val: any) => { // 表单验证规则 const rules = { + // 知识库基本信息验证 (仅在知识库设置模式下使用) + 'kbName': [ + { required: (t: any) => props.isKbSettings, message: '请输入知识库名称', type: 'error' }, + { min: 1, max: 50, message: '知识库名称长度应在1-50个字符之间', type: 'error' } + ], + 'kbDescription': [ + { max: 200, message: '知识库描述长度不能超过200个字符', type: 'error' } + ], 'llm.modelName': [{ required: true, message: '请输入LLM模型名称', type: 'error' }], 'llm.baseUrl': [ { required: (t: any) => formData.llm.source === 'remote', message: '请输入BaseURL', type: 'error' } @@ -1191,7 +1231,22 @@ const startProgressPolling = (type: 'llm' | 'embedding' | 'vlm', taskId: string, // 配置回填 const loadCurrentConfig = async () => { try { - const config = await getCurrentConfig(); + // 如果是知识库设置模式,先加载知识库基本信息 + if (props.isKbSettings && currentKbId.value) { + try { + const kbInfo = await getKnowledgeBaseById(currentKbId.value); + if (kbInfo && kbInfo.data) { + formData.kbName = kbInfo.data.name || ''; + formData.kbDescription = kbInfo.data.description || ''; + } + } catch (error) { + console.error('获取知识库信息失败:', error); + MessagePlugin.error('获取知识库信息失败'); + } + } + + // 根据是否为知识库设置模式选择不同的API + const config = await getCurrentConfigByKB(currentKbId.value); // 设置hasFiles状态 hasFiles.value = config.hasFiles || false; @@ -1234,6 +1289,9 @@ const loadCurrentConfig = async () => { } else { selectedPreset.value = 'custom'; } + } else { + // 如果没有文档分割配置,确保使用默认的precision模式 + selectedPreset.value = 'precision'; } // 在配置加载完成后,检查模型状态 @@ -1883,21 +1941,43 @@ const handleSubmit = async () => { submitting.value = true; + // 如果是知识库设置模式,先更新知识库基本信息 + if (props.isKbSettings && currentKbId.value) { + try { + const { updateKnowledgeBase } = await import('@/api/knowledge-base'); + await updateKnowledgeBase(currentKbId.value, { + name: formData.kbName, + description: formData.kbDescription, + config: {} // 空的config对象,因为这里只更新基本信息 + }); + } catch (error) { + console.error('更新知识库基本信息失败:', error); + MessagePlugin.error('更新知识库基本信息失败'); + return; + } + } + // 确保embedding.dimension是数字类型 if (formData.embedding.dimension) { formData.embedding.dimension = Number(formData.embedding.dimension); } - // 直接使用formData,API期望原始结构 - const result = await initializeSystem(formData); + // 根据是否为知识库设置模式选择不同的API + const result = await initializeSystemByKB(currentKbId.value, formData); if (result.success) { - MessagePlugin.success(isUpdateMode.value ? '配置更新成功' : '系统初始化完成'); + MessagePlugin.success(props.isKbSettings ? '知识库设置更新成功' : (isUpdateMode.value ? '配置更新成功' : '系统初始化完成')); - // 如果是初始化模式,跳转到主页面 - if (!isUpdateMode.value) { + // 根据不同模式进行跳转 + if (props.isKbSettings && currentKbId.value) { + // 知识库设置模式,跳转回知识库详情页面 setTimeout(() => { - router.push('/platform/knowledgeBase'); + router.push(`/platform/knowledge-bases/${currentKbId.value}`); + }, 1500); + } else if (!isUpdateMode.value) { + // 初始化模式,跳转到知识库列表页面 + setTimeout(() => { + router.push('/platform/knowledge-bases'); }, 1500); } } else { @@ -1940,7 +2020,18 @@ onMounted(async () => { diff --git a/frontend/src/views/settings/SystemSettings.vue b/frontend/src/views/settings/SystemSettings.vue index 730b3d0..17ba9e1 100644 --- a/frontend/src/views/settings/SystemSettings.vue +++ b/frontend/src/views/settings/SystemSettings.vue @@ -2,23 +2,109 @@
-

系统设置

-

管理和更新系统模型与服务配置

+

{{ isKbSettings ? '知识库设置' : '系统设置' }}

+

{{ isKbSettings ? '配置该知识库的模型与文档切分参数' : '管理和更新系统模型与服务配置' }}

- - + + + +
+ +
+

⚙️基础信息

+ + + + + + +
+
+

📄文档切分

+ + + + + + + + + + + + +
+
+ 保存 +
+
+