feat:新增dify接入知识库时更新文档嵌入参数的功能
This commit is contained in:
@@ -225,6 +225,44 @@ export async function fetchUploadFileInfo(
|
||||
return response.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文档原始文件
|
||||
* 通过代理路由下载 Dify 知识库中的原始文件
|
||||
*
|
||||
* @param uploadFileInfo - 上传文件信息(从 fetchUploadFileInfo 获取)
|
||||
* @returns File 对象
|
||||
*/
|
||||
export async function downloadOriginalFile(
|
||||
uploadFileInfo: UploadFileInfo
|
||||
): Promise<File> {
|
||||
if (!uploadFileInfo.download_url) {
|
||||
throw new Error('无法获取原始文件下载地址');
|
||||
}
|
||||
|
||||
// download_url 格式: /files/xxx/file-preview?...
|
||||
// 转换为代理路由: /api/dataset/dify-files/xxx/file-preview?...
|
||||
const downloadPath = uploadFileInfo.download_url.replace(/^\/files\//, '');
|
||||
const proxyUrl = `${API_URL}/dify-files/${downloadPath}`;
|
||||
|
||||
console.log('[Dataset Client] 下载原始文件:', {
|
||||
originalUrl: uploadFileInfo.download_url,
|
||||
proxyUrl,
|
||||
});
|
||||
|
||||
const response = await axios.get(proxyUrl, {
|
||||
responseType: 'blob',
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
const file = new File(
|
||||
[response.data],
|
||||
uploadFileInfo.name || 'document',
|
||||
{ type: uploadFileInfo.mime_type || 'application/octet-stream' }
|
||||
);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 预处理规则 ID
|
||||
*/
|
||||
@@ -244,6 +282,7 @@ export interface PreProcessingRule {
|
||||
export interface SegmentationConfig {
|
||||
separator: string;
|
||||
max_tokens: number;
|
||||
chunk_overlap?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user