fix: prevent truncated Ollama answers
GeoIntel CI / docs-smoke (push) Canceled after 0s
GeoIntel CI / contract-smoke (push) Canceled after 0s

This commit is contained in:
Codex
2026-07-15 07:39:03 +02:00
parent 5be8f628ef
commit 56f823f02a
13 changed files with 89 additions and 4 deletions
+1
View File
@@ -51,6 +51,7 @@ class Settings(BaseSettings):
ollama_default_model: str = Field(default="qwen3.5:9b", validation_alias="OLLAMA_DEFAULT_MODEL")
ollama_timeout_seconds: int = Field(default=120, ge=5, le=600, validation_alias="OLLAMA_TIMEOUT_SECONDS")
ollama_max_output_tokens: int = Field(default=700, ge=100, le=4_000, validation_alias="OLLAMA_MAX_OUTPUT_TOKENS")
ollama_context_tokens: int = Field(default=16_384, ge=4_096, le=131_072, validation_alias="OLLAMA_CONTEXT_TOKENS")
cors_origins: list[str] | str = Field(
default=["http://localhost:5173", "http://127.0.0.1:5173"],
validation_alias="CORS_ORIGINS",
+15 -1
View File
@@ -367,9 +367,23 @@ class GeoAssistantService:
"stream": False,
"think": False,
"keep_alive": "10m",
"options": {"temperature": 0.1, "num_predict": self.settings.ollama_max_output_tokens},
"options": {
"temperature": 0.1,
"num_ctx": self.settings.ollama_context_tokens,
"num_predict": self.settings.ollama_max_output_tokens,
},
},
)
if response.get("done_reason") == "length":
raise AppError(
code="OLLAMA_RESPONSE_TRUNCATED",
message="Ollama kon geen volledig antwoord binnen de ingestelde contextlimiet genereren.",
details={
"context_tokens": self.settings.ollama_context_tokens,
"max_output_tokens": self.settings.ollama_max_output_tokens,
},
status_code=502,
)
message = response.get("message") if isinstance(response.get("message"), dict) else {}
answer = str(message.get("content") or "").strip()
if not answer: