-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: respect Ollama Modelfile num_ctx configuration #7798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed my own code and found issues I should have caught before pushing. Classic.
Critical Issues
-
Missing UI support - The new
ollamaNumCtxfield has no UI component in the settings panel, so users cannot configure this value through the interface. -
Missing type definition - The
ollamaNumCtxfield should be added to the ProviderSettings schema inpackages/types/src/provider-settings.tsfor proper type safety.
Suggestions
- Consider using proper TypeScript types instead of
anyfor the chat options - Add validation for the
ollamaNumCtxvalue to ensure it's within reasonable bounds - The documentation could be more explicit about when to use this override
src/api/providers/native-ollama.ts
Outdated
|
|
||
| try { | ||
| // Build options object conditionally | ||
| const chatOptions: any = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using any type here bypasses TypeScript's type checking. Consider defining a proper interface:
const chatOptions: { temperature: number; num_ctx?: number } = {
temperature: this.options.modelTemperature ?? (useR1Format ? DEEP_SEEK_DEFAULT_TEMPERATURE : 0),
}
src/api/providers/native-ollama.ts
Outdated
| const useR1Format = modelId.toLowerCase().includes("deepseek-r1") | ||
|
|
||
| // Build options object conditionally | ||
| const chatOptions: any = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same type safety issue here. Should use a proper type instead of any.
| * When set, this value will be used in Ollama chat requests. | ||
| * When undefined, Ollama will use the model's default num_ctx from the Modelfile. | ||
| */ | ||
| ollamaNumCtx?: number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional that we're not adding this field to the ProviderSettings type in packages/types? Without that, the field won't be properly validated when settings are saved/loaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be added to the ProviderSettings?
| apiModelId: "llama2", | ||
| ollamaModelId: "llama2", | ||
| ollamaBaseUrl: "http://localhost:11434", | ||
| ollamaNumCtx: 8192, // Explicitly set num_ctx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding tests for edge cases like negative numbers or extremely large values for ollamaNumCtx. Validation tests would help ensure the field only accepts reasonable values.
|
@hannesrudolph it seems that there's no way to set the new setting since there's no UI changes |
|
@roomote-agent lets add a setting for setting to set the CTX or whatever? |
|
Hi @hannesrudolph! I see the request - I'll add a UI setting for configuring the Ollama context window (num_ctx). This will allow users to set this value through the settings panel. Working on it now! |
|
Hi @hannesrudolph! I've successfully added the UI setting for Ollama's num_ctx configuration. Here's what was implemented: Changes Made:
How it works:
CI Status:Most checks are passing. The translation check is failing because translations for other languages need to be added - this is typically handled by the translation team or can be added in a follow-up. The feature is ready to use! Users can now configure the context window size for their Ollama models directly from the settings panel. |
Tested with and without this fix. So not only does the config now respect what the user has set in ollama, it can be overidden with a new box that shows up in the config. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue where Roo was forcefully overriding Ollama's Modelfile num_ctx configuration, causing memory allocation problems on budget GPUs. Previously, Roo automatically sent num_ctx equal to its inferred context window on every chat request, ignoring users' intentional Modelfile configurations.
- Removed automatic
num_ctxparameter from default Ollama chat options - Added optional
ollamaNumCtxparameter for explicit context window overrides - Updated both streaming and non-streaming Ollama methods to conditionally include
num_ctx
Reviewed Changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/shared/api.ts | Added ollamaNumCtx optional field to ApiHandlerOptions interface |
| src/api/providers/native-ollama.ts | Modified to conditionally include num_ctx only when explicitly set via ollamaNumCtx |
| src/api/providers/tests/native-ollama.spec.ts | Added comprehensive tests verifying conditional num_ctx behavior |
| packages/types/src/provider-settings.ts | Added ollamaNumCtx field to Ollama schema with validation |
| webview-ui/src/components/settings/providers/Ollama.tsx | Implemented UI input field for configuring context window size |
| webview-ui/src/i18n/locales/*/settings.json | Added localized strings for new context window configuration options |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| "numCtxHelp": "Sovrascrive la dimensione predefinita della finestra di contesto del modello. Lasciare vuoto per utilizzare la configurazione del Modelfile del modello. Il valore minimo è 128.", | ||
| "description": "Ollama ti permette di eseguire modelli localmente sul tuo computer. Per iniziare, consulta la guida rapida.", | ||
| "warning": "Nota: Roo Code utilizza prompt complessi e funziona meglio con i modelli Claude. I modelli con capacità inferiori potrebbero non funzionare come previsto." | ||
| "warning": "Nota: Roo Code utiliza prompt complessi e funziona meglio con i modelli Claude. I modelli con capacità inferiori potrebbero non funzionare come previsto." |
Copilot
AI
Sep 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Italian text uses 'utiliza' (Spanish) instead of the correct Italian 'utilizza'. This should be 'utilizza' to match proper Italian grammar.
| "warning": "Nota: Roo Code utiliza prompt complessi e funziona meglio con i modelli Claude. I modelli con capacità inferiori potrebbero non funzionare come previsto." | |
| "warning": "Nota: Roo Code utilizza prompt complessi e funziona meglio con i modelli Claude. I modelli con capacità inferiori potrebbero non funzionare come previsto." |
| "numCtxHelp": "Sovrascrive la dimensione predefinita della finestra di contesto del modello. Lasciare vuoto per utilizzare la configurazione del Modelfile del modello. Il valore minimo è 128.", | ||
| "description": "Ollama ti permette di eseguire modelli localmente sul tuo computer. Per iniziare, consulta la guida rapida.", | ||
| "warning": "Nota: Roo Code utilizza prompt complessi e funziona meglio con i modelli Claude. I modelli con capacità inferiori potrebbero non funzionare come previsto." | ||
| "warning": "Nota: Roo Code utiliza prompt complessi e funziona meglio con i modelli Claude. I modelli con capacità inferiori potrebbero non funzionare come previsto." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There appears to be a typographical error: "utiliza" should likely be "utilizza" (in Italian).
| "warning": "Nota: Roo Code utiliza prompt complessi e funziona meglio con i modelli Claude. I modelli con capacità inferiori potrebbero non funzionare come previsto." | |
| "warning": "Nota: Roo Code utilizza prompt complessi e funziona meglio con i modelli Claude. I modelli con capacità inferiori potrebbero non funzionare come previsto." |
Description
This PR fixes an issue where Roo was overriding Ollama's Modelfile setting by forcing from the inferred . This was causing memory allocation problems on budget GPUs when users had specifically configured smaller context windows in their Modelfiles.
Problem
Solution
Changes
Testing
Impact
Fixes #7797
Important
Fixes issue with Ollama's
num_ctxconfiguration by respecting Modelfile settings by default and allowing explicit overrides.num_ctxfrom default chat options innative-ollama.ts.ollamaNumCtxparameter toApiHandlerOptionsinapi.tsfor explicit overrides.native-ollama.tsto includenum_ctxonly when explicitly set.native-ollama.spec.tsto verifynum_ctxbehavior in both streaming and non-streaming modes.ollamaNumCtxinput field inOllama.tsxfor user configuration.numCtxandnumCtxHelpdescriptions in multiple languages.This description was created by
for 0c436e0. You can customize this summary. It will automatically update as commits are pushed.