Changesets · Branches · Tags · Compare
| Changeset | 54c1c444611d38ffb95bd6bd490f19d0199e4ab37d35198c083b3d51555fa68e |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-09-11 14:07 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-09-11 14:07 -07:00 |
| Parents | cda4ebce3e94, 4369cf8c84d9 |
11 files changed
modified core/llm/autodetect.ts +27 −1
| @@ -1,4 +1,9 @@ | ||
| 1 | -import { ChatMessage, ModelCapability, TemplateType } from "../index.js"; | |
| 1 | +import { | |
| 2 | + ChatMessage, | |
| 3 | + ModelCapability, | |
| 4 | + ModelDescription, | |
| 5 | + TemplateType, | |
| 6 | +} from "../index.js"; | |
| 2 | 7 | import { NEXT_EDIT_MODELS } from "./constants.js"; |
| 3 | 8 | |
| 4 | 9 | import { |
| @@ -126,6 +131,26 @@ | ||
| 126 | 131 | |
| 127 | 132 | return false; |
| 128 | 133 | } |
| 134 | + | |
| 135 | +function modelSupportsReasoning( | |
| 136 | + model: ModelDescription | null | undefined, | |
| 137 | +): boolean { | |
| 138 | + if (!model) { | |
| 139 | + return false; | |
| 140 | + } | |
| 141 | + if ("anthropic" === model.underlyingProviderName) { | |
| 142 | + return true; | |
| 143 | + } | |
| 144 | + if (model.model.includes("deepseek-r")) { | |
| 145 | + return true; | |
| 146 | + } | |
| 147 | + if (model.completionOptions?.reasoning) { | |
| 148 | + // Reasoning support is forced at the config level. Model might not necessarily support it though! | |
| 149 | + return true; | |
| 150 | + } | |
| 151 | + return false; | |
| 152 | +} | |
| 153 | + | |
| 129 | 154 | const PARALLEL_PROVIDERS: string[] = [ |
| 130 | 155 | "anthropic", |
| 131 | 156 | "bedrock", |
| @@ -421,4 +446,5 @@ | ||
| 421 | 446 | llmCanGenerateInParallel, |
| 422 | 447 | modelSupportsImages, |
| 423 | 448 | modelSupportsNextEdit, |
| 449 | + modelSupportsReasoning, | |
| 424 | 450 | }; |
modified core/llm/llms/Ollama.ts +2 −1
| @@ -87,6 +87,7 @@ | ||
| 87 | 87 | tools?: OllamaTool[]; // the tools of the chat, this can be used to keep a tool memory |
| 88 | 88 | // Not supported yet - tools: tools for the model to use if supported. Requires stream to be set to false |
| 89 | 89 | // And correspondingly, tool calls in OllamaChatMessage |
| 90 | + think?: boolean; // if true the model will be prompted to think about the response before generating it | |
| 90 | 91 | } |
| 91 | 92 | |
| 92 | 93 | type OllamaBaseResponse = { |
| @@ -146,7 +147,6 @@ | ||
| 146 | 147 | private static modelsBeingInstalledMutex = new Mutex(); |
| 147 | 148 | |
| 148 | 149 | private fimSupported: boolean = false; |
| 149 | - | |
| 150 | 150 | constructor(options: LLMOptions) { |
| 151 | 151 | super(options); |
| 152 | 152 | |
| @@ -393,6 +393,7 @@ | ||
| 393 | 393 | model: this._getModel(), |
| 394 | 394 | messages: ollamaMessages, |
| 395 | 395 | options: this._getModelFileParams(options), |
| 396 | + think: options.reasoning, | |
| 396 | 397 | keep_alive: options.keepAlive ?? 60 * 30, // 30 minutes |
| 397 | 398 | stream: options.stream, |
| 398 | 399 | // format: options.format, // Not currently in base completion options |
modified docs/reference.mdx +1 −1
| @@ -219,7 +219,7 @@ | ||
| 219 | 219 | - `topP`: The cumulative probability for nucleus sampling. |
| 220 | 220 | - `topK`: Maximum number of tokens considered at each step. |
| 221 | 221 | - `stop`: An array of stop tokens that will terminate the completion. |
| 222 | - - `reasoning`: Boolean to enable thinking/reasoning for Anthropic Claude 3.7+ models. | |
| 222 | + - `reasoning`: Boolean to enable thinking/reasoning for Anthropic Claude 3.7+ and some Ollama models. | |
| 223 | 223 | - `reasoningBudgetTokens`: Budget tokens for thinking/reasoning in Anthropic Claude 3.7+ models. |
| 224 | 224 | |
| 225 | 225 | - `requestOptions`: HTTP request options specific to the model. |
modified docs/reference/json-reference.mdx +1 −5
| @@ -191,7 +191,7 @@ | ||
| 191 | 191 | - `keepAlive`: For Ollama, this parameter sets the number of seconds to keep the model loaded after the last request, unloading it from memory if inactive (default: `1800` seconds, or 30 minutes). |
| 192 | 192 | - `numGpu`: For Ollama, this parameter overrides the number of gpu layers that will be used to load the model into VRAM. |
| 193 | 193 | - `useMmap`: For Ollama, this parameter allows the model to be mapped into memory. If disabled can enhance response time on low end devices but will slow down the stream. |
| 194 | -- `reasoning`: Enables thinking/reasoning for Anthropic Claude 3.7+ models. | |
| 194 | +- `reasoning`: Enables thinking/reasoning for Anthropic Claude 3.7+ and some Ollama models. | |
| 195 | 195 | - `reasoningBudgetTokens`: Sets budget tokens for thinking/reasoning in Anthropic Claude 3.7+ models. |
| 196 | 196 | |
| 197 | 197 | Example |
| @@ -485,8 +485,6 @@ | ||
| 485 | 485 | - `applyCodeBlock`: Model title for applying code blocks. |
| 486 | 486 | - `repoMapFileSelection`: Model title for repo map selections. |
| 487 | 487 | |
| 488 | - | |
| 489 | - | |
| 490 | 488 | - `modelContextProtocolServers`: See [Model Context Protocol](/customize/deep-dives/mcp) |
| 491 | 489 | |
| 492 | 490 | Example |
| @@ -540,5 +538,3 @@ | ||
| 540 | 538 | - `codeWrap` |
| 541 | 539 | - `displayRawMarkdown` |
| 542 | 540 | - `showChatScrollbar` |
| 543 | - | |
| 544 | - |
modified extensions/vscode/config_schema.json +1 −1
| @@ -78,7 +78,7 @@ | ||
| 78 | 78 | }, |
| 79 | 79 | "reasoning": { |
| 80 | 80 | "title": "Reasoning", |
| 81 | - "description": "Enable thinking/reasoning for Anthropic Claude 3.7+ models", | |
| 81 | + "description": "Enable thinking/reasoning for Anthropic Claude 3.7+ and some Ollama models", | |
| 82 | 82 | "type": "boolean" |
| 83 | 83 | }, |
| 84 | 84 | "reasoningBudgetTokens": { |
modified gui/src/components/mainInput/InputToolbar.tsx +7 −2
| @@ -5,7 +5,10 @@ | ||
| 5 | 5 | } from "@heroicons/react/24/outline"; |
| 6 | 6 | import { LightBulbIcon as LightBulbIconSolid } from "@heroicons/react/24/solid"; |
| 7 | 7 | import { InputModifiers } from "core"; |
| 8 | -import { modelSupportsImages } from "core/llm/autodetect"; | |
| 8 | +import { | |
| 9 | + modelSupportsImages, | |
| 10 | + modelSupportsReasoning, | |
| 11 | +} from "core/llm/autodetect"; | |
| 9 | 12 | import { useContext, useRef } from "react"; |
| 10 | 13 | import { IdeMessengerContext } from "../../context/IdeMessenger"; |
| 11 | 14 | import { useAppDispatch, useAppSelector } from "../../redux/hooks"; |
| @@ -66,6 +69,8 @@ | ||
| 66 | 69 | defaultModel.capabilities, |
| 67 | 70 | ); |
| 68 | 71 | |
| 72 | + const supportsReasoning = modelSupportsReasoning(defaultModel); | |
| 73 | + | |
| 69 | 74 | const smallFont = useFontSize(-2); |
| 70 | 75 | const tinyFont = useFontSize(-3); |
| 71 | 76 | |
| @@ -130,7 +135,7 @@ | ||
| 130 | 135 | </HoverItem> |
| 131 | 136 | </ToolTip> |
| 132 | 137 | )} |
| 133 | - {defaultModel?.underlyingProviderName === "anthropic" && ( | |
| 138 | + {supportsReasoning && ( | |
| 134 | 139 | <HoverItem |
| 135 | 140 | onClick={() => |
| 136 | 141 | dispatch(setHasReasoningEnabled(!hasReasoningEnabled)) |
modified gui/src/hooks/ParallelListeners.tsx +8 −6
| @@ -19,6 +19,7 @@ | ||
| 19 | 19 | } from "../redux/slices/sessionSlice"; |
| 20 | 20 | import { setTTSActive } from "../redux/slices/uiSlice"; |
| 21 | 21 | |
| 22 | +import { modelSupportsReasoning } from "core/llm/autodetect"; | |
| 22 | 23 | import { cancelStream } from "../redux/thunks/cancelStream"; |
| 23 | 24 | import { handleApplyStateUpdate } from "../redux/thunks/handleApplyStateUpdate"; |
| 24 | 25 | import { refreshSessionMetadata } from "../redux/thunks/session"; |
| @@ -79,12 +80,13 @@ | ||
| 79 | 80 | document.body.style.fontSize = `${configResult.config.ui.fontSize}px`; |
| 80 | 81 | } |
| 81 | 82 | |
| 82 | - if ( | |
| 83 | - configResult.config?.selectedModelByRole.chat?.completionOptions | |
| 84 | - ?.reasoning | |
| 85 | - ) { | |
| 86 | - dispatch(setHasReasoningEnabled(true)); | |
| 87 | - } | |
| 83 | + const chatModel = configResult.config?.selectedModelByRole.chat; | |
| 84 | + const supportsReasoning = modelSupportsReasoning(chatModel); | |
| 85 | + const isReasoningDisabled = | |
| 86 | + chatModel?.completionOptions?.reasoning === false; | |
| 87 | + dispatch( | |
| 88 | + setHasReasoningEnabled(supportsReasoning && !isReasoningDisabled), | |
| 89 | + ); | |
| 88 | 90 | }, |
| 89 | 91 | [dispatch, hasDoneInitialConfigLoad], |
| 90 | 92 | ); |
modified gui/src/redux/thunks/streamNormalInput.ts +40 −11
| @@ -1,13 +1,14 @@ | ||
| 1 | +import { ToolPolicy } from "@continuedev/terminal-security"; | |
| 1 | 2 | import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit"; |
| 2 | 3 | import { |
| 3 | - ContextItem, | |
| 4 | 4 | LLMFullCompletionOptions, |
| 5 | + ModelDescription, | |
| 5 | 6 | Tool, |
| 6 | 7 | ToolCallState, |
| 7 | 8 | } from "core"; |
| 8 | -import { ToolPolicy } from "@continuedev/terminal-security"; | |
| 9 | 9 | import { getRuleId } from "core/llm/rules/getSystemMessageWithRules"; |
| 10 | 10 | import { ToCoreProtocol } from "core/protocol"; |
| 11 | +import { IIdeMessenger } from "../../context/IdeMessenger"; | |
| 11 | 12 | import { selectActiveTools } from "../selectors/selectActiveTools"; |
| 12 | 13 | import { selectSelectedChatModel } from "../slices/configSlice"; |
| 13 | 14 | import { |
| @@ -25,7 +26,6 @@ | ||
| 25 | 26 | updateToolCallOutput, |
| 26 | 27 | } from "../slices/sessionSlice"; |
| 27 | 28 | import { AppThunkDispatch, RootState, ThunkApiType } from "../store"; |
| 28 | -import { IIdeMessenger } from "../../context/IdeMessenger"; | |
| 29 | 29 | import { constructMessages } from "../util/constructMessages"; |
| 30 | 30 | |
| 31 | 31 | import { modelSupportsNativeTools } from "core/llm/toolSupport"; |
| @@ -192,6 +192,38 @@ | ||
| 192 | 192 | return allAutoApproved; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | +/** | |
| 196 | + * Builds completion options with reasoning configuration based on session state and model capabilities. | |
| 197 | + * | |
| 198 | + * @param baseOptions - Base completion options to extend | |
| 199 | + * @param hasReasoningEnabled - Whether reasoning is enabled in the session | |
| 200 | + * @param model - The selected model with provider and completion options | |
| 201 | + * @returns Completion options with reasoning configuration | |
| 202 | + */ | |
| 203 | +function buildReasoningCompletionOptions( | |
| 204 | + baseOptions: LLMFullCompletionOptions, | |
| 205 | + hasReasoningEnabled: boolean | undefined, | |
| 206 | + model: ModelDescription, | |
| 207 | +): LLMFullCompletionOptions { | |
| 208 | + if (hasReasoningEnabled === undefined) { | |
| 209 | + return baseOptions; | |
| 210 | + } | |
| 211 | + | |
| 212 | + const reasoningOptions: LLMFullCompletionOptions = { | |
| 213 | + ...baseOptions, | |
| 214 | + reasoning: !!hasReasoningEnabled, | |
| 215 | + }; | |
| 216 | + | |
| 217 | + // Add reasoning budget tokens if reasoning is enabled and provider supports it | |
| 218 | + if (hasReasoningEnabled && model.underlyingProviderName !== "ollama") { | |
| 219 | + // Ollama doesn't support limiting reasoning tokens at this point | |
| 220 | + reasoningOptions.reasoningBudgetTokens = | |
| 221 | + model.completionOptions?.reasoningBudgetTokens ?? 2048; | |
| 222 | + } | |
| 223 | + | |
| 224 | + return reasoningOptions; | |
| 225 | +} | |
| 226 | + | |
| 195 | 227 | export const streamNormalInput = createAsyncThunk< |
| 196 | 228 | void, |
| 197 | 229 | { |
| @@ -228,14 +260,11 @@ | ||
| 228 | 260 | }; |
| 229 | 261 | } |
| 230 | 262 | |
| 231 | - if (state.session.hasReasoningEnabled) { | |
| 232 | - completionOptions = { | |
| 233 | - ...completionOptions, | |
| 234 | - reasoning: true, | |
| 235 | - reasoningBudgetTokens: | |
| 236 | - selectedChatModel.completionOptions?.reasoningBudgetTokens ?? 2048, | |
| 237 | - }; | |
| 238 | - } | |
| 263 | + completionOptions = buildReasoningCompletionOptions( | |
| 264 | + completionOptions, | |
| 265 | + state.session.hasReasoningEnabled, | |
| 266 | + selectedChatModel, | |
| 267 | + ); | |
| 239 | 268 | |
| 240 | 269 | // Construct messages (excluding system message) |
| 241 | 270 | const baseSystemMessage = getBaseSystemMessage( |
modified gui/src/redux/thunks/streamResponse.test.ts +15 −5
| @@ -435,12 +435,16 @@ | ||
| 435 | 435 | ], |
| 436 | 436 | }, |
| 437 | 437 | ], |
| 438 | - options: {}, | |
| 438 | + options: { | |
| 439 | + reasoning: false, | |
| 440 | + }, | |
| 439 | 441 | }); |
| 440 | 442 | |
| 441 | 443 | expect(mockIdeMessenger.llmStreamChat).toHaveBeenCalledWith( |
| 442 | 444 | { |
| 443 | - completionOptions: {}, | |
| 445 | + completionOptions: { | |
| 446 | + reasoning: false, | |
| 447 | + }, | |
| 444 | 448 | legacySlashCommandData: undefined, |
| 445 | 449 | messageOptions: { precompiled: true }, |
| 446 | 450 | messages: [ |
| @@ -918,7 +922,9 @@ | ||
| 918 | 922 | ], |
| 919 | 923 | }, |
| 920 | 924 | ], |
| 921 | - options: {}, | |
| 925 | + options: { | |
| 926 | + reasoning: false, | |
| 927 | + }, | |
| 922 | 928 | }, |
| 923 | 929 | ); |
| 924 | 930 | |
| @@ -1527,13 +1533,17 @@ | ||
| 1527 | 1533 | ], |
| 1528 | 1534 | }, |
| 1529 | 1535 | ], |
| 1530 | - options: {}, | |
| 1536 | + options: { | |
| 1537 | + reasoning: false, | |
| 1538 | + }, | |
| 1531 | 1539 | }, |
| 1532 | 1540 | ); |
| 1533 | 1541 | |
| 1534 | 1542 | expect(mockIdeMessengerAbort.llmStreamChat).toHaveBeenCalledWith( |
| 1535 | 1543 | { |
| 1536 | - completionOptions: {}, | |
| 1544 | + completionOptions: { | |
| 1545 | + reasoning: false, | |
| 1546 | + }, | |
| 1537 | 1547 | legacySlashCommandData: undefined, |
| 1538 | 1548 | messageOptions: { precompiled: true }, |
| 1539 | 1549 | messages: [ |
modified gui/src/redux/thunks/streamResponse_errorHandling.test.ts +6 −2
| @@ -677,7 +677,9 @@ | ||
| 677 | 677 | ], |
| 678 | 678 | }, |
| 679 | 679 | ], |
| 680 | - options: {}, | |
| 680 | + options: { | |
| 681 | + reasoning: false, | |
| 682 | + }, | |
| 681 | 683 | }); |
| 682 | 684 | expect(mockIdeMessenger.llmStreamChat).not.toHaveBeenCalled(); |
| 683 | 685 | |
| @@ -1027,7 +1029,9 @@ | ||
| 1027 | 1029 | ], |
| 1028 | 1030 | }, |
| 1029 | 1031 | ], |
| 1030 | - options: {}, | |
| 1032 | + options: { | |
| 1033 | + reasoning: false, | |
| 1034 | + }, | |
| 1031 | 1035 | }); |
| 1032 | 1036 | expect(mockIdeMessenger.llmStreamChat).not.toHaveBeenCalled(); |
| 1033 | 1037 |
modified gui/src/redux/thunks/streamResponse_toolCalls.test.ts +15 −5
| @@ -535,7 +535,9 @@ | ||
| 535 | 535 | ], |
| 536 | 536 | }, |
| 537 | 537 | ], |
| 538 | - options: {}, | |
| 538 | + options: { | |
| 539 | + reasoning: false, | |
| 540 | + }, | |
| 539 | 541 | }, |
| 540 | 542 | ); |
| 541 | 543 | |
| @@ -1217,13 +1219,17 @@ | ||
| 1217 | 1219 | ], |
| 1218 | 1220 | }, |
| 1219 | 1221 | ], |
| 1220 | - options: {}, | |
| 1222 | + options: { | |
| 1223 | + reasoning: false, | |
| 1224 | + }, | |
| 1221 | 1225 | }, |
| 1222 | 1226 | ); |
| 1223 | 1227 | |
| 1224 | 1228 | expect(mockIdeMessengerReject.llmStreamChat).toHaveBeenCalledWith( |
| 1225 | 1229 | { |
| 1226 | - completionOptions: {}, | |
| 1230 | + completionOptions: { | |
| 1231 | + reasoning: false, | |
| 1232 | + }, | |
| 1227 | 1233 | legacySlashCommandData: undefined, |
| 1228 | 1234 | messageOptions: { precompiled: true }, |
| 1229 | 1235 | messages: [ |
| @@ -1877,13 +1883,17 @@ | ||
| 1877 | 1883 | ], |
| 1878 | 1884 | }, |
| 1879 | 1885 | ], |
| 1880 | - options: {}, | |
| 1886 | + options: { | |
| 1887 | + reasoning: false, | |
| 1888 | + }, | |
| 1881 | 1889 | }, |
| 1882 | 1890 | ); |
| 1883 | 1891 | |
| 1884 | 1892 | expect(mockIdeMessengerManual.llmStreamChat).toHaveBeenCalledWith( |
| 1885 | 1893 | { |
| 1886 | - completionOptions: {}, | |
| 1894 | + completionOptions: { | |
| 1895 | + reasoning: false, | |
| 1896 | + }, | |
| 1887 | 1897 | legacySlashCommandData: undefined, |
| 1888 | 1898 | messageOptions: { precompiled: true }, |
| 1889 | 1899 | messages: [ |