mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-22 12:20:34 +00:00

* perf: local file create collection * rename middleware * perf: remove code * feat: next14 * feat: external file dataset * collection tags field * external file dataset doc * fix: ts
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { TrainingModeEnum, DatasetCollectionTypeEnum } from './constants';
|
|
import { getFileIcon } from '../../common/file/icon';
|
|
import { strIsLink } from '../../common/string/tools';
|
|
|
|
export function getCollectionIcon(
|
|
type: DatasetCollectionTypeEnum = DatasetCollectionTypeEnum.file,
|
|
name = ''
|
|
) {
|
|
if (type === DatasetCollectionTypeEnum.folder) {
|
|
return 'common/folderFill';
|
|
}
|
|
if (type === DatasetCollectionTypeEnum.link) {
|
|
return 'common/linkBlue';
|
|
}
|
|
if (type === DatasetCollectionTypeEnum.virtual) {
|
|
return 'file/fill/manual';
|
|
}
|
|
return getFileIcon(name);
|
|
}
|
|
export function getSourceNameIcon({
|
|
sourceName,
|
|
sourceId
|
|
}: {
|
|
sourceName: string;
|
|
sourceId?: string;
|
|
}) {
|
|
const fileIcon = getFileIcon(decodeURIComponent(sourceName), '');
|
|
if (fileIcon) {
|
|
return fileIcon;
|
|
}
|
|
if (strIsLink(sourceId)) {
|
|
return 'common/linkBlue';
|
|
}
|
|
|
|
return 'file/fill/manual';
|
|
}
|
|
|
|
/* get dataset data default index */
|
|
export function getDefaultIndex(props?: { q?: string; a?: string; dataId?: string }) {
|
|
const { q = '', a, dataId } = props || {};
|
|
const qaStr = `${q}\n${a}`.trim();
|
|
return {
|
|
defaultIndex: true,
|
|
text: a ? qaStr : q,
|
|
dataId
|
|
};
|
|
}
|
|
|
|
export const predictDataLimitLength = (mode: TrainingModeEnum, data: any[]) => {
|
|
if (mode === TrainingModeEnum.qa) return data.length * 20;
|
|
if (mode === TrainingModeEnum.auto) return data.length * 5;
|
|
return data.length;
|
|
};
|