Skip to content

fix: progress logging, Ollama timeout for LLM extraction. Closes #132…#239

Open
utkarshqz wants to merge 2 commits intofireform-core:mainfrom
utkarshqz:fix/progress-logging-and-llm-hardening
Open

fix: progress logging, Ollama timeout for LLM extraction. Closes #132…#239
utkarshqz wants to merge 2 commits intofireform-core:mainfrom
utkarshqz:fix/progress-logging-and-llm-hardening

Conversation

@utkarshqz
Copy link

fix: real-time progress logging and Ollama timeout for LLM extraction

Summary

Adds real-time console progress logging during LLM extraction and a request timeout to prevent indefinite hangs on slow or lower-end hardware.

The console was previously silent between [3] Starting extraction... and the final result — leaving developers unable to tell if the process was working or frozen. This PR fixes that with clear per-field [LOG] output and elapsed time reporting.


Closes / Fixes

Closes #132
Addresses #152


Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

What changed and why

1. 🪵 Real-time progress logging (src/llm.py)

Added [LOG] output immediately before the batch Ollama request so developers can see exactly which fields are being processed and confirm the backend is actively working.

Console output after this PR:

[LOG] Starting batch extraction for 7 field(s)...
[LOG] Queuing field 1/7 -> 'Name/SID'
[LOG] Queuing field 2/7 -> 'Job Title'
[LOG] Queuing field 3/7 -> 'Department'
[LOG] Queuing field 4/7 -> 'Phone Number'
[LOG] Queuing field 5/7 -> 'Email'
[LOG] Queuing field 6/7 -> 'Date'
[LOG] Queuing field 7/7 -> 'Signature'
[LOG] Sending single batch request to Ollama (model: mistral)...
[LOG] Ollama responded in 4.32s
[LOG] Batch extraction successful.

Fallback per-field extraction path also logs progress:

[LOG] Extracting field 1/7 -> 'Name/SID'
[LOG] Extracting field 2/7 -> 'Job Title'
...

 

2. ⏱️ Ollama request timeout (src/llm.py)

Added timeout=30 to requests.post().

Previously, if Ollama was slow or unresponsive, the process would hang indefinitely with no feedback. The 30-second timeout raises a clear requests.exceptions.Timeout which is caught and surfaced as a 503 error to the client — consistent with existing error handling.

This is especially important on lower-end hardware where CPU inference can be slow, as noted in #132.


How to test

# 1. Start Ollama
ollama serve

# 2. Start the API
uvicorn api.main:app --reload

# 3. Open frontend and fill a form
# OR hit the API directly:
curl -X POST http://localhost:8000/forms/fill \
  -H "Content-Type: application/json" \
  -d '{"template_id": 1, "input_text": "John Smith, firefighter..."}'

# 4. Watch the uvicorn console — you should see [LOG] lines appear
#    in real time during extraction

 

Run the test suite:

python -m pytest tests/ -v

Expected: 52 passed


Screenshots / Evidence

Console output during extraction (verified locally):

[LOG] Starting batch extraction for 7 field(s)...
[LOG] Queuing field 1/7 -> 'Name/SID'
[LOG] Queuing field 2/7 -> 'Job Title'
[LOG] Queuing field 3/7 -> 'Department'
[LOG] Queuing field 4/7 -> 'Phone Number'
[LOG] Queuing field 5/7 -> 'Email'
[LOG] Queuing field 6/7 -> 'Date'
[LOG] Queuing field 7/7 -> 'Signature'
[LOG] Sending single batch request to Ollama (model: mistral)...
[LOG] Ollama responded in 4.32s
[LOG] Batch extraction successful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT]: Add real-time console progress logging during LLM extraction

1 participant