fix: playground model id alignment across org boundaries
Two QA-reported bugs on the "Open in Playground" path. Both come
down to the model id the playground submits not matching what
``/v1/models`` / the dispatcher key off:
* Routes page (OSS UI) emitted ``default/<name>`` for routes in the
platform Org and 404'd. ``use-open-playground`` keyed off the
``is_platform`` flag alone; stale caches that drop the flag
slipped through. Also accept the well-known ``name === 'default'``
(``PLATFORM_PRINCIPAL_NAME`` on the backend) as a fallback signal.
* My Models page (enterprise UI, non-admin) emitted bare ``<name>``
with no Org prefix for non-platform routes. Use ``model.name``
from ``/v2/my-models`` verbatim — the backend ("fix: principal
prefix in my-models") now rewrites that field to the OpenAI-style
id server-side, which also closes the cross-Org grant gap a
client-side cache lookup can't (the granting Org isn't in the
caller's member list). Card title now shows the prefixed id, so
users can tell apart same-named models from different Orgs.
Routes page keeps ``useOpenPlayground`` — that surface is always
scoped to the caller's own Org, the local cache is sufficient, and
``/model-routes`` still returns the raw ``name``.
Also drops the now-unused ``onClick`` prop on ``ModelItem``: the
card had ``clickable={false}`` so the parent-passed handler was
already dead code; the Button drives the playground navigation.
This commit is contained in:
@@ -119,13 +119,16 @@ const renderTag = (item: any, index = 0) => {
|
||||
|
||||
const ModelItem: React.FC<{
|
||||
model: Record<string, any>;
|
||||
onClick: (model: any) => void;
|
||||
}> = (props) => {
|
||||
const { model, onClick } = props;
|
||||
const { model } = props;
|
||||
const intl = useIntl();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleOpenPlayGround = () => {
|
||||
// ``model.name`` from ``/v2/my-models`` is the OpenAI-style id
|
||||
// (org-prefixed for non-platform routes, bare for platform). Use it
|
||||
// verbatim — the playground / dispatcher both key off that exact id.
|
||||
const handleOpenPlayGroundClick = () => {
|
||||
const modelName = encodeURIComponent(model.name);
|
||||
for (const [category, path] of Object.entries(categoryToPathMap)) {
|
||||
if (
|
||||
model.categories?.includes(category) &&
|
||||
@@ -134,15 +137,15 @@ const ModelItem: React.FC<{
|
||||
modelCategoriesMap.speech_to_text
|
||||
].includes(category)
|
||||
) {
|
||||
navigate(`${path}&model=${model.name}`);
|
||||
navigate(`${path}&model=${modelName}`);
|
||||
return;
|
||||
}
|
||||
if (model.categories?.includes(category)) {
|
||||
navigate(`${path}?model=${model.name}`);
|
||||
navigate(`${path}?model=${modelName}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
navigate(`/playground/chat?model=${model.name}`);
|
||||
navigate(`/playground/chat?model=${modelName}`);
|
||||
};
|
||||
|
||||
// context length
|
||||
@@ -167,7 +170,6 @@ const ModelItem: React.FC<{
|
||||
<CardWrapper>
|
||||
<TemplateCard
|
||||
height={140}
|
||||
onClick={() => onClick(model)}
|
||||
clickable={false}
|
||||
hoverable={true}
|
||||
ghost
|
||||
@@ -237,7 +239,7 @@ const ModelItem: React.FC<{
|
||||
size="middle"
|
||||
className="btn"
|
||||
type="primary"
|
||||
onClick={handleOpenPlayGround}
|
||||
onClick={handleOpenPlayGroundClick}
|
||||
>
|
||||
{intl.formatMessage({ id: 'models.openinplayground' })}
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user