fix: api acccess info model name

This commit is contained in:
jialin
2026-06-03 15:50:06 +08:00
committed by jialin
parent 9705818b15
commit ac45a72e0e
3 changed files with 22 additions and 28 deletions
@@ -6,6 +6,13 @@ import { categoryToPathMap } from '../../llmodels/config/button-actions';
const useOpenPlayground = () => {
const navigate = useNavigate();
const generateModelName = (row: any) => {
const org = getOrgById(row.owner_principal_id) ?? getCurrentOrg();
const rawModel =
org?.name && !org.is_platform ? `${org.name}/${row.name}` : row.name;
return rawModel;
};
const handleOpenPlayGround = (row: any) => {
// Match the id format the OpenAI ``/v1/models`` endpoint reports: an
// org's models are namespaced as ``{org}/{name}``, while the platform
@@ -13,9 +20,7 @@ const useOpenPlayground = () => {
// ``owner_principal_id`` (an org principal id); fall back to the Org the
// caller is currently acting under for the admin "All" view, where the
// row's owner still resolves via the platform-wide org cache.
const org = getOrgById(row.owner_principal_id) ?? getCurrentOrg();
const rawModel =
org?.name && !org.is_platform ? `${org.name}/${row.name}` : row.name;
const rawModel = generateModelName(row);
const modelName = encodeURIComponent(rawModel);
for (const [category, path] of Object.entries(categoryToPathMap)) {
@@ -37,7 +42,8 @@ const useOpenPlayground = () => {
navigate(`/playground/chat?model=${modelName}`);
};
return {
handleOpenPlayGround
handleOpenPlayGround,
generateModelName
};
};
@@ -9,9 +9,10 @@ import {
type TableColumnProps
} from '@gpustack/core-ui';
import { useIntl } from '@umijs/max';
import { useMemoizedFn } from 'ahooks';
import { MenuProps } from 'antd';
import dayjs from 'dayjs';
import { useCallback, useMemo } from 'react';
import { useMemo } from 'react';
import { RouteItem } from '../config/types';
import type { ModelRouteConfigAction } from '../plugin';
@@ -128,10 +129,8 @@ const useAccessColumns = ({
});
}, [configActions, onConfigAction]);
const filterActions = useCallback(
(record: RouteItem) =>
sortedActions.filter((a) => (a.show ? a.show(record) : true)),
[sortedActions]
const filterActions = useMemoizedFn((record: RouteItem) =>
sortedActions.filter((a) => (a.show ? a.show(record) : true))
);
// Plugin entries carry their own `onClick` (wired to `onConfigAction`
@@ -139,15 +138,14 @@ const useAccessColumns = ({
// when present. Built-ins fall through to the page's `handleSelect`
// dispatcher keyed by `val`. Mirrors the api-keys page's onSelect
// path — no key lookup needed.
const onSelectAction = useCallback(
const onSelectAction = useMemoizedFn(
(val: string, record: RouteItem, item?: RankedAction) => {
if (item?.onClick) {
item.onClick(record);
return;
}
handleSelect(val, record);
},
[handleSelect]
}
);
return useMemo(() => {
+6 -16
View File
@@ -121,7 +121,7 @@ const ModelRoutes: React.FC = () => {
openAccessControlModalStatus
} = useAccessControl();
const { sourceModels, fetchSourceModels } = useTargetSourceModels();
const { handleOpenPlayGround } = useOpenPlayground();
const { handleOpenPlayGround, generateModelName } = useOpenPlayground();
const { apiAccessInfo, openViewAPIInfo, closeViewAPIInfo } = useViewApIInfo();
const [registerRouteConfig, setRegisterRouteConfig] = useAtom(
registerRouteConfigAtom
@@ -214,7 +214,10 @@ const ModelRoutes: React.FC = () => {
} else if (val === 'chat') {
handleOpenPlayGround(row);
} else if (val === 'api') {
openViewAPIInfo(row);
openViewAPIInfo({
...row,
name: generateModelName(row)
});
}
});
@@ -308,18 +311,8 @@ const ModelRoutes: React.FC = () => {
}
}, [registerRouteConfig, dataSource.loadend]);
// Generic per-row plugin slot. Each enterprise plugin contributes a
// `{ key, labelId, icon, priority, form, useCreate }` entry; the host
// renders a button per entry in the dropdown and renders one
// `ModelRouteConfigActionMount` per entry — those mounts own each
// entry's controller and register it back into `controllersRef` so
// dropdown clicks can route to the correct `openModal`. See
// `./plugin.tsx`.
//
// The action list is read once. Plugins are registered at boot and
// never recompute, so the reference is stable for the lifetime of
// the page and `useMemo([])` is safe.
const configActions = useMemo(() => getModelRouteConfigActions(), []);
const controllersRef = useRef<
Record<string, ModelRouteConfigActionController>
>({});
@@ -336,9 +329,6 @@ const ModelRoutes: React.FC = () => {
}
);
// Per-row save closes the drawer and refetches the table. The wrapped
// `fetchAPI` above takes care of bumping `pluginContext.refreshToken`
// for derived plugin data.
const handleConfigActionOk = useMemoizedFn(() => {
fetchData();
});