fix: api acccess info model name
This commit is contained in:
@@ -6,6 +6,13 @@ import { categoryToPathMap } from '../../llmodels/config/button-actions';
|
|||||||
const useOpenPlayground = () => {
|
const useOpenPlayground = () => {
|
||||||
const navigate = useNavigate();
|
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) => {
|
const handleOpenPlayGround = (row: any) => {
|
||||||
// Match the id format the OpenAI ``/v1/models`` endpoint reports: an
|
// Match the id format the OpenAI ``/v1/models`` endpoint reports: an
|
||||||
// org's models are namespaced as ``{org}/{name}``, while the platform
|
// 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
|
// ``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
|
// caller is currently acting under for the admin "All" view, where the
|
||||||
// row's owner still resolves via the platform-wide org cache.
|
// row's owner still resolves via the platform-wide org cache.
|
||||||
const org = getOrgById(row.owner_principal_id) ?? getCurrentOrg();
|
const rawModel = generateModelName(row);
|
||||||
const rawModel =
|
|
||||||
org?.name && !org.is_platform ? `${org.name}/${row.name}` : row.name;
|
|
||||||
const modelName = encodeURIComponent(rawModel);
|
const modelName = encodeURIComponent(rawModel);
|
||||||
|
|
||||||
for (const [category, path] of Object.entries(categoryToPathMap)) {
|
for (const [category, path] of Object.entries(categoryToPathMap)) {
|
||||||
@@ -37,7 +42,8 @@ const useOpenPlayground = () => {
|
|||||||
navigate(`/playground/chat?model=${modelName}`);
|
navigate(`/playground/chat?model=${modelName}`);
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
handleOpenPlayGround
|
handleOpenPlayGround,
|
||||||
|
generateModelName
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,10 @@ import {
|
|||||||
type TableColumnProps
|
type TableColumnProps
|
||||||
} from '@gpustack/core-ui';
|
} from '@gpustack/core-ui';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
|
import { useMemoizedFn } from 'ahooks';
|
||||||
import { MenuProps } from 'antd';
|
import { MenuProps } from 'antd';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { useCallback, useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { RouteItem } from '../config/types';
|
import { RouteItem } from '../config/types';
|
||||||
import type { ModelRouteConfigAction } from '../plugin';
|
import type { ModelRouteConfigAction } from '../plugin';
|
||||||
|
|
||||||
@@ -128,10 +129,8 @@ const useAccessColumns = ({
|
|||||||
});
|
});
|
||||||
}, [configActions, onConfigAction]);
|
}, [configActions, onConfigAction]);
|
||||||
|
|
||||||
const filterActions = useCallback(
|
const filterActions = useMemoizedFn((record: RouteItem) =>
|
||||||
(record: RouteItem) =>
|
sortedActions.filter((a) => (a.show ? a.show(record) : true))
|
||||||
sortedActions.filter((a) => (a.show ? a.show(record) : true)),
|
|
||||||
[sortedActions]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Plugin entries carry their own `onClick` (wired to `onConfigAction`
|
// 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`
|
// when present. Built-ins fall through to the page's `handleSelect`
|
||||||
// dispatcher keyed by `val`. Mirrors the api-keys page's onSelect
|
// dispatcher keyed by `val`. Mirrors the api-keys page's onSelect
|
||||||
// path — no key lookup needed.
|
// path — no key lookup needed.
|
||||||
const onSelectAction = useCallback(
|
const onSelectAction = useMemoizedFn(
|
||||||
(val: string, record: RouteItem, item?: RankedAction) => {
|
(val: string, record: RouteItem, item?: RankedAction) => {
|
||||||
if (item?.onClick) {
|
if (item?.onClick) {
|
||||||
item.onClick(record);
|
item.onClick(record);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handleSelect(val, record);
|
handleSelect(val, record);
|
||||||
},
|
}
|
||||||
[handleSelect]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ const ModelRoutes: React.FC = () => {
|
|||||||
openAccessControlModalStatus
|
openAccessControlModalStatus
|
||||||
} = useAccessControl();
|
} = useAccessControl();
|
||||||
const { sourceModels, fetchSourceModels } = useTargetSourceModels();
|
const { sourceModels, fetchSourceModels } = useTargetSourceModels();
|
||||||
const { handleOpenPlayGround } = useOpenPlayground();
|
const { handleOpenPlayGround, generateModelName } = useOpenPlayground();
|
||||||
const { apiAccessInfo, openViewAPIInfo, closeViewAPIInfo } = useViewApIInfo();
|
const { apiAccessInfo, openViewAPIInfo, closeViewAPIInfo } = useViewApIInfo();
|
||||||
const [registerRouteConfig, setRegisterRouteConfig] = useAtom(
|
const [registerRouteConfig, setRegisterRouteConfig] = useAtom(
|
||||||
registerRouteConfigAtom
|
registerRouteConfigAtom
|
||||||
@@ -214,7 +214,10 @@ const ModelRoutes: React.FC = () => {
|
|||||||
} else if (val === 'chat') {
|
} else if (val === 'chat') {
|
||||||
handleOpenPlayGround(row);
|
handleOpenPlayGround(row);
|
||||||
} else if (val === 'api') {
|
} else if (val === 'api') {
|
||||||
openViewAPIInfo(row);
|
openViewAPIInfo({
|
||||||
|
...row,
|
||||||
|
name: generateModelName(row)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -308,18 +311,8 @@ const ModelRoutes: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [registerRouteConfig, dataSource.loadend]);
|
}, [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 configActions = useMemo(() => getModelRouteConfigActions(), []);
|
||||||
|
|
||||||
const controllersRef = useRef<
|
const controllersRef = useRef<
|
||||||
Record<string, ModelRouteConfigActionController>
|
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(() => {
|
const handleConfigActionOk = useMemoizedFn(() => {
|
||||||
fetchData();
|
fetchData();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user