Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/lib/models/providers/ollama/ollamaLLM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ type OllamaConfig = {
options?: GenerateOptions;
};

const DEFAULT_OLLAMA_NUM_CTX = 32000;
const numCtx = process.env.OLLAMA_NUM_CTX
? parseInt(process.env.OLLAMA_NUM_CTX, 10)
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: OLLAMA_NUM_CTX parsing lacks validation; non-numeric truthy values produce NaN, which is then sent as num_ctx for all Ollama calls.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/lib/models/providers/ollama/ollamaLLM.ts, line 24:

<comment>`OLLAMA_NUM_CTX` parsing lacks validation; non-numeric truthy values produce `NaN`, which is then sent as `num_ctx` for all Ollama calls.</comment>

<file context>
@@ -19,6 +19,11 @@ type OllamaConfig = {
 
+const DEFAULT_OLLAMA_NUM_CTX = 32000;
+const numCtx = process.env.OLLAMA_NUM_CTX
+  ? parseInt(process.env.OLLAMA_NUM_CTX, 10)
+  : DEFAULT_OLLAMA_NUM_CTX;
+
</file context>
Fix with Cubic

: DEFAULT_OLLAMA_NUM_CTX;

const reasoningModels = [
'gpt-oss',
'deepseek-r1',
Expand Down Expand Up @@ -94,7 +99,7 @@ class OllamaLLM extends BaseLLM<OllamaConfig> {
temperature:
input.options?.temperature ?? this.config.options?.temperature ?? 0.7,
num_predict: input.options?.maxTokens ?? this.config.options?.maxTokens,
num_ctx: 32000,
num_ctx: numCtx,
frequency_penalty:
input.options?.frequencyPenalty ??
this.config.options?.frequencyPenalty,
Expand Down Expand Up @@ -148,7 +153,7 @@ class OllamaLLM extends BaseLLM<OllamaConfig> {
top_p: input.options?.topP ?? this.config.options?.topP,
temperature:
input.options?.temperature ?? this.config.options?.temperature ?? 0.7,
num_ctx: 32000,
num_ctx: numCtx,
num_predict: input.options?.maxTokens ?? this.config.options?.maxTokens,
frequency_penalty:
input.options?.frequencyPenalty ??
Expand Down Expand Up @@ -195,6 +200,7 @@ class OllamaLLM extends BaseLLM<OllamaConfig> {
top_p: input.options?.topP ?? this.config.options?.topP,
temperature:
input.options?.temperature ?? this.config.options?.temperature ?? 0.7,
num_ctx: numCtx,
num_predict: input.options?.maxTokens ?? this.config.options?.maxTokens,
frequency_penalty:
input.options?.frequencyPenalty ??
Expand Down Expand Up @@ -235,6 +241,7 @@ class OllamaLLM extends BaseLLM<OllamaConfig> {
top_p: input.options?.topP ?? this.config.options?.topP,
temperature:
input.options?.temperature ?? this.config.options?.temperature ?? 0.7,
num_ctx: numCtx,
num_predict: input.options?.maxTokens ?? this.config.options?.maxTokens,
frequency_penalty:
input.options?.frequencyPenalty ??
Expand Down