Skip to content

Commit

Permalink
Updating to pull Models and supplemental info from configs vs API
Browse files Browse the repository at this point in the history
  • Loading branch information
estohlmann committed Jun 5, 2024
1 parent b7a4be5 commit d7ca3f4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 25 deletions.
9 changes: 9 additions & 0 deletions lib/user-interface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ export class UserInterfaceStack extends Stack {
},
);

const modelsList = config.ecsModels.map((modelConfig) => {
return {
model: modelConfig.modelId,
streaming: modelConfig.streaming,
modelType: modelConfig.modelType,
};
});

// Website bucket deployment
// Copy auth and LISA-Serve info to UI deployment bucket
const appEnvConfig = {
Expand All @@ -179,6 +187,7 @@ export class UserInterfaceStack extends Stack {
fontColor: config.systemBanner?.fontColor,
},
API_BASE_URL: config.apiGatewayConfig?.domainName ? '/' : `/${config.deploymentStage}/`,
MODELS: modelsList,
};

const appEnvSource = Source.data('env.js', `window.env = ${JSON.stringify(appEnvConfig)}`);
Expand Down
8 changes: 5 additions & 3 deletions lib/user-interface/react/src/components/chatbot/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ export default function Chat({ sessionId }) {
useEffect(() => {
if (selectedModelOption) {
const model = models.filter((model) => model.id === selectedModelOption.value)[0];
setModelCanStream(true);
if (!model.streaming && streamingEnabled) {
setStreamingEnabled(false);
}
setModelCanStream(model.streaming);
setSelectedModel(model);
}
}, [selectedModelOption, streamingEnabled]);
Expand Down Expand Up @@ -463,8 +466,7 @@ export default function Chat({ sessionId }) {

const describeTextGenModels = useCallback(async () => {
setIsLoadingModels(true);
const resp = await describeModels(auth.user?.id_token);
setModels(resp.data);
setModels(describeModels('textgen'));
setIsLoadingModels(false);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@ export default function RagControls({ auth, isRunning, setUseRag, setRagConfig }
useEffect(() => {
setIsLoadingEmbeddingModels(true);
setIsLoadingRepositories(true);

describeModels(auth.user?.id_token).then((resp) => {
setEmbeddingModels(resp.data);
setIsLoadingEmbeddingModels(false);
});
setEmbeddingModels(describeModels('embedding'));
setIsLoadingEmbeddingModels(false);

listRagRepositories(auth.user?.id_token).then((repositories) => {
setRepositoryOptions(
Expand Down
16 changes: 4 additions & 12 deletions lib/user-interface/react/src/components/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,11 @@ export interface Repository {
/**
* Interface for model
*/
export interface Model {
export type Model = {
id: string;
object: string;
created: number;
owned_by: string;
}

/**
* Interface for the response body received when describing a model
*/
export interface DescribeModelsResponseBody {
data: Model[];
}
modelType: ModelTypes;
streaming?: boolean;
};

/**
* Interface for creating a session request body; composed of LisaChatMessageFields
Expand Down
13 changes: 8 additions & 5 deletions lib/user-interface/react/src/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

import {
LisaChatSession,
DescribeModelsResponseBody,
LisaChatMessageFields,
PutSessionRequestBody,
LisaChatMessage,
Repository,
ModelTypes,
Model,
} from './types';

Expand Down Expand Up @@ -167,12 +167,15 @@ export const deleteUserSessions = async (idToken: string) => {

/**
* Describes all models of a given type which are available to a user
* @param idToken the user's ID token from authenticating
* @param modelType model type we are requesting
* @returns
*/
export const describeModels = async (idToken: string): Promise<DescribeModelsResponseBody> => {
const resp = await sendAuthenticatedRequest(`${RESTAPI_URI}/${RESTAPI_VERSION}/serve/models`, 'GET', idToken);
return await resp.json();
export const describeModels = (modelType: ModelTypes): Model[] => {
return window.env.MODELS?.filter((m) => m.modelType === modelType).map((m) => ({
id: m.model,
streaming: m.streaming,
modelType: m.modelType,
}));
};

/**
Expand Down
8 changes: 8 additions & 0 deletions lib/user-interface/react/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import './index.css';
import AppConfigured from './components/app-configured';

import '@cloudscape-design/global-styles/index.css';
import { ModelTypes } from './components/types';

declare global {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
Expand All @@ -36,6 +37,13 @@ declare global {
backgroundColor: string;
fontColor: string;
};
MODELS: [
{
model: string;
streaming: boolean | null;
modelType: ModelTypes;
},
];
};
}
}
Expand Down

0 comments on commit d7ca3f4

Please sign in to comment.