mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-22 20:04:01 +00:00
fix: csv select
This commit is contained in:
@@ -48,27 +48,29 @@ const CsvImport = ({ kbId }: { kbId: string }) => {
|
|||||||
setSelecting(true);
|
setSelecting(true);
|
||||||
try {
|
try {
|
||||||
let promise = Promise.resolve();
|
let promise = Promise.resolve();
|
||||||
files.forEach((file) => {
|
files
|
||||||
promise = promise.then(async () => {
|
.filter((file) => /csv$/.test(file.name))
|
||||||
const { header, data } = await readCsvContent(file);
|
.forEach((file) => {
|
||||||
if (header[0] !== 'question' || header[1] !== 'answer') {
|
promise = promise.then(async () => {
|
||||||
throw new Error('csv 文件格式有误,请确保 question 和 answer 两列');
|
const { header, data } = await readCsvContent(file);
|
||||||
}
|
if (header[0] !== 'question' || header[1] !== 'answer') {
|
||||||
|
throw new Error('csv 文件格式有误,请确保 question 和 answer 两列');
|
||||||
|
}
|
||||||
|
|
||||||
setFiles((state) => [
|
setFiles((state) => [
|
||||||
{
|
{
|
||||||
id: nanoid(),
|
id: nanoid(),
|
||||||
filename: file.name,
|
filename: file.name,
|
||||||
chunks: data.map((item) => ({
|
chunks: data.map((item) => ({
|
||||||
q: item[0],
|
q: item[0],
|
||||||
a: item[1],
|
a: item[1],
|
||||||
source: item[2]
|
source: item[2]
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
...state
|
...state
|
||||||
]);
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
await promise;
|
await promise;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
Reference in New Issue
Block a user