Files
ragflow/web/src/utils/form.ts
chanx 2b4bca4447 Fix(i18n): Added new translations #3221 (#9727)
### What problem does this PR solve?

Fix(i18n): Added new translations #3221

- Added and updated internationalization translations in multiple
components


### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

---------

Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
2025-08-26 17:57:53 +08:00

63 lines
1.7 KiB
TypeScript

import { variableEnabledFieldMap } from '@/constants/chat';
import { TFunction } from 'i18next';
import omit from 'lodash/omit';
// chat model setting and generate operator
export const excludeUnEnabledVariables = (
values: any = {},
prefix = 'llm_setting.',
) => {
const unEnabledFields: Array<keyof typeof variableEnabledFieldMap> =
Object.keys(variableEnabledFieldMap).filter((key) => !values[key]) as Array<
keyof typeof variableEnabledFieldMap
>;
return unEnabledFields.map(
(key) => `${prefix}${variableEnabledFieldMap[key]}`,
);
};
// chat model setting and generate operator
export const removeUselessFieldsFromValues = (values: any, prefix?: string) => {
const nextValues: any = omit(values, [
...Object.keys(variableEnabledFieldMap),
'parameter',
...excludeUnEnabledVariables(values, prefix),
]);
return nextValues;
};
export function buildOptions(
data: Record<string, any>,
t?: TFunction<['translation', ...string[]], undefined>,
prefix?: string,
) {
if (t) {
return Object.values(data).map((val) => ({
label: t(`${prefix ? prefix + '.' : ''}${val.toLowerCase()}`),
value: val,
}));
}
return Object.values(data).map((val) => ({ label: val, value: val }));
}
export function setLLMSettingEnabledValues(
initialLlmSetting?: Record<string, any>,
) {
const values = Object.keys(variableEnabledFieldMap).reduce<
Record<string, boolean>
>((pre, field) => {
pre[field] =
initialLlmSetting === undefined
? false
: !!initialLlmSetting[
variableEnabledFieldMap[
field as keyof typeof variableEnabledFieldMap
]
];
return pre;
}, {});
return values;
}