### What problem does this PR solve? fix: Set the default value of Self RAG to false #1220 fix: Change all tool file names to kebab format ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
74
web/src/utils/common-util.ts
Normal file
74
web/src/utils/common-util.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { IFactory } from '@/interfaces/database/llm';
|
||||
import isObject from 'lodash/isObject';
|
||||
import snakeCase from 'lodash/snakeCase';
|
||||
|
||||
export const isFormData = (data: unknown): data is FormData => {
|
||||
return data instanceof FormData;
|
||||
};
|
||||
|
||||
const excludedFields = ['img2txt_id'];
|
||||
|
||||
const isExcludedField = (key: string) => {
|
||||
return excludedFields.includes(key);
|
||||
};
|
||||
|
||||
export const convertTheKeysOfTheObjectToSnake = (data: unknown) => {
|
||||
if (isObject(data) && !isFormData(data)) {
|
||||
return Object.keys(data).reduce<Record<string, any>>((pre, cur) => {
|
||||
const value = (data as Record<string, any>)[cur];
|
||||
pre[isFormData(value) || isExcludedField(cur) ? cur : snakeCase(cur)] =
|
||||
value;
|
||||
return pre;
|
||||
}, {});
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getSearchValue = (key: string) => {
|
||||
const params = new URL(document.location as any).searchParams;
|
||||
return params.get(key);
|
||||
};
|
||||
|
||||
// Formatize numbers, add thousands of separators
|
||||
export const formatNumberWithThousandsSeparator = (numberStr: string) => {
|
||||
const formattedNumber = numberStr.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
return formattedNumber;
|
||||
};
|
||||
|
||||
const orderFactoryList = [
|
||||
'OpenAI',
|
||||
'Moonshot',
|
||||
'ZHIPU-AI',
|
||||
'Ollama',
|
||||
'Xinference',
|
||||
];
|
||||
|
||||
export const sortLLmFactoryListBySpecifiedOrder = (list: IFactory[]) => {
|
||||
const finalList: IFactory[] = [];
|
||||
orderFactoryList.forEach((orderItem) => {
|
||||
const index = list.findIndex((item) => item.name === orderItem);
|
||||
if (index !== -1) {
|
||||
finalList.push(list[index]);
|
||||
}
|
||||
});
|
||||
|
||||
list.forEach((item) => {
|
||||
if (finalList.every((x) => x.name !== item.name)) {
|
||||
finalList.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
return finalList;
|
||||
};
|
||||
|
||||
export const filterOptionsByInput = (
|
||||
input: string,
|
||||
option: { label: string; value: string } | undefined,
|
||||
) => (option?.label ?? '').toLowerCase().includes(input.toLowerCase());
|
||||
|
||||
export const toFixed = (value: unknown, fixed = 2) => {
|
||||
if (typeof value === 'number') {
|
||||
return value.toFixed(fixed);
|
||||
}
|
||||
return value;
|
||||
};
|
||||
Reference in New Issue
Block a user