知识库上传、分段
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,
|
||||
|
||||
Reference in New Issue
Block a user