fix: open model in playground

This commit is contained in:
jialin
2026-02-03 18:21:08 +08:00
parent 134827a0f7
commit 46969702a8
6 changed files with 51 additions and 41 deletions
@@ -41,12 +41,10 @@ import {
import { import {
InstanceRealtimeLogStatus, InstanceRealtimeLogStatus,
modelCategories, modelCategories,
modelCategoriesMap,
modelSourceMap modelSourceMap
} from '../config'; } from '../config';
import { import {
ButtonList, ButtonList,
categoryToPathMap,
modalConfig, modalConfig,
sourceOptions sourceOptions
} from '../config/button-actions'; } from '../config/button-actions';
@@ -351,26 +349,6 @@ const Models: React.FC<ModelsProps> = ({
}); });
}; };
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) => { const handleViewLogs = async (row: any) => {
try { try {
setCurrentInstance({ setCurrentInstance({
@@ -445,9 +423,6 @@ const Models: React.FC<ModelsProps> = ({
if (val === 'edit') { if (val === 'edit') {
handleEdit(row); handleEdit(row);
} }
if (val === 'chat') {
handleOpenPlayGround(row);
}
if (val === 'delete') { if (val === 'delete') {
handleDelete(row); handleDelete(row);
} }
@@ -39,16 +39,6 @@ export const ActionList: ActionItem[] = [
key: 'edit', key: 'edit',
icon: icons.EditOutlined icon: icons.EditOutlined
}, },
// {
// label: 'common.button.detail',
// key: 'details',
// icon: icons.FileTextOutlined
// },
{
label: 'models.openinplayground',
key: 'chat',
icon: icons.ExperimentOutlined
},
{ {
label: 'common.button.start', label: 'common.button.start',
key: 'start', key: 'start',
@@ -59,11 +49,6 @@ export const ActionList: ActionItem[] = [
key: 'api', key: 'api',
icon: icons.ApiOutlined icon: icons.ApiOutlined
}, },
// {
// label: 'models.button.accessSettings',
// key: 'accessControl',
// icon: icons.Permission
// },
{ {
label: 'common.button.stop', label: 'common.button.stop',
key: 'stop', key: 'stop',
+5
View File
@@ -24,6 +24,11 @@ export const rowActionList = [
label: 'common.button.edit', label: 'common.button.edit',
icon: icons.EditOutlined icon: icons.EditOutlined
}, },
{
label: 'models.openinplayground',
key: 'chat',
icon: icons.ExperimentOutlined
},
{ {
label: 'models.button.accessSettings', label: 'models.button.accessSettings',
key: 'accessControl', key: 'accessControl',
@@ -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;
@@ -16,6 +16,15 @@ const useAccessColumns = (
): SealColumnProps[] => { ): SealColumnProps[] => {
const intl = useIntl(); 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 useMemo(() => {
return [ return [
{ {
@@ -59,7 +68,7 @@ const useAccessColumns = (
span: 4, span: 4,
render: (value: string, record: RouteItem) => ( render: (value: string, record: RouteItem) => (
<DropdownButtons <DropdownButtons
items={rowActionList} items={filterActions(record)}
onSelect={(val) => handleSelect(val, record)} onSelect={(val) => handleSelect(val, record)}
></DropdownButtons> ></DropdownButtons>
) )
+4
View File
@@ -36,6 +36,7 @@ import RouteTargets from './components/route-targets';
import { FormData, RouteItem as ListItem } from './config/types'; import { FormData, RouteItem as ListItem } from './config/types';
import useAccessControl from './hooks/use-access-control'; import useAccessControl from './hooks/use-access-control';
import useCreateRoute from './hooks/use-create-route'; import useCreateRoute from './hooks/use-create-route';
import useOpenPlayground from './hooks/use-open-playground';
import useRoutesColumns from './hooks/use-routes-columns'; import useRoutesColumns from './hooks/use-routes-columns';
import useTargetSourceModels from './hooks/use-target-source-models'; import useTargetSourceModels from './hooks/use-target-source-models';
@@ -73,6 +74,7 @@ const ModelRoutes: React.FC = () => {
openAccessControlModalStatus openAccessControlModalStatus
} = useAccessControl(); } = useAccessControl();
const { sourceModels, fetchSourceModels } = useTargetSourceModels(); const { sourceModels, fetchSourceModels } = useTargetSourceModels();
const { handleOpenPlayGround } = useOpenPlayground();
const [modelList, setModelsList] = useState<Global.BaseOption<number>[]>([]); const [modelList, setModelsList] = useState<Global.BaseOption<number>[]>([]);
useEffect(() => { useEffect(() => {
@@ -145,6 +147,8 @@ const ModelRoutes: React.FC = () => {
intl.formatMessage({ id: 'models.button.accessSettings' }), intl.formatMessage({ id: 'models.button.accessSettings' }),
row row
); );
} else if (val === 'chat') {
handleOpenPlayGround(row);
} }
}); });