diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx index bd798063..90a5d2f6 100644 --- a/src/layouts/index.tsx +++ b/src/layouts/index.tsx @@ -235,8 +235,6 @@ export default (props: any) => { onPageChange={(route) => { const { location } = history; - console.log('onPageChange', userInfo, initialState); - // if user is not change password, redirect to change password page if ( location.pathname !== loginPath && diff --git a/src/locales/en-US.ts b/src/locales/en-US.ts index eb69fe7d..d81ebb08 100644 --- a/src/locales/en-US.ts +++ b/src/locales/en-US.ts @@ -1,23 +1,18 @@ -import apikeys from './en-US/apikeys'; -import common from './en-US/common'; -import dashboard from './en-US/dashboard'; -import menu from './en-US/menu'; -import models from './en-US/models'; -import playground from './en-US/playground'; -import resources from './en-US/resources'; -import shortcuts from './en-US/shortcuts'; -import usage from './en-US/usage'; -import users from './en-US/users'; +/** + * @description The directory name used in require.context must match the language configuration names defined in lang-config-map.ts. + * @example Directories like 'en-US' or 'zh-CN' should correspond exactly to the configuration names in lang-config-map.ts. + */ -export default { - ...common, - ...menu, - ...models, - ...playground, - ...resources, - ...apikeys, - ...users, - ...dashboard, - ...usage, - ...shortcuts -}; +const requireContext = require.context(`./en-US`, false, /\.ts$/); + +let languageConfig: Record = {}; + +requireContext.keys().forEach((fileName: any) => { + const moduleConfig = requireContext(fileName).default; + languageConfig = { + ...languageConfig, + ...moduleConfig + }; +}); + +export default languageConfig; diff --git a/src/locales/lang-config-map.tsx b/src/locales/lang-config-map.tsx index 2512146e..25d496b7 100644 --- a/src/locales/lang-config-map.tsx +++ b/src/locales/lang-config-map.tsx @@ -1,5 +1,11 @@ import IconFont from '@/components/icon-font'; +/** + * Language configuration map + * Warning: The key of the map must be the same as the directory name in the locales directory + * Do not modify the key of the map + * + */ const langConfigMap = { 'ar-EG': { lang: 'ar-EG', diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index f07040f5..7c42cbd6 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -1,31 +1,18 @@ -import apikeys from './zh-CN/apikeys'; -import common from './zh-CN/common'; -import dashboard from './zh-CN/dashboard'; -import menu from './zh-CN/menu'; -import models from './zh-CN/models'; -import playground from './zh-CN/playground'; -import resources from './zh-CN/resources'; -import shortcuts from './zh-CN/shortcuts'; -import usage from './zh-CN/usage'; -import users from './zh-CN/users'; +/** + * @description The directory name used in require.context must match the language configuration names defined in lang-config-map.ts. + * @example Directories like 'en-US' or 'zh-CN' should correspond exactly to the configuration names in lang-config-map.ts. + */ -// import { LangConfigType } from './lang-config-map'; +const requireContext = require.context(`./zh-CN`, false, /\.ts$/); -// const DIR: LangConfigType = 'zh-CN'; +let languageConfig: Record = {}; -// const langConfig = require.context(`./`, true, /\.ts$/); +requireContext.keys().forEach((fileName: any) => { + const moduleConfig = requireContext(fileName).default; + languageConfig = { + ...languageConfig, + ...moduleConfig + }; +}); -// console.log('langConfig====', langConfig); - -export default { - ...common, - ...menu, - ...models, - ...playground, - ...resources, - ...apikeys, - ...users, - ...dashboard, - ...usage, - ...shortcuts -}; +export default languageConfig; diff --git a/src/pages/llmodels/components/advance-config.tsx b/src/pages/llmodels/components/advance-config.tsx index 3f23623c..706205da 100644 --- a/src/pages/llmodels/components/advance-config.tsx +++ b/src/pages/llmodels/components/advance-config.tsx @@ -37,7 +37,6 @@ const AdvanceConfig: React.FC = (props) => { const wokerSelector = Form.useWatch('worker_selector', form); const scheduleType = Form.useWatch('scheduleType', form); const backend = Form.useWatch('backend', form); - const [params, setParams] = React.useState([]); const placementStrategyTips = [ { @@ -313,6 +312,7 @@ const AdvanceConfig: React.FC = (props) => { {intl.formatMessage({ id: 'resources.form.advanced' })} ), + forceRender: true, children } ]; @@ -331,6 +331,7 @@ const AdvanceConfig: React.FC = (props) => { expandIconPosition="start" bordered={false} ghost + destroyInactivePanel={false} className={dataformStyles['advanced-collapse']} expandIcon={({ isActive }) => ( = (props) => { }; }, [open]); + useEffect(() => { + if (source === modelSourceMap.ollama_library_value) { + setIsGGUF(true); + } + }, [source]); + return ( = ({ )} {item?.distributed_servers?.rpc_servers?.length && ( = (props) => { const [form] = Form.useForm(); const intl = useIntl(); const [gpuOptions, setGpuOptions] = useState([]); + const [isGGUF, setIsGGUF] = useState(false); const [loading, setLoading] = useState(false); - const modelSource = Form.useWatch('source', form); - const [fileOptions, setFileOptions] = useState< - { label: string; value: string }[] - >([]); const getGPUList = async () => { const data = await queryGPUList(); @@ -88,6 +84,7 @@ const UpdateModal: React.FC = (props) => { props.data?.source || '', props.data ); + form.setFieldsValue({ ...result.values, ..._.omit(props.data, result.omits), @@ -103,43 +100,9 @@ const UpdateModal: React.FC = (props) => { initFormValue(); }, [open]); - const fileNamLabel = (item: any) => { - return ( - - {item.path} - - ({convertFileSize(item.size)}) - - - ); - }; - const handleFetchModelFiles = async (repo: string) => { - try { - setLoading(true); - const res = await queryHuggingfaceModelFiles({ repo }); - const list = _.filter(res, (file: any) => { - return _.endsWith(file.path, '.gguf'); - }).map((item: any) => { - return { - label: fileNamLabel(item), - value: item.path, - size: item.size - }; - }); - setFileOptions(list); - setLoading(false); - } catch (error) { - setFileOptions([]); - setLoading(false); - } - }; - - const handleRepoOnBlur = (e: any) => { - const repo = form.getFieldValue('repo_id'); - handleFetchModelFiles(repo); - }; + useEffect(() => { + setIsGGUF(props.data?.backend === backendOptionsMap.llamaBox); + }, [props.data?.backend]); const renderHuggingfaceFields = () => { return ( @@ -164,7 +127,7 @@ const UpdateModal: React.FC = (props) => { disabled={true} > - {form.getFieldValue('file_name') && ( + {isGGUF && ( name="file_name" rules={[ @@ -183,7 +146,7 @@ const UpdateModal: React.FC = (props) => { filterOption label={intl.formatMessage({ id: 'models.form.filename' })} required - options={fileOptions} + options={[]} loading={loading} disabled={action === PageAction.EDIT} > @@ -263,7 +226,7 @@ const UpdateModal: React.FC = (props) => { } return null; - }, [props.data?.source]); + }, [props.data?.source, isGGUF]); const handleSumit = () => { form.submit(); diff --git a/src/pages/llmodels/config/types.ts b/src/pages/llmodels/config/types.ts index a948c88c..6c48b5a4 100644 --- a/src/pages/llmodels/config/types.ts +++ b/src/pages/llmodels/config/types.ts @@ -1,5 +1,6 @@ export interface ListItem { source: string; + backend: string; huggingface_repo_id: string; huggingface_file_name: string; huggingface_filename: string; diff --git a/src/pages/playground/components/ground-left.tsx b/src/pages/playground/components/ground-left.tsx index 8cd2f296..32fbba7d 100644 --- a/src/pages/playground/components/ground-left.tsx +++ b/src/pages/playground/components/ground-left.tsx @@ -314,7 +314,11 @@ const GroundLeft: React.FC = forwardRef((props, ref) => { })} >
- +
diff --git a/src/pages/playground/components/multiple-chat/model-item.tsx b/src/pages/playground/components/multiple-chat/model-item.tsx index 36b9ac2a..932b5334 100644 --- a/src/pages/playground/components/multiple-chat/model-item.tsx +++ b/src/pages/playground/components/multiple-chat/model-item.tsx @@ -68,7 +68,6 @@ const ModelItem: React.FC = forwardRef( messageId.current = messageId.current + 1; }; const maxHeight = useMemo(() => { - console.log('spans==========', spans); const total = 72 + 110 + 46 + 16 + 32; if (spans.count < 4) { return `calc(100vh - ${total}px)`; @@ -367,11 +366,14 @@ const ModelItem: React.FC = forwardRef( > } diff --git a/src/pages/playground/components/params-settings.tsx b/src/pages/playground/components/params-settings.tsx index 04ab1f97..a830d547 100644 --- a/src/pages/playground/components/params-settings.tsx +++ b/src/pages/playground/components/params-settings.tsx @@ -7,7 +7,6 @@ import { useIntl } from '@umijs/max'; import { Form, InputNumber, Slider, Tooltip } from 'antd'; import _ from 'lodash'; import { useEffect, useId, useState } from 'react'; -import { queryModelsList } from '../apis'; import CustomLabelStyles from '../style/custom-label.less'; type ParamsSettingsFormProps = { @@ -24,6 +23,7 @@ type ParamsSettingsProps = { showModelSelector?: boolean; params?: ParamsSettingsFormProps; model?: string; + modelList: Global.BaseOption[]; onValuesChange?: (changeValues: any, value: Record) => void; setParams: (params: any) => void; globalParams?: ParamsSettingsFormProps; @@ -35,6 +35,7 @@ const ParamsSettings: React.FC = ({ globalParams, onValuesChange, model, + modelList, showModelSelector = true }) => { const intl = useIntl(); @@ -51,41 +52,26 @@ const ParamsSettings: React.FC = ({ const formId = useId(); useEffect(() => { - const getModelList = async () => { - try { - const params = { - embedding_only: false - }; - const res = await queryModelsList(params); - const list = _.map(res.data || [], (item: any) => { - return { - value: item.id, - label: item.id - }; - }); - setModelList(list); - form.setFieldsValue({ - model: selectedModel || _.get(list, '[0].value'), - ...initialValues - }); - setParams({ - model: selectedModel || _.get(list, '[0].value'), - ...initialValues - }); - } catch (error) { - setModelList([]); - form.setFieldsValue({ - model: selectedModel || '', - ...initialValues - }); - setParams({ - model: selectedModel || '', - ...initialValues - }); - } - }; - getModelList(); - }, []); + if (showModelSelector) { + form.setFieldsValue({ + model: selectedModel || _.get(modelList, '[0].value'), + ...initialValues + }); + setParams({ + model: selectedModel || _.get(modelList, '[0].value'), + ...initialValues + }); + } else { + form.setFieldsValue({ + model: selectedModel || '', + ...initialValues + }); + setParams({ + model: selectedModel || '', + ...initialValues + }); + } + }, [modelList, showModelSelector, selectedModel]); const handleOnFinish = (values: any) => { console.log('handleOnFinish', values); @@ -126,8 +112,8 @@ const ParamsSettings: React.FC = ({ useEffect(() => { form.setFieldsValue(globalParams); - console.log('globalParams=========11111', model, globalParams); }, [globalParams]); + const renderLabel = (args: { field: string; label: string; @@ -193,7 +179,7 @@ const ParamsSettings: React.FC = ({ > diff --git a/src/pages/playground/index.tsx b/src/pages/playground/index.tsx index fe59c941..0eaf706d 100644 --- a/src/pages/playground/index.tsx +++ b/src/pages/playground/index.tsx @@ -142,26 +142,6 @@ const Playground: React.FC = () => {
- {/* {activeKey === 'chat' && ( -
-
-
- -
-
-
- )} */} ); diff --git a/src/utils/index.ts b/src/utils/index.ts index 20528daf..3e1d97da 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -167,3 +167,19 @@ export const formatNumber = (num: number) => { return num.toString(); } }; + +export function loadLanguageConfig(language: string) { + const requireContext = require.context(`./${language}`, false, /\.ts$/); + + const languageConfig: Record = {}; + + requireContext.keys().forEach((fileName: any) => { + const moduleConfig = requireContext(fileName).default; + + const moduleName = fileName.replace(/(\.\/|\.ts)/g, ''); + + languageConfig[moduleName] = moduleConfig; + }); + + return languageConfig; +}