Skip to content

Add unit tests for LLM class methods#186

Open
Gopisokk wants to merge 1 commit intofireform-core:mainfrom
Gopisokk:test/add-llm-unit-tests
Open

Add unit tests for LLM class methods#186
Gopisokk wants to merge 1 commit intofireform-core:mainfrom
Gopisokk:test/add-llm-unit-tests

Conversation

@Gopisokk
Copy link

@Gopisokk Gopisokk commented Mar 4, 2026

Summary

Adds comprehensive unit tests for the LLM class in tests/test_llm.py.

The LLM class is the core AI extraction component of FireForm — it handles
prompting Ollama, parsing responses, and building the JSON used to fill PDFs.
Despite being the most critical module in the pipeline, it had zero test coverage.

Tests Added (17 tests across 4 methods)

build_prompt()

  • Prompt contains the target field name
  • Prompt contains the full transcript text
  • Return type is always str

handle_plural_values()

  • Correctly splits "Engine 12; Engine 14"["Engine 12", "Engine 14"]
  • Raises ValueError when no semicolon present
  • Return type is always list

add_response_to_json()

  • Stores None when LLM returns "-1" (field not found)
  • Stores valid values correctly
  • Strips extra quotes from LLM output
  • Handles plural values with semicolons
  • Creates new fields if they don't exist

main_loop() (mocked Ollama API)

  • Calls Ollama exactly once per field
  • Returns self for method chaining
  • Correctly populates _json from Ollama responses
  • Raises ConnectionError when Ollama is not reachable

How to Run

pytest tests/test_llm.py -v

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.

1 participant