From 46969702a8b7dc7ecaf3cf76614c3bcc66bf9397 Mon Sep 17 00:00:00 2001 From: jialin Date: Tue, 3 Feb 2026 13:40:52 +0800 Subject: [PATCH] fix: open model in playground --- src/pages/llmodels/components/table-list.tsx | 25 --------------- src/pages/llmodels/config/button-actions.ts | 15 --------- src/pages/model-routes/config/index.ts | 5 +++ .../model-routes/hooks/use-open-playground.ts | 32 +++++++++++++++++++ .../model-routes/hooks/use-routes-columns.tsx | 11 ++++++- src/pages/model-routes/index.tsx | 4 +++ 6 files changed, 51 insertions(+), 41 deletions(-) create mode 100644 src/pages/model-routes/hooks/use-open-playground.ts diff --git a/src/pages/llmodels/components/table-list.tsx b/src/pages/llmodels/components/table-list.tsx index cc687326..c73a3dbc 100644 --- a/src/pages/llmodels/components/table-list.tsx +++ b/src/pages/llmodels/components/table-list.tsx @@ -41,12 +41,10 @@ import { import { InstanceRealtimeLogStatus, modelCategories, - modelCategoriesMap, modelSourceMap } from '../config'; import { ButtonList, - categoryToPathMap, modalConfig, sourceOptions } from '../config/button-actions'; @@ -351,26 +349,6 @@ const Models: React.FC = ({ }); }; - const handleOpenPlayGround = (row: any) => { - for (const [category, path] of Object.entries(categoryToPathMap)) { - if ( - row.categories?.includes(category) && - [ - modelCategoriesMap.text_to_speech, - modelCategoriesMap.speech_to_text - ].includes(category) - ) { - navigate(`${path}&model=${row.name}`); - return; - } - if (row.categories?.includes(category)) { - navigate(`${path}?model=${row.name}`); - return; - } - } - navigate(`/playground/chat?model=${row.name}`); - }; - const handleViewLogs = async (row: any) => { try { setCurrentInstance({ @@ -445,9 +423,6 @@ const Models: React.FC = ({ if (val === 'edit') { handleEdit(row); } - if (val === 'chat') { - handleOpenPlayGround(row); - } if (val === 'delete') { handleDelete(row); } diff --git a/src/pages/llmodels/config/button-actions.ts b/src/pages/llmodels/config/button-actions.ts index 8328d7e7..a4567541 100644 --- a/src/pages/llmodels/config/button-actions.ts +++ b/src/pages/llmodels/config/button-actions.ts @@ -39,16 +39,6 @@ export const ActionList: ActionItem[] = [ key: 'edit', icon: icons.EditOutlined }, - // { - // label: 'common.button.detail', - // key: 'details', - // icon: icons.FileTextOutlined - // }, - { - label: 'models.openinplayground', - key: 'chat', - icon: icons.ExperimentOutlined - }, { label: 'common.button.start', key: 'start', @@ -59,11 +49,6 @@ export const ActionList: ActionItem[] = [ key: 'api', icon: icons.ApiOutlined }, - // { - // label: 'models.button.accessSettings', - // key: 'accessControl', - // icon: icons.Permission - // }, { label: 'common.button.stop', key: 'stop', diff --git a/src/pages/model-routes/config/index.ts b/src/pages/model-routes/config/index.ts index b1857e69..db6a4a52 100644 --- a/src/pages/model-routes/config/index.ts +++ b/src/pages/model-routes/config/index.ts @@ -24,6 +24,11 @@ export const rowActionList = [ label: 'common.button.edit', icon: icons.EditOutlined }, + { + label: 'models.openinplayground', + key: 'chat', + icon: icons.ExperimentOutlined + }, { label: 'models.button.accessSettings', key: 'accessControl', diff --git a/src/pages/model-routes/hooks/use-open-playground.ts b/src/pages/model-routes/hooks/use-open-playground.ts new file mode 100644 index 00000000..236d1d0b --- /dev/null +++ b/src/pages/model-routes/hooks/use-open-playground.ts @@ -0,0 +1,32 @@ +import { useNavigate } from '@umijs/max'; +import { modelCategoriesMap } from '../../llmodels/config'; +import { categoryToPathMap } from '../../llmodels/config/button-actions'; + +const useOpenPlayground = () => { + const navigate = useNavigate(); + + const handleOpenPlayGround = (row: any) => { + for (const [category, path] of Object.entries(categoryToPathMap)) { + if ( + row.categories?.includes(category) && + [ + modelCategoriesMap.text_to_speech, + modelCategoriesMap.speech_to_text + ].includes(category) + ) { + navigate(`${path}&model=${row.name}`); + return; + } + if (row.categories?.includes(category)) { + navigate(`${path}?model=${row.name}`); + return; + } + } + navigate(`/playground/chat?model=${row.name}`); + }; + return { + handleOpenPlayGround + }; +}; + +export default useOpenPlayground; diff --git a/src/pages/model-routes/hooks/use-routes-columns.tsx b/src/pages/model-routes/hooks/use-routes-columns.tsx index 403c73ea..2e177f68 100644 --- a/src/pages/model-routes/hooks/use-routes-columns.tsx +++ b/src/pages/model-routes/hooks/use-routes-columns.tsx @@ -16,6 +16,15 @@ const useAccessColumns = ( ): SealColumnProps[] => { const intl = useIntl(); + const filterActions = (record: RouteItem) => { + return rowActionList.filter((action) => { + if (action.key === 'chat') { + return record.ready_targets > 0; + } + return true; + }); + }; + return useMemo(() => { return [ { @@ -59,7 +68,7 @@ const useAccessColumns = ( span: 4, render: (value: string, record: RouteItem) => ( handleSelect(val, record)} > ) diff --git a/src/pages/model-routes/index.tsx b/src/pages/model-routes/index.tsx index bfe3a051..78e90319 100644 --- a/src/pages/model-routes/index.tsx +++ b/src/pages/model-routes/index.tsx @@ -36,6 +36,7 @@ import RouteTargets from './components/route-targets'; import { FormData, RouteItem as ListItem } from './config/types'; import useAccessControl from './hooks/use-access-control'; import useCreateRoute from './hooks/use-create-route'; +import useOpenPlayground from './hooks/use-open-playground'; import useRoutesColumns from './hooks/use-routes-columns'; import useTargetSourceModels from './hooks/use-target-source-models'; @@ -73,6 +74,7 @@ const ModelRoutes: React.FC = () => { openAccessControlModalStatus } = useAccessControl(); const { sourceModels, fetchSourceModels } = useTargetSourceModels(); + const { handleOpenPlayGround } = useOpenPlayground(); const [modelList, setModelsList] = useState[]>([]); useEffect(() => { @@ -145,6 +147,8 @@ const ModelRoutes: React.FC = () => { intl.formatMessage({ id: 'models.button.accessSettings' }), row ); + } else if (val === 'chat') { + handleOpenPlayGround(row); } });