Skip to content

Commit

Permalink
makes frontend use thie resultingChatInfoMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
pmarsh-scottlogic committed Mar 22, 2024
1 parent b466448 commit 2fa7519
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
5 changes: 4 additions & 1 deletion frontend/src/components/ControlPanel/ControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DEFENCES_HIDDEN_LEVEL3_IDS, MODEL_DEFENCES } from '@src/Defences';
import DefenceBox from '@src/components/DefenceBox/DefenceBox';
import DocumentViewButton from '@src/components/DocumentViewer/DocumentViewButton';
import ModelBox from '@src/components/ModelBox/ModelBox';
import { ChatModel } from '@src/models/chat';
import { ChatMessage, ChatModel } from '@src/models/chat';
import {
DEFENCE_ID,
DefenceConfigItem,
Expand All @@ -24,6 +24,7 @@ function ControlPanel({
setDefenceConfiguration,
openDocumentViewer,
addInfoMessage,
addChatMessage,
}: {
currentLevel: LEVEL_NAMES;
defences: Defence[];
Expand All @@ -41,6 +42,7 @@ function ControlPanel({
) => Promise<boolean>;
openDocumentViewer: () => void;
addInfoMessage: (message: string) => void;
addChatMessage: (chatMessage: ChatMessage) => void;
}) {
const configurableDefences =
currentLevel === LEVEL_NAMES.SANDBOX
Expand Down Expand Up @@ -103,6 +105,7 @@ function ControlPanel({
setChatModelId={setChatModelId}
chatModelOptions={chatModelOptions}
addInfoMessage={addInfoMessage}
addChatMessage={addChatMessage}
/>
)}
</details>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/MainComponent/MainBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function MainBody({
setDefenceConfiguration={setDefenceConfiguration}
openDocumentViewer={openDocumentViewer}
addInfoMessage={addInfoMessage}
addChatMessage={addChatMessage}
/>
</div>
<div className="centre-area">
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/components/ModelBox/ModelBox.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatModel } from '@src/models/chat';
import { ChatMessage, ChatModel } from '@src/models/chat';

import ModelConfiguration from './ModelConfiguration';
import ModelSelection from './ModelSelection';
Expand All @@ -10,11 +10,13 @@ function ModelBox({
setChatModelId,
chatModelOptions,
addInfoMessage,
addChatMessage,
}: {
chatModel?: ChatModel;
setChatModelId: (modelId: string) => void;
chatModelOptions: string[];
addInfoMessage: (message: string) => void;
addChatMessage: (chatMessage: ChatMessage) => void;
}) {
return (
<div className="model-box">
Expand All @@ -26,7 +28,7 @@ function ModelBox({
/>
<ModelConfiguration
chatModel={chatModel}
addInfoMessage={addInfoMessage}
addChatMessage={addChatMessage}
/>
</div>
);
Expand Down
21 changes: 12 additions & 9 deletions frontend/src/components/ModelBox/ModelConfiguration.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react';

import {
ChatMessage,
ChatModel,
CustomChatModelConfiguration,
MODEL_CONFIG_ID,
Expand Down Expand Up @@ -48,10 +49,10 @@ const DEFAULT_CONFIGS: CustomChatModelConfiguration[] = [

function ModelConfiguration({
chatModel,
addInfoMessage,
addChatMessage,
}: {
chatModel?: ChatModel;
addInfoMessage: (message: string) => void;
addChatMessage: (chatMessage: ChatMessage) => void;
}) {
const [customChatModelConfigs, setCustomChatModel] =
useState<CustomChatModelConfiguration[]>(DEFAULT_CONFIGS);
Expand All @@ -77,13 +78,15 @@ function ModelConfiguration({

setCustomChatModelByID(id, newValue);

void chatService.configureGptModel(id, newValue).then((success) => {
if (success) {
addInfoMessage(`changed ${id} to ${newValue}`);
} else {
setCustomChatModelByID(id, prevValue);
}
});
void chatService
.configureGptModel(id, newValue)
.then((resultingChatInfoMessage) => {
if (resultingChatInfoMessage) {
addChatMessage(resultingChatInfoMessage);
} else {
setCustomChatModelByID(id, prevValue);
}
});
}

useEffect(() => {
Expand Down

0 comments on commit 2fa7519

Please sign in to comment.