diff --git a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx index b2e57bf71..1c661cf3e 100644 --- a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx @@ -18,6 +18,7 @@ import { setDialogMessage, setShowDialog, } from "../../../../redux/slices/uiSlice"; +import { getBaseSystemMessage } from "../../../../util"; import HeaderButtonWithToolTip from "../../../gui/HeaderButtonWithToolTip"; import { useFontSize } from "../../../ui/font"; import { ExploreBlocksButton } from "./ExploreBlocksButton"; @@ -182,12 +183,7 @@ export function RulesSection() { } // Add a displayed rule for the base system chat message when in chat mode if (mode === "chat" || mode === "agent") { - let baseMessage:string | undefined; - if(mode === 'agent') { - baseMessage = config.selectedModelByRole.chat?.baseAgentSystemMessage ?? config.selectedModelByRole.chat?.baseChatSystemMessage - } else { - baseMessage = config.selectedModelByRole.chat?.baseChatSystemMessage - } + const baseMessage = getBaseSystemMessage(config.selectedModelByRole.chat, mode) if (baseMessage) { rules.unshift({ rule: baseMessage, diff --git a/gui/src/redux/thunks/streamResponse.ts b/gui/src/redux/thunks/streamResponse.ts index 4b7ccf798..6c406f868 100644 --- a/gui/src/redux/thunks/streamResponse.ts +++ b/gui/src/redux/thunks/streamResponse.ts @@ -4,6 +4,7 @@ import { InputModifiers } from "core"; import { constructMessages } from "core/llm/constructMessages"; import posthog from "posthog-js"; import { v4 as uuidv4 } from "uuid"; +import { getBaseSystemMessage } from "../../util"; import { selectSelectedChatModel } from "../slices/configSlice"; import { submitEditorAndInitAtIndex, @@ -87,12 +88,7 @@ export const streamResponseThunk = createAsyncThunk< const updatedHistory = getState().session.history; const messageMode = getState().session.mode - let baseChatOrAgentSystemMessage: string|undefined - if(messageMode === 'agent') { - baseChatOrAgentSystemMessage = selectedChatModel?.baseAgentSystemMessage ?? selectedChatModel?.baseChatSystemMessage // fallback to chat system message if agent system message is unavailable - } else { - baseChatOrAgentSystemMessage = selectedChatModel.baseChatSystemMessage - } + const baseChatOrAgentSystemMessage = getBaseSystemMessage(selectedChatModel, messageMode) const messages = constructMessages( [...updatedHistory], diff --git a/gui/src/redux/thunks/streamResponseAfterToolCall.ts b/gui/src/redux/thunks/streamResponseAfterToolCall.ts index 813a5e1f8..2b4ada0c1 100644 --- a/gui/src/redux/thunks/streamResponseAfterToolCall.ts +++ b/gui/src/redux/thunks/streamResponseAfterToolCall.ts @@ -2,6 +2,7 @@ import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit"; import { ChatMessage } from "core"; import { constructMessages } from "core/llm/constructMessages"; import { renderContextItems } from "core/util/messageContent"; +import { getBaseSystemMessage } from "../../util"; import { selectSelectedChatModel } from "../slices/configSlice"; import { addContextItemsAtIndex, @@ -68,12 +69,7 @@ export const streamResponseAfterToolCall = createAsyncThunk< const updatedHistory = getState().session.history; const messageMode = getState().session.mode - let baseChatOrAgentSystemMessage: string|undefined - if(messageMode === 'agent') { - baseChatOrAgentSystemMessage = selectedChatModel?.baseAgentSystemMessage ?? selectedChatModel?.baseChatSystemMessage // fallback to chat system message if agent system message is unavailable - } else { - baseChatOrAgentSystemMessage = selectedChatModel.baseChatSystemMessage - } + const baseChatOrAgentSystemMessage = getBaseSystemMessage(selectedChatModel, messageMode) const messages = constructMessages( [...updatedHistory], diff --git a/gui/src/util/index.ts b/gui/src/util/index.ts index f2b18105b..511dd1a64 100644 --- a/gui/src/util/index.ts +++ b/gui/src/util/index.ts @@ -1,3 +1,4 @@ +import { MessageModes, ModelDescription } from "core"; import { ProfileDescription } from "core/config/ProfileLifecycleManager"; import _ from "lodash"; import { KeyboardEvent } from "react"; @@ -114,3 +115,16 @@ export function updatedObj(old: any, pathToValue: { [key: string]: any }) { export function isLocalProfile(profile: ProfileDescription): boolean { return profile.profileType === "local"; } + +/** + * Get the base system message for the agent or chat mode from the model description. + */ +export function getBaseSystemMessage(modelDetails: ModelDescription | null, mode: MessageModes) { + let baseChatOrAgentSystemMessage: string|undefined + if(mode === 'agent') { + baseChatOrAgentSystemMessage = modelDetails?.baseAgentSystemMessage ?? modelDetails?.baseChatSystemMessage // fallback to chat system message if agent system message is unavailable + } else { + baseChatOrAgentSystemMessage = modelDetails?.baseChatSystemMessage + } + return baseChatOrAgentSystemMessage +} \ No newline at end of file