Skip to content

Commit 2276572

Browse files
tbitcsoz-agent
andcommitted
feat: OllamaProvider reads SPECSMITH_OLLAMA_NUM_CTX for context length
Reads SPECSMITH_OLLAMA_NUM_CTX env var (default 4096) and passes it as num_ctx in every native API request. The VS Code extension injects this var automatically based on detected GPU VRAM. Co-Authored-By: Oz <oz-agent@warp.dev>
1 parent e8718ab commit 2276572

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/specsmith/agent/providers/ollama.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from collections.abc import Iterator
1515
from typing import Any
1616

17+
import os
18+
1719
from specsmith.agent.core import (
1820
CompletionResponse,
1921
Message,
@@ -23,7 +25,12 @@
2325

2426

2527
class OllamaProvider:
26-
"""Ollama local LLM provider. Works with llama3.3, qwen2.5, phi4, etc."""
28+
"""Ollama local LLM provider. Works with llama3.3, qwen2.5, phi4, etc.
29+
30+
Context length (num_ctx) is controlled by the SPECSMITH_OLLAMA_NUM_CTX
31+
environment variable. Default 4096; set higher for larger context windows.
32+
The VS Code extension auto-detects GPU VRAM and sets this appropriately.
33+
"""
2734

2835
provider_name = "ollama"
2936

@@ -34,6 +41,8 @@ def __init__(
3441
) -> None:
3542
self.model = model
3643
self._base_url = base_url.rstrip("/")
44+
# Context window size: env var, default 4096
45+
self._num_ctx: int = int(os.environ.get("SPECSMITH_OLLAMA_NUM_CTX", "4096"))
3746

3847
def is_available(self) -> bool:
3948
try:
@@ -60,7 +69,7 @@ def _complete_native(self, messages: list[Message], max_tokens: int) -> Completi
6069
"model": self.model,
6170
"messages": [m.to_dict() for m in messages],
6271
"stream": False,
63-
"options": {"num_predict": max_tokens},
72+
"options": {"num_predict": max_tokens, "num_ctx": self._num_ctx},
6473
}
6574
data = self._post("/api/chat", payload)
6675
content = data.get("message", {}).get("content", "")

0 commit comments

Comments
 (0)