From dfd1f19bf91b8fd49893fd4772b5aec595afa02f Mon Sep 17 00:00:00 2001 From: Jeroen Schweitzer Date: Tue, 23 Dec 2025 17:21:18 +0100 Subject: [PATCH] feat: add temperature parameter to Ollama generate_text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add temperature control for LLM text generation: - temperature=0.0 for deterministic outputs (JSON, rankings) - temperature=0.3-0.5 for controlled creative content - None uses model default (~0.7 for mistral-nemo) Based on llm-findings.md recommendations for improving mistral-nemo output consistency. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/clients/ollama_client.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/clients/ollama_client.py b/src/clients/ollama_client.py index b5169aa..aaa4457 100644 --- a/src/clients/ollama_client.py +++ b/src/clients/ollama_client.py @@ -249,7 +249,8 @@ class OllamaClient: self, prompt: str, model: Optional[str] = None, - stream: bool = False + stream: bool = False, + temperature: Optional[float] = None ) -> Optional[str]: """ Generate text completion (for non-embedding use cases). @@ -258,12 +259,15 @@ class OllamaClient: prompt: Input prompt model: Model name (defaults to self.model) stream: Enable streaming response + temperature: Sampling temperature (0.0 = deterministic, higher = more creative) + None uses model default (~0.7 for mistral-nemo) Returns: Generated text or None on failure - Note: This is primarily for debugging/testing. Use specialized - LLM services for production text generation. + Note: Use temperature=0.0 for deterministic outputs like JSON parsing, + ranking, and factual extraction. Use higher values (0.3-0.7) for + creative content generation. """ try: payload = { @@ -272,6 +276,10 @@ class OllamaClient: "stream": stream } + # Add temperature to options if specified + if temperature is not None: + payload["options"] = {"temperature": temperature} + response = await self.client.post( self.generate_url, json=payload