Skip to content

Commit eb73648

Browse files
authored
Add MaaS model to check the llama model enabled status (opendatahub-io#5244)
1 parent 1dfe5f6 commit eb73648

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

packages/gen-ai/frontend/src/app/Chatbot/ChatbotPlayground.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { useLocation } from 'react-router-dom';
1414
import { useUserContext } from '~/app/context/UserContext';
1515
import { ChatbotContext } from '~/app/context/ChatbotContext';
16-
import { getLlamaModelStatus } from '~/app/utilities';
16+
import { isLlamaModelEnabled } from '~/app/utilities';
1717
import { DEFAULT_SYSTEM_INSTRUCTIONS, FILE_UPLOAD_CONFIG, ERROR_MESSAGES } from './const';
1818
import { ChatbotSourceSettingsModal } from './sourceUpload/ChatbotSourceSettingsModal';
1919
import useSourceManagement from './hooks/useSourceManagement';
@@ -42,6 +42,7 @@ const ChatbotPlayground: React.FC<ChatbotPlaygroundProps> = ({
4242
models,
4343
modelsLoaded,
4444
aiModels,
45+
maasModels,
4546
selectedModel,
4647
setSelectedModel,
4748
lastInput,
@@ -66,15 +67,23 @@ const ChatbotPlayground: React.FC<ChatbotPlaygroundProps> = ({
6667
// so that when refreshing the page, the selected model is not passed again
6768
window.history.replaceState({}, '');
6869
} else {
69-
const availableModels = models.filter(
70-
(model) => getLlamaModelStatus(model.id, aiModels) === 'Running',
70+
const availableModels = models.filter((model) =>
71+
isLlamaModelEnabled(model.id, aiModels, maasModels),
7172
);
7273
if (availableModels.length > 0) {
7374
setSelectedModel(availableModels[0].id);
7475
}
7576
}
7677
}
77-
}, [modelsLoaded, models, selectedModel, setSelectedModel, aiModels, selectedAAModel]);
78+
}, [
79+
modelsLoaded,
80+
models,
81+
selectedModel,
82+
setSelectedModel,
83+
aiModels,
84+
maasModels,
85+
selectedAAModel,
86+
]);
7887

7988
// Custom hooks for managing different aspects of the chatbot
8089
const alertManagement = useAlertManagement();

packages/gen-ai/frontend/src/app/Chatbot/components/ModelDetailsDropdown.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { ExclamationCircleIcon } from '@patternfly/react-icons';
1212
import { fireMiscTrackingEvent } from '@odh-dashboard/internal/concepts/analyticsTracking/segmentIOUtils';
1313
import { ChatbotContext } from '~/app/context/ChatbotContext';
14-
import { getLlamaModelDisplayName, getLlamaModelStatus } from '~/app/utilities';
14+
import { getLlamaModelDisplayName, isLlamaModelEnabled } from '~/app/utilities';
1515

1616
interface ModelDetailsDropdownProps {
1717
selectedModel: string;
@@ -22,7 +22,7 @@ const ModelDetailsDropdown: React.FunctionComponent<ModelDetailsDropdownProps> =
2222
selectedModel,
2323
onModelChange,
2424
}) => {
25-
const { models, aiModels } = React.useContext(ChatbotContext);
25+
const { models, aiModels, maasModels } = React.useContext(ChatbotContext);
2626
const [isOpen, setIsOpen] = React.useState(false);
2727

2828
const placeholder = models.length === 0 ? 'No models available' : 'Select a model';
@@ -62,7 +62,7 @@ const ModelDetailsDropdown: React.FunctionComponent<ModelDetailsDropdownProps> =
6262
>
6363
<DropdownList style={{ maxHeight: '300px', overflowY: 'auto' }}>
6464
{models.map((option) => {
65-
const isDisabled = getLlamaModelStatus(option.id, aiModels) !== 'Running';
65+
const isDisabled = !isLlamaModelEnabled(option.id, aiModels, maasModels);
6666
return (
6767
<DropdownItem
6868
value={option.id}

packages/gen-ai/frontend/src/app/utilities/utils.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,25 @@ export const getLlamaModelDisplayName = (modelId: string, aiModels: AIModel[]):
3737
return `${providerId}/${enabledModel.display_name}`;
3838
};
3939

40-
export const getLlamaModelStatus = (
40+
export const isLlamaModelEnabled = (
4141
modelId: string,
4242
aiModels: AIModel[],
43-
): AIModel['status'] | undefined => {
43+
maasModels: MaaSModel[],
44+
): boolean => {
4445
const { id } = splitLlamaModelId(modelId);
46+
4547
const enabledModel = aiModels.find((aiModel) => aiModel.model_id === id);
46-
return enabledModel?.status;
48+
49+
if (enabledModel) {
50+
return enabledModel.status === 'Running';
51+
}
52+
53+
const maasModel = maasModels.find((m) => m.id === id);
54+
if (maasModel) {
55+
return maasModel.ready;
56+
}
57+
58+
return false;
4759
};
4860

4961
export const generateMCPServerConfig = (

0 commit comments

Comments
 (0)