diff --git a/gui/src/components/mainInput/ContextStatus.tsx b/gui/src/components/mainInput/ContextStatus.tsx index 4ed048d86..abf06c19c 100644 --- a/gui/src/components/mainInput/ContextStatus.tsx +++ b/gui/src/components/mainInput/ContextStatus.tsx @@ -1,3 +1,4 @@ +import { useMemo, useRef } from "react"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { saveCurrentSession } from "../../redux/thunks/session"; import { useCompactConversation } from "../../util/compactConversation"; @@ -8,15 +9,36 @@ const ContextStatus = () => { const contextPercentage = useAppSelector( (state) => state.session.contextPercentage, ); + const selectedChatModel = useAppSelector( + (state) => state.config.config.selectedModelByRole.chat?.model, + ); + const previousHistoryLength = useRef(null); + const previousSelectedChatModel = useRef(null); const history = useAppSelector((state) => state.session.history); const percent = Math.round((contextPercentage ?? 0) * 100); const isPruned = useAppSelector((state) => state.session.isPruned); + const isDifferentModelAndSameHistory = useMemo(() => { + if (!selectedChatModel) return false; + // only reset if history changes + if (previousHistoryLength.current !== history.length) { + previousHistoryLength.current = history.length; + previousSelectedChatModel.current = selectedChatModel; + return false; + } + return previousSelectedChatModel.current !== selectedChatModel; + }, [history.length, selectedChatModel]); + const compactConversation = useCompactConversation(); if (!isPruned && percent < 60) { return null; } + // if user changed to a different model, we shouldn't show the context status until the user sends a new message + if (isDifferentModelAndSameHistory) { + return null; + } + const barColorClass = isPruned ? "bg-error" : "bg-description"; return (