fix: reg failed
This commit is contained in:
parent
0ea464f30f
commit
2ae8d43216
@ -6,11 +6,11 @@ export enum UserAuthTypeEnum {
|
||||
export const PRICE_SCALE = 100000;
|
||||
|
||||
export const fileImgs = [
|
||||
{ reg: /pdf/gi, src: '/imgs/files/pdf.svg' },
|
||||
{ reg: /csv/gi, src: '/imgs/files/csv.svg' },
|
||||
{ reg: /(doc|docs)/gi, src: '/imgs/files/doc.svg' },
|
||||
{ reg: /txt/gi, src: '/imgs/files/txt.svg' },
|
||||
{ reg: /md/gi, src: '/imgs/files/markdown.svg' }
|
||||
{ suffix: 'pdf', src: '/imgs/files/pdf.svg' },
|
||||
{ suffix: 'csv', src: '/imgs/files/csv.svg' },
|
||||
{ suffix: '(doc|docs)', src: '/imgs/files/doc.svg' },
|
||||
{ suffix: 'txt', src: '/imgs/files/txt.svg' },
|
||||
{ suffix: 'md', src: '/imgs/files/markdown.svg' }
|
||||
];
|
||||
|
||||
export const htmlTemplate = `<!DOCTYPE html>
|
||||
|
||||
@ -76,13 +76,18 @@ const FileSelect = ({
|
||||
setSelecting(true);
|
||||
try {
|
||||
// Parse file by file
|
||||
let promise = Promise.resolve<FileItemType[]>([]);
|
||||
files.forEach((file) => {
|
||||
promise = promise.then(async (result) => {
|
||||
const chunkFiles: FileItemType[] = [];
|
||||
|
||||
for await (let file of files) {
|
||||
const extension = file?.name?.split('.')?.pop()?.toLowerCase();
|
||||
|
||||
/* text file */
|
||||
const icon = fileImgs.find((item) => new RegExp(item.reg).test(file.name))?.src;
|
||||
const icon = fileImgs.find((item) => new RegExp(item.suffix, 'gi').test(file.name))?.src;
|
||||
|
||||
if (!icon) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let text = await (async () => {
|
||||
switch (extension) {
|
||||
case 'txt':
|
||||
@ -97,8 +102,6 @@ const FileSelect = ({
|
||||
return '';
|
||||
})();
|
||||
|
||||
if (!icon) return result;
|
||||
|
||||
if (text) {
|
||||
text = simpleText(text);
|
||||
const splitRes = splitText2Chunks({
|
||||
@ -117,7 +120,8 @@ const FileSelect = ({
|
||||
source: file.name
|
||||
}))
|
||||
};
|
||||
return [fileItem].concat(result);
|
||||
chunkFiles.unshift(fileItem);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* csv file */
|
||||
@ -138,14 +142,10 @@ const FileSelect = ({
|
||||
source: item[2] || file.name
|
||||
}))
|
||||
};
|
||||
return [fileItem].concat(result);
|
||||
|
||||
chunkFiles.unshift(fileItem);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
});
|
||||
|
||||
const chunkFiles = await promise;
|
||||
|
||||
onPushFiles(chunkFiles);
|
||||
} catch (error: any) {
|
||||
console.log(error);
|
||||
|
||||
@ -9,6 +9,7 @@ import { axiosConfig, getAIChatApi } from '../ai/openai';
|
||||
import { ChatCompletionRequestMessage } from 'openai';
|
||||
import { modelToolMap } from '@/utils/plugin';
|
||||
import { gptMessage2ChatType } from '@/utils/adapt';
|
||||
import { addLog } from '../utils/tools';
|
||||
|
||||
const reduceQueue = () => {
|
||||
global.qaQueueLen = global.qaQueueLen > 0 ? global.qaQueueLen - 1 : 0;
|
||||
@ -105,12 +106,16 @@ A2:
|
||||
const result = formatSplitText(answer || ''); // 格式化后的QA对
|
||||
console.log(`split result length: `, result.length);
|
||||
// 计费
|
||||
result.length > 0 &&
|
||||
if (result.length > 0) {
|
||||
pushQABill({
|
||||
userId: data.userId,
|
||||
totalTokens,
|
||||
appName: 'QA 拆分'
|
||||
});
|
||||
} else {
|
||||
addLog.info(`QA result 0:`, { answer });
|
||||
}
|
||||
|
||||
return {
|
||||
rawContent: answer,
|
||||
result
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user