Make Ollama context size and threads configurable
build / build (push) Successful in 3m23s

This commit is contained in:
ml
2026-10-04 12:45:54 +02:00
parent 7a91a37049
commit 8980f9599b
3 changed files with 12 additions and 3 deletions
+1 -1
View File
@@ -1 +1 @@
0.1.0
0.1.1
+9 -1
View File
@@ -10,6 +10,11 @@ import requests
OLLAMA_URL = os.environ.get("OLLAMA_URL", "http://127.0.0.1:11434/api/chat")
MODEL = os.environ.get("OLLAMA_MODEL", "qwen2.5:3b")
# Ollama restarts its runner when a request's context size or thread count
# differs from the loaded one; set these to match other clients of a shared
# Ollama. OLLAMA_NUM_THREAD unset = Ollama's default.
NUM_CTX = int(os.environ.get("OLLAMA_NUM_CTX", "3072"))
NUM_THREAD = os.environ.get("OLLAMA_NUM_THREAD")
SCHEMA = {
"type": "object",
@@ -57,6 +62,9 @@ Respond with ONLY the JSON object, no other text.
def structure(ocr_text: str) -> dict:
options = {"temperature": 0, "num_ctx": NUM_CTX}
if NUM_THREAD:
options["num_thread"] = int(NUM_THREAD)
payload = {
"model": MODEL,
"messages": [
@@ -64,7 +72,7 @@ def structure(ocr_text: str) -> dict:
],
"format": SCHEMA,
"stream": False,
"options": {"temperature": 0, "num_ctx": 3072},
"options": options,
}
start = time.time()