Skip to content

Commit b04566b

Browse files
authored
Support multi knowledgebases operation
2 parents c589a91 + 0157eb2 commit b04566b

File tree

39 files changed

+1718
-4839
lines changed

39 files changed

+1718
-4839
lines changed

.github/workflows/docker-image.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,25 @@ jobs:
4242
username: ${{ secrets.DOCKERHUB_USERNAME }}
4343
password: ${{ secrets.DOCKERHUB_PASSWORD }}
4444

45-
- name: Read VERSION file
46-
run: echo "VERSION=$(cat VERSION)" >> $GITHUB_ENV
45+
- name: Set up Go
46+
if: matrix.service_name == 'app'
47+
uses: actions/setup-go@v4
48+
with:
49+
go-version: '1.24'
50+
51+
- name: Prepare version info
52+
id: version
53+
run: |
54+
# 使用统一的版本管理脚本
55+
eval $(./scripts/get_version.sh env)
56+
57+
echo "version=$VERSION" >> $GITHUB_OUTPUT
58+
echo "commit_id=$COMMIT_ID" >> $GITHUB_OUTPUT
59+
echo "build_time=$BUILD_TIME" >> $GITHUB_OUTPUT
60+
echo "go_version=$GO_VERSION" >> $GITHUB_OUTPUT
61+
62+
# 显示版本信息
63+
./scripts/get_version.sh info
4764
4865
- name: Build ${{ matrix.service_name }} Image
4966
uses: docker/build-push-action@v3
@@ -52,8 +69,13 @@ jobs:
5269
platforms: ${{ matrix.platform }}
5370
file: ${{ matrix.file }}
5471
context: ${{ matrix.context }}
72+
build-args: |
73+
${{ matrix.service_name == 'app' && format('VERSION_ARG={0}', steps.version.outputs.version) || '' }}
74+
${{ matrix.service_name == 'app' && format('COMMIT_ID_ARG={0}', steps.version.outputs.commit_id) || '' }}
75+
${{ matrix.service_name == 'app' && format('BUILD_TIME_ARG={0}', steps.version.outputs.build_time) || '' }}
76+
${{ matrix.service_name == 'app' && format('GO_VERSION_ARG={0}', steps.version.outputs.go_version) || '' }}
5577
tags: |
5678
${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:latest
57-
${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:${{ env.VERSION }}
79+
${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:${{ steps.version.outputs.version }}
5880
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:cache
5981
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:cache,mode=max

Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,15 @@ clean:
8585

8686
# Build Docker image
8787
docker-build-app:
88-
docker build --platform $(PLATFORM) -f docker/Dockerfile.app -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
88+
@echo "获取版本信息..."
89+
@eval $$(./scripts/get_version.sh env); \
90+
./scripts/get_version.sh info; \
91+
docker build --platform $(PLATFORM) \
92+
--build-arg VERSION_ARG="$$VERSION" \
93+
--build-arg COMMIT_ID_ARG="$$COMMIT_ID" \
94+
--build-arg BUILD_TIME_ARG="$$BUILD_TIME" \
95+
--build-arg GO_VERSION_ARG="$$GO_VERSION" \
96+
-f docker/Dockerfile.app -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
8997

9098
# Build docreader Docker image
9199
docker-build-docreader:
@@ -168,7 +176,12 @@ deps:
168176

169177
# Build for production
170178
build-prod:
171-
GOOS=linux go build -installsuffix cgo -ldflags="-w -s" -o $(BINARY_NAME) $(MAIN_PATH)
179+
@VERSION=$${VERSION:-unknown}; \
180+
COMMIT_ID=$${COMMIT_ID:-unknown}; \
181+
BUILD_TIME=$${BUILD_TIME:-unknown}; \
182+
GO_VERSION=$${GO_VERSION:-unknown}; \
183+
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'"; \
184+
GOOS=linux go build -installsuffix cgo -ldflags="-w -s $$LDFLAGS" -o $(BINARY_NAME) $(MAIN_PATH)
172185

173186
clean-db:
174187
@echo "Cleaning database..."

config/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ conversation:
99
keyword_threshold: 0.3
1010
embedding_top_k: 10
1111
vector_threshold: 0.5
12-
rerank_threshold: 0.7
12+
rerank_threshold: 0.5
1313
rerank_top_k: 5
1414
fallback_strategy: "fixed"
1515
fallback_response: "抱歉,我无法回答这个问题。"

docker/Dockerfile.app

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,19 @@ RUN go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate
2828
# Copy source code
2929
COPY . .
3030

31-
# Build the application
31+
# Get version and commit info for build injection
32+
ARG VERSION_ARG
33+
ARG COMMIT_ID_ARG
34+
ARG BUILD_TIME_ARG
35+
ARG GO_VERSION_ARG
36+
37+
# Set build-time variables
38+
ENV VERSION=${VERSION_ARG}
39+
ENV COMMIT_ID=${COMMIT_ID_ARG}
40+
ENV BUILD_TIME=${BUILD_TIME_ARG}
41+
ENV GO_VERSION=${GO_VERSION_ARG}
42+
43+
# Build the application with version info
3244
RUN make build-prod
3345

3446
# Final stage

frontend/src/api/auth/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ export async function register(data: RegisterRequest): Promise<RegisterResponse>
143143
/**
144144
* 获取当前用户信息
145145
*/
146-
export async function getCurrentUser(): Promise<{ success: boolean; data?: UserInfo; message?: string }> {
146+
export async function getCurrentUser(): Promise<{ success: boolean; data?: { user: UserInfo; tenant: TenantInfo }; message?: string }> {
147147
try {
148148
const response = await get('/api/v1/auth/me')
149-
return response as unknown as { success: boolean; data?: UserInfo; message?: string }
149+
return response as unknown as { success: boolean; data?: { user: UserInfo; tenant: TenantInfo }; message?: string }
150150
} catch (error: any) {
151151
return {
152152
success: false,

frontend/src/api/chat/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
11
import { get, post, put, del, postChat } from "../../utils/request";
2-
import { loadTestData } from "../test-data";
32

43

54

65
export async function createSessions(data = {}) {
7-
await loadTestData();
86
return post("/api/v1/sessions", data);
97
}
108

119
export async function getSessionsList(page: number, page_size: number) {
12-
await loadTestData();
1310
return get(`/api/v1/sessions?page=${page}&page_size=${page_size}`);
1411
}
1512

1613
export async function generateSessionsTitle(session_id: string, data: any) {
17-
await loadTestData();
1814
return post(`/api/v1/sessions/${session_id}/generate_title`, data);
1915
}
2016

2117
export async function knowledgeChat(data: { session_id: string; query: string; }) {
22-
await loadTestData();
2318
return postChat(`/api/v1/knowledge-chat/${data.session_id}`, { query: data.query });
2419
}
2520

2621
export async function getMessageList(data: { session_id: string; limit: number, created_at: string }) {
27-
await loadTestData();
2822
if (data.created_at) {
2923
return get(`/api/v1/messages/${data.session_id}/load?before_time=${encodeURIComponent(data.created_at)}&limit=${data.limit}`);
3024
} else {
@@ -33,6 +27,5 @@ export async function getMessageList(data: { session_id: string; limit: number,
3327
}
3428

3529
export async function delSession(session_id: string) {
36-
await loadTestData();
3730
return del(`/api/v1/sessions/${session_id}`);
3831
}

frontend/src/api/chat/streame.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { fetchEventSource } from '@microsoft/fetch-event-source'
22
import { ref, type Ref, onUnmounted, nextTick } from 'vue'
33
import { generateRandomString } from '@/utils/index';
4-
import { getTestData } from '@/utils/request';
5-
import { loadTestData } from "../test-data";
64

75

86

@@ -37,16 +35,16 @@ export function useStream() {
3735
isStreaming.value = true;
3836
isLoading.value = true;
3937

40-
// 使用默认配置
41-
await loadTestData();
42-
const testData = getTestData();
43-
if (!testData) {
44-
error.value = "测试数据未初始化,无法进行聊天";
38+
// 获取API配置
39+
const apiUrl = import.meta.env.VITE_IS_DOCKER ? "" : "http://localhost:8080";
40+
41+
// 获取JWT Token
42+
const token = localStorage.getItem('weknora_token');
43+
if (!token) {
44+
error.value = "未找到登录令牌,请重新登录";
4545
stopStream();
4646
return;
4747
}
48-
const apiUrl = import.meta.env.VITE_IS_DOCKER ? "" : "http://localhost:8080";
49-
const apiKey = testData.tenant.api_key;
5048

5149
try {
5250
let url =
@@ -57,7 +55,7 @@ export function useStream() {
5755
method: params.method,
5856
headers: {
5957
"Content-Type": "application/json",
60-
"X-API-Key": apiKey,
58+
"Authorization": `Bearer ${token}`,
6159
"X-Request-ID": `${generateRandomString(12)}`,
6260
},
6361
body:

frontend/src/api/initialization/index.ts

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -63,38 +63,19 @@ export interface DownloadTask {
6363
endTime?: string;
6464
}
6565

66-
// 系统初始化状态检查
67-
export function checkInitializationStatus(): Promise<{ initialized: boolean }> {
68-
return new Promise((resolve, reject) => {
69-
get('/api/v1/initialization/status')
70-
.then((response: any) => {
71-
resolve(response.data || { initialized: false });
72-
})
73-
.catch((error: any) => {
74-
// 如果是401,交给全局拦截器去处理(重定向登录),这里不要把它当成未初始化
75-
if (error && error.status === 401) {
76-
reject(error);
77-
return;
78-
}
79-
console.warn('检查初始化状态失败,假设需要初始化:', error);
80-
resolve({ initialized: false });
81-
});
82-
});
83-
}
8466

85-
// 执行系统初始化
86-
export function initializeSystem(config: InitializationConfig): Promise<any> {
67+
68+
// 根据知识库ID执行配置更新
69+
export function initializeSystemByKB(kbId: string, config: InitializationConfig): Promise<any> {
8770
return new Promise((resolve, reject) => {
88-
console.log('开始系统初始化...', config);
89-
post('/api/v1/initialization/initialize', config)
71+
console.log('开始知识库配置更新...', kbId, config);
72+
post(`/api/v1/initialization/initialize/${kbId}`, config)
9073
.then((response: any) => {
91-
console.log('系统初始化完成', response);
92-
// 设置本地初始化状态标记
93-
localStorage.setItem('system_initialized', 'true');
74+
console.log('知识库配置更新完成', response);
9475
resolve(response);
9576
})
9677
.catch((error: any) => {
97-
console.error('系统初始化失败:', error);
78+
console.error('知识库配置更新失败:', error);
9879
reject(error);
9980
});
10081
});
@@ -184,15 +165,15 @@ export function listDownloadTasks(): Promise<DownloadTask[]> {
184165
});
185166
}
186167

187-
// 获取当前系统配置
188-
export function getCurrentConfig(): Promise<InitializationConfig & { hasFiles: boolean }> {
168+
169+
export function getCurrentConfigByKB(kbId: string): Promise<InitializationConfig & { hasFiles: boolean }> {
189170
return new Promise((resolve, reject) => {
190-
get('/api/v1/initialization/config')
171+
get(`/api/v1/initialization/config/${kbId}`)
191172
.then((response: any) => {
192173
resolve(response.data || {});
193174
})
194175
.catch((error: any) => {
195-
console.error('获取当前配置失败:', error);
176+
console.error('获取知识库配置失败:', error);
196177
reject(error);
197178
});
198179
});
Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,55 @@
1-
import { get, post, put, del, postUpload, getDown, getTestData } from "../../utils/request";
2-
import { loadTestData } from "../test-data";
3-
export async function getDefaultKnowledgeBaseId(): Promise<string> {
4-
// 如果设置中没有知识库ID,则使用测试数据
5-
await loadTestData();
6-
const testData = getTestData();
7-
if (!testData || testData.knowledge_bases.length === 0) {
8-
throw new Error('没有可用的知识库');
9-
}
10-
11-
return testData.knowledge_bases[0].id;
12-
}
13-
14-
export async function uploadKnowledgeBase(data = {}) {
15-
const kbId = await getDefaultKnowledgeBaseId();
1+
import { get, post, put, del, postUpload, getDown } from "../../utils/request";
2+
3+
// 知识库管理 API(列表、创建、获取、更新、删除、复制)
4+
export function listKnowledgeBases() {
5+
return get(`/api/v1/knowledge-bases`);
6+
}
7+
8+
export function createKnowledgeBase(data: { name: string; description?: string; chunking_config?: any }) {
9+
return post(`/api/v1/knowledge-bases`, data);
10+
}
11+
12+
export function getKnowledgeBaseById(id: string) {
13+
return get(`/api/v1/knowledge-bases/${id}`);
14+
}
15+
16+
export function updateKnowledgeBase(id: string, data: { name: string; description?: string; config: any }) {
17+
return put(`/api/v1/knowledge-bases/${id}` , data);
18+
}
19+
20+
export function deleteKnowledgeBase(id: string) {
21+
return del(`/api/v1/knowledge-bases/${id}`);
22+
}
23+
24+
export function copyKnowledgeBase(data: { source_id: string; target_id?: string }) {
25+
return post(`/api/v1/knowledge-bases/copy`, data);
26+
}
27+
28+
// 知识文件 API(基于具体知识库)
29+
export function uploadKnowledgeFile(kbId: string, data = {}) {
1630
return postUpload(`/api/v1/knowledge-bases/${kbId}/knowledge/file`, data);
1731
}
1832

19-
export async function getKnowledgeBase({page, page_size}: {page: number, page_size: number}) {
20-
const kbId = await getDefaultKnowledgeBaseId();
21-
return get(
22-
`/api/v1/knowledge-bases/${kbId}/knowledge?page=${page}&page_size=${page_size}`
23-
);
33+
export function listKnowledgeFiles(kbId: string, { page, page_size }: { page: number; page_size: number }) {
34+
return get(`/api/v1/knowledge-bases/${kbId}/knowledge?page=${page}&page_size=${page_size}`);
2435
}
2536

26-
export function getKnowledgeDetails(id: any) {
37+
export function getKnowledgeDetails(id: string) {
2738
return get(`/api/v1/knowledge/${id}`);
2839
}
2940

30-
export function delKnowledgeDetails(id: any) {
41+
export function delKnowledgeDetails(id: string) {
3142
return del(`/api/v1/knowledge/${id}`);
3243
}
3344

34-
export function downKnowledgeDetails(id: any) {
45+
export function downKnowledgeDetails(id: string) {
3546
return getDown(`/api/v1/knowledge/${id}/download`);
3647
}
3748

38-
export function batchQueryKnowledge(ids: any) {
39-
return get(`/api/v1/knowledge/batch?${ids}`);
49+
export function batchQueryKnowledge(idsQueryString: string) {
50+
return get(`/api/v1/knowledge/batch?${idsQueryString}`);
4051
}
4152

42-
export function getKnowledgeDetailsCon(id: any, page: number) {
53+
export function getKnowledgeDetailsCon(id: string, page: number) {
4354
return get(`/api/v1/chunks/${id}?page=${page}&page_size=25`);
4455
}

frontend/src/api/system/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { get } from '@/utils/request'
2+
3+
export interface SystemInfo {
4+
version: string
5+
commit_id?: string
6+
build_time?: string
7+
go_version?: string
8+
}
9+
10+
export function getSystemInfo(): Promise<{ data: SystemInfo }> {
11+
return get('/api/v1/system/info')
12+
}

0 commit comments

Comments
 (0)