diff --git a/AGENT.md b/AGENT.md index 6575f18..1486498 100644 --- a/AGENT.md +++ b/AGENT.md @@ -60,7 +60,8 @@ implausibly - is `12_adaptive_preprocess_ocr.sh` below. steps are short-lived and stateless (one `docker run` per receipt). `3_extract_data.sh` reaches it via `--network host` at `http://127.0.0.1:11434` by default (override with `OLLAMA_URL`/ - `OLLAMA_MODEL`). + `OLLAMA_MODEL`; `OLLAMA_NUM_CTX` (default 3072) and `OLLAMA_NUM_THREAD` + (default: Ollama's) set the request options). - `build-image.sh` / `upload-image.sh` - build/push the `tooling-container/` image, tagged from `tooling-container/VERSION`. Image name defaults to `fuelish/tools`, overridable via diff --git a/tooling-container/VERSION b/tooling-container/VERSION index 6e8bf73..17e51c3 100644 --- a/tooling-container/VERSION +++ b/tooling-container/VERSION @@ -1 +1 @@ -0.1.0 +0.1.1 diff --git a/tooling-container/src/extract.py b/tooling-container/src/extract.py index e63ec48..da3bf6b 100644 --- a/tooling-container/src/extract.py +++ b/tooling-container/src/extract.py @@ -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()