165 lines
5.3 KiB
TypeScript
165 lines
5.3 KiB
TypeScript
import { get, post, put, del, postUpload, getDown } from "../../utils/request";
|
|
|
|
// 知识库管理 API(列表、创建、获取、更新、删除、复制)
|
|
export function listKnowledgeBases() {
|
|
return get(`/api/v1/knowledge-bases`);
|
|
}
|
|
|
|
export function createKnowledgeBase(data: {
|
|
name: string;
|
|
description?: string;
|
|
type?: 'document' | 'faq';
|
|
chunking_config?: any;
|
|
embedding_model_id?: string;
|
|
summary_model_id?: string;
|
|
vlm_model_id?: string;
|
|
vlm_config?: any;
|
|
cos_config?: any;
|
|
extract_config?: any;
|
|
faq_config?: { index_mode: string; question_index_mode?: string };
|
|
}) {
|
|
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 function createManualKnowledge(kbId: string, data: { title: string; content: string; status: string }) {
|
|
return post(`/api/v1/knowledge-bases/${kbId}/knowledge/manual`, data);
|
|
}
|
|
|
|
export function listKnowledgeFiles(
|
|
kbId: string,
|
|
params: { page: number; page_size: number; tag_id?: string },
|
|
) {
|
|
const query = new URLSearchParams();
|
|
query.append('page', String(params.page));
|
|
query.append('page_size', String(params.page_size));
|
|
if (params.tag_id) {
|
|
query.append('tag_id', params.tag_id);
|
|
}
|
|
const qs = query.toString();
|
|
return get(`/api/v1/knowledge-bases/${kbId}/knowledge?${qs}`);
|
|
}
|
|
|
|
export function getKnowledgeDetails(id: string) {
|
|
return get(`/api/v1/knowledge/${id}`);
|
|
}
|
|
|
|
export function updateManualKnowledge(id: string, data: { title: string; content: string; status: string }) {
|
|
return put(`/api/v1/knowledge/manual/${id}`, data);
|
|
}
|
|
|
|
export function delKnowledgeDetails(id: string) {
|
|
return del(`/api/v1/knowledge/${id}`);
|
|
}
|
|
|
|
export function downKnowledgeDetails(id: string) {
|
|
return getDown(`/api/v1/knowledge/${id}/download`);
|
|
}
|
|
|
|
export function batchQueryKnowledge(idsQueryString: string) {
|
|
return get(`/api/v1/knowledge/batch?${idsQueryString}`);
|
|
}
|
|
|
|
export function getKnowledgeDetailsCon(id: string, page: number) {
|
|
return get(`/api/v1/chunks/${id}?page=${page}&page_size=25`);
|
|
}
|
|
|
|
// Get chunk by chunk_id only (new endpoint - to be added to backend)
|
|
export function getChunkByIdOnly(chunkId: string) {
|
|
return get(`/api/v1/chunks/by-id/${chunkId}`);
|
|
}
|
|
|
|
export function listKnowledgeTags(kbId: string) {
|
|
return get(`/api/v1/knowledge-bases/${kbId}/tags`);
|
|
}
|
|
|
|
export function createKnowledgeBaseTag(
|
|
kbId: string,
|
|
data: { name: string; color?: string; sort_order?: number },
|
|
) {
|
|
return post(`/api/v1/knowledge-bases/${kbId}/tags`, data);
|
|
}
|
|
|
|
export function updateKnowledgeBaseTag(
|
|
kbId: string,
|
|
tagId: string,
|
|
data: { name?: string; color?: string; sort_order?: number },
|
|
) {
|
|
return put(`/api/v1/knowledge-bases/${kbId}/tags/${tagId}`, data);
|
|
}
|
|
|
|
export function deleteKnowledgeBaseTag(kbId: string, tagId: string, params?: { force?: boolean }) {
|
|
const forceQuery = params?.force ? '?force=true' : '';
|
|
return del(`/api/v1/knowledge-bases/${kbId}/tags/${tagId}${forceQuery}`);
|
|
}
|
|
|
|
export function updateKnowledgeTagBatch(data: { updates: Record<string, string | null> }) {
|
|
return put(`/api/v1/knowledge/tags`, data);
|
|
}
|
|
|
|
export function updateFAQEntryTagBatch(kbId: string, data: { updates: Record<string, string | null> }) {
|
|
return put(`/api/v1/knowledge-bases/${kbId}/faq/entries/tags`, data);
|
|
}
|
|
|
|
const buildQuery = (params?: Record<string, any>) => {
|
|
if (!params) return '';
|
|
const query = new URLSearchParams();
|
|
Object.entries(params).forEach(([key, value]) => {
|
|
if (value === undefined || value === null || value === '') return;
|
|
query.append(key, String(value));
|
|
});
|
|
const queryString = query.toString();
|
|
return queryString ? `?${queryString}` : '';
|
|
};
|
|
|
|
export function listFAQEntries(kbId: string, params?: { page?: number; page_size?: number; tag_id?: string }) {
|
|
const query = buildQuery(params);
|
|
return get(`/api/v1/knowledge-bases/${kbId}/faq/entries${query}`);
|
|
}
|
|
|
|
export function upsertFAQEntries(kbId: string, data: { entries: any[]; mode: 'append' | 'replace' }) {
|
|
return post(`/api/v1/knowledge-bases/${kbId}/faq/entries`, data);
|
|
}
|
|
|
|
export function updateFAQEntry(kbId: string, entryId: string, data: any) {
|
|
return put(`/api/v1/knowledge-bases/${kbId}/faq/entries/${entryId}`, data);
|
|
}
|
|
|
|
export function updateFAQEntryStatusBatch(kbId: string, data: { updates: Record<string, boolean> }) {
|
|
return put(`/api/v1/knowledge-bases/${kbId}/faq/entries/status`, data);
|
|
}
|
|
|
|
export function deleteFAQEntries(kbId: string, ids: string[]) {
|
|
return del(`/api/v1/knowledge-bases/${kbId}/faq/entries`, { ids });
|
|
}
|
|
|
|
export function searchFAQEntries(
|
|
kbId: string,
|
|
data: {
|
|
query_text: string
|
|
vector_threshold?: number
|
|
match_count?: number
|
|
}
|
|
) {
|
|
return post(`/api/v1/knowledge-bases/${kbId}/faq/search`, data);
|
|
} |