diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index 23d242ae2..0dfbcd493 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -1,4 +1,8 @@ -import { AtSymbolIcon, PhotoIcon } from "@heroicons/react/24/outline"; +import { + AtSymbolIcon, + LightBulbIcon, + PhotoIcon, +} from "@heroicons/react/24/outline"; import { InputModifiers } from "core"; import { modelSupportsImages, modelSupportsTools } from "core/llm/autodetect"; import { useContext, useRef } from "react"; @@ -10,8 +14,10 @@ import { selectCurrentToolCallApplyState, } from "../../redux/selectors/selectCurrentToolCall"; import { selectSelectedChatModel } from "../../redux/slices/configSlice"; +import { setHasReasoningEnabled } from "../../redux/slices/sessionSlice"; import { exitEdit } from "../../redux/thunks/edit"; import { getAltKeyLabel, isMetaEquivalentKeyPressed } from "../../util"; +import { cn } from "../../util/cn"; import { ToolTip } from "../gui/Tooltip"; import ModelSelect from "../modelSelection/ModelSelect"; import { ModeSelect } from "../ModeSelect"; @@ -51,6 +57,9 @@ function InputToolbar(props: InputToolbarProps) { const currentToolCallApplyState = useAppSelector( selectCurrentToolCallApplyState, ); + const hasReasoningEnabled = useAppSelector( + (store) => store.session.hasReasoningEnabled, + ); const isEnterDisabled = props.disabled || @@ -143,6 +152,25 @@ function InputToolbar(props: InputToolbarProps) { )} + {defaultModel?.provider === "anthropic" && ( + + dispatch(setHasReasoningEnabled(!hasReasoningEnabled)) + } + > + + + + Use Model Reasoning + + + )} diff --git a/gui/src/hooks/ParallelListeners.tsx b/gui/src/hooks/ParallelListeners.tsx index a283ed969..8d0fef86d 100644 --- a/gui/src/hooks/ParallelListeners.tsx +++ b/gui/src/hooks/ParallelListeners.tsx @@ -20,6 +20,7 @@ import { import { acceptToolCall, addContextItemsAtIndex, + setHasReasoningEnabled, updateApplyState, } from "../redux/slices/sessionSlice"; import { setTTSActive } from "../redux/slices/uiSlice"; @@ -86,6 +87,13 @@ function ParallelListeners() { setLocalStorage("fontSize", configResult.config.ui.fontSize); document.body.style.fontSize = `${configResult.config.ui.fontSize}px`; } + + if ( + configResult.config?.selectedModelByRole.chat?.completionOptions + ?.reasoning + ) { + dispatch(setHasReasoningEnabled(true)); + } }, [dispatch, hasDoneInitialConfigLoad], ); @@ -241,7 +249,7 @@ function ParallelListeners() { dispatch(updateEditStateApplyState(state)); if (state.status === "closed") { - dispatch(exitEdit({})); + void dispatch(exitEdit({})); } } else { // chat or agent diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 37eba4b4f..6803947fb 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -51,6 +51,7 @@ type SessionState = { curIndex: number; }; newestToolbarPreviewForInput: Record; + hasReasoningEnabled?: boolean; }; const initialState: SessionState = { @@ -594,6 +595,9 @@ export const sessionSlice = createSlice({ setIsInEdit: (state, action: PayloadAction) => { state.isInEdit = action.payload; }, + setHasReasoningEnabled: (state, action: PayloadAction) => { + state.hasReasoningEnabled = action.payload; + }, setNewestToolbarPreviewForInput: ( state, { @@ -691,6 +695,7 @@ export const { deleteSessionMetadata, setNewestToolbarPreviewForInput, setIsInEdit, + setHasReasoningEnabled, } = sessionSlice.actions; export const { selectIsGatheringContext } = sessionSlice.selectors; diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index 441cf3c20..6d84f800e 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -45,6 +45,14 @@ export const streamNormalInput = createAsyncThunk< }; } + if (state.session.hasReasoningEnabled) { + completionOptions = { + ...completionOptions, + reasoning: true, + reasoningBudgetTokens: completionOptions.reasoningBudgetTokens ?? 2048, + }; + } + // Send request const gen = extra.ideMessenger.llmStreamChat( {