知识库上传、分段
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
import { api } from '@/apis/index';
|
||||
import type { ResultDomain } from '@/types';
|
||||
import type {
|
||||
DifySegmentListResponse,
|
||||
DifyChildChunkListResponse,
|
||||
DifyChildChunkResponse,
|
||||
SegmentUpdateRequest,
|
||||
@@ -22,13 +21,13 @@ export const documentSegmentApi = {
|
||||
* 获取文档的所有分段(父级)
|
||||
* @param datasetId Dify数据集ID
|
||||
* @param documentId Dify文档ID
|
||||
* @returns Promise<ResultDomain<DifySegmentListResponse>>
|
||||
* @returns Promise<ResultDomain<DifySegment[]>> 后端直接返回分段数组
|
||||
*/
|
||||
async getDocumentSegments(
|
||||
datasetId: string,
|
||||
documentId: string
|
||||
): Promise<ResultDomain<DifySegmentListResponse>> {
|
||||
const response = await api.get<DifySegmentListResponse>(
|
||||
): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>(
|
||||
`/ai/dify/datasets/${datasetId}/documents/${documentId}/segments`
|
||||
);
|
||||
return response.data;
|
||||
@@ -131,14 +130,14 @@ export const documentSegmentApi = {
|
||||
// 1. 获取所有父级分段
|
||||
const segmentsResult = await this.getDocumentSegments(datasetId, documentId);
|
||||
|
||||
if (!segmentsResult.success || !segmentsResult.data?.data) {
|
||||
if (!segmentsResult.success || !segmentsResult.dataList) {
|
||||
throw new Error('获取分段列表失败');
|
||||
}
|
||||
|
||||
// 2. 对每个父级分段,获取其子块
|
||||
const allChunks: any[] = [];
|
||||
|
||||
for (const segment of segmentsResult.data.data) {
|
||||
for (const segment of segmentsResult.dataList) {
|
||||
try {
|
||||
const chunksResult = await this.getChildChunks(
|
||||
datasetId,
|
||||
|
||||
@@ -89,8 +89,10 @@ export const fileUploadApi = {
|
||||
* @param knowledgeId 知识库ID
|
||||
* @returns Promise<ResultDomain<AiUploadFile[]>>
|
||||
*/
|
||||
async listFilesByKnowledge(knowledgeId: string): Promise<ResultDomain<AiUploadFile[]>> {
|
||||
const response = await api.get<AiUploadFile[]>(`/ai/file/knowledge/${knowledgeId}`);
|
||||
async listFilesByKnowledge(knowledgeId: string): Promise<ResultDomain<AiUploadFile>> {
|
||||
const response = await api.get<AiUploadFile>('/ai/file/list', {
|
||||
knowledgeId
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
@@ -138,5 +140,25 @@ export const fileUploadApi = {
|
||||
showLoading: false
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新文档启用/禁用状态
|
||||
* @param datasetId Dify数据集ID
|
||||
* @param documentId Dify文档ID
|
||||
* @param enabled 是否启用
|
||||
* @returns Promise<ResultDomain<void>>
|
||||
*/
|
||||
async updateDocumentStatus(
|
||||
datasetId: string,
|
||||
documentId: string,
|
||||
enabled: boolean
|
||||
): Promise<ResultDomain<void>> {
|
||||
const action = enabled ? 'enable' : 'disable';
|
||||
const response = await api.post<void>(
|
||||
`/ai/dify/datasets/${datasetId}/documents/status/${action}`,
|
||||
{ document_ids: [documentId] }
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -151,6 +151,20 @@ export const knowledgeApi = {
|
||||
async getAvailableRerankModels(): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/ai/knowledge/rerank-models');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取知识库文档列表
|
||||
* @param knowledgeId 知识库ID
|
||||
* @param page 页码(从1开始)
|
||||
* @param limit 每页数量
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async getDocumentList(knowledgeId: string, page = 1, limit = 20): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>(`/ai/knowledge/${knowledgeId}/documents`, {
|
||||
page, limit
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user