diff --git a/frontend/src/components/ModelBox/ModelSelection.tsx b/frontend/src/components/ModelBox/ModelSelection.tsx
index 8740548ef..019a6418c 100644
--- a/frontend/src/components/ModelBox/ModelSelection.tsx
+++ b/frontend/src/components/ModelBox/ModelSelection.tsx
@@ -2,22 +2,27 @@
import { useEffect, useState } from 'react';
import LoadingButton from '@src/components/ThemedButtons/LoadingButton';
+import { ChatModel } from '@src/models/chat';
import { chatService } from '@src/service';
import './ModelSelection.css';
// return a drop down menu with the models
function ModelSelection({
+ chatModel,
+ setChatModelId,
chatModelOptions,
addInfoMessage,
}: {
+ chatModel?: ChatModel;
+ setChatModelId: (modelId: string) => void;
chatModelOptions: string[];
addInfoMessage: (message: string) => void;
}) {
// model currently selected in the dropdown
- const [selectedModel, setSelectedModel] = useState
(null);
- // model in use by the app
- const [modelInUse, setModelInUse] = useState(null);
+ const [selectedModel, setSelectedModel] = useState(
+ undefined
+ );
const [errorChangingModel, setErrorChangingModel] = useState(false);
@@ -32,9 +37,9 @@ function ModelSelection({
const modelUpdated = await chatService.setGptModel(currentSelectedModel);
setIsSettingModel(false);
if (modelUpdated) {
- setModelInUse(currentSelectedModel);
setErrorChangingModel(false);
addInfoMessage(`changed model to ${currentSelectedModel}`);
+ setChatModelId(currentSelectedModel);
} else {
setErrorChangingModel(true);
}
@@ -43,67 +48,58 @@ function ModelSelection({
// get the model
useEffect(() => {
- chatService
- .getGptModel()
- .then((model) => {
- setModelInUse(model.id);
- // default the dropdown selection to the model in use
- setSelectedModel(model.id);
- })
- .catch((err) => {
- console.log(err);
- });
- }, []);
+ setSelectedModel(chatModel?.id);
+ }, [chatModel]);
// return a drop down menu with the models
return (
);
diff --git a/frontend/src/models/combined.ts b/frontend/src/models/combined.ts
index c77672b20..d70589842 100644
--- a/frontend/src/models/combined.ts
+++ b/frontend/src/models/combined.ts
@@ -1,4 +1,4 @@
-import { ChatMessageDTO } from './chat';
+import { ChatMessageDTO, ChatModel } from './chat';
import { DefenceDTO } from './defence';
import { EmailInfo } from './email';
import { LevelSystemRole } from './level';
@@ -9,12 +9,14 @@ type StartReponse = {
defences?: DefenceDTO[];
availableModels: string[];
systemRoles: LevelSystemRole[];
+ chatModel?: ChatModel;
};
type LoadLevelResponse = {
emails: EmailInfo[];
chatHistory: ChatMessageDTO[];
defences?: DefenceDTO[];
+ chatModel?: ChatModel;
};
export type { StartReponse, LoadLevelResponse };
diff --git a/frontend/src/service/chatService.ts b/frontend/src/service/chatService.ts
index 2ed55c7b0..97aaaeb08 100644
--- a/frontend/src/service/chatService.ts
+++ b/frontend/src/service/chatService.ts
@@ -2,7 +2,6 @@ import {
CHAT_MESSAGE_TYPE,
ChatMessageDTO,
ChatMessage,
- ChatModel,
ChatResponse,
MODEL_CONFIG,
} from '@src/models/chat';
@@ -87,11 +86,6 @@ async function configureGptModel(
return response.status === 200;
}
-async function getGptModel(): Promise {
- const response = await sendRequest(`${PATH}model`, { method: 'GET' });
- return (await response.json()) as ChatModel;
-}
-
async function addInfoMessageToChatHistory(
message: string,
chatMessageType: CHAT_MESSAGE_TYPE,
@@ -113,7 +107,6 @@ export {
clearChat,
sendMessage,
configureGptModel,
- getGptModel,
setGptModel,
addInfoMessageToChatHistory,
getChatMessagesFromDTOResponse,
diff --git a/frontend/src/service/levelService.ts b/frontend/src/service/levelService.ts
index d376d4d98..4b8619759 100644
--- a/frontend/src/service/levelService.ts
+++ b/frontend/src/service/levelService.ts
@@ -10,13 +10,14 @@ async function loadLevel(level: number) {
const response = await sendRequest(`${PATH}?level=${level}`, {
method: 'GET',
});
- const { defences, emails, chatHistory } =
+ const { defences, emails, chatHistory, chatModel } =
(await response.json()) as LoadLevelResponse;
return {
emails,
chatHistory: getChatMessagesFromDTOResponse(chatHistory),
defences: defences ? getDefencesFromDTOs(defences) : [],
+ chatModel,
};
}
diff --git a/frontend/src/service/startService.ts b/frontend/src/service/startService.ts
index 089764d15..55e5fb718 100644
--- a/frontend/src/service/startService.ts
+++ b/frontend/src/service/startService.ts
@@ -10,8 +10,14 @@ async function start(level: number) {
const response = await sendRequest(`${PATH}?level=${level}`, {
method: 'GET',
});
- const { availableModels, defences, emails, chatHistory, systemRoles } =
- (await response.json()) as StartReponse;
+ const {
+ availableModels,
+ defences,
+ emails,
+ chatHistory,
+ systemRoles,
+ chatModel,
+ } = (await response.json()) as StartReponse;
return {
emails,
@@ -19,6 +25,7 @@ async function start(level: number) {
defences: defences ? getDefencesFromDTOs(defences) : [],
availableModels,
systemRoles,
+ chatModel,
};
}