Metadata-Version: 2.4
Name: radfact-lite
Version: 0.2.0
Summary: Lightweight text-only RadFact metric with OpenAI and Ollama backends
Author-email: Luca Lumetti <lumetti.luca@gmail.com>
License-Expression: MIT
Project-URL: Repository, https://github.com/LucaLumetti/radfact_lite
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: openai>=1.0.0
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Dynamic: license-file

# radfact-lite

Lightweight, text-only [RadFact](https://github.com/microsoft/RadFact) with OpenAI and Ollama backends.

Parses reports into phrases, optionally removes normal (non-pathological) findings, then scores bidirectional LLM entailment as logical precision / recall / F1.

This library was created for the [ODIN 2026 challenge](https://odin2026.grand-challenge.org/).

## Install

```bash
pip install radfact-lite
```

## Usage

```python
from radfact_lite import ModelConfig, PipelineModels, RadFactLitePipeline, ReportType

cfg = ModelConfig(model="gpt-4o-mini", provider="openai")  # reads OPENAI_API_KEY
models = PipelineModels(parse_model=cfg, entailment_model=cfg, filtering_model=cfg)
pipeline = RadFactLitePipeline(models, report_type=ReportType.TOOTHFAIRY)

aggregate, per_sample = pipeline.compute_radfact(
    candidates_by_id={"id1": "Absence of tooth 4.8. Endosseous implant in position 4.6."},
    references_by_id={"id1": "Endosseous implant in position 4.6, correctly osseointegrated. All other teeth are present."},
    remove_normal_findings=True,
)
print(aggregate.logical_f1)
```

For Ollama: `ModelConfig(model="llama3.1", provider="ollama")` (default base URL `http://localhost:11434/v1`).

Pass pre-parsed phrase lists instead of narrative text with `is_narrative_text=False`.

## Report types

`report_type` selects the prompt set used for parsing, filtering, and entailment:

- `ReportType.GENERAL` (default) — generic medical imaging prompts that work in any medical context.
- `ReportType.TOOTHFAIRY` — maxillofacial CBCT reports (ODIN 2026 / ToothFairy).
- `ReportType.BITE2TEXT` — orthodontic occlusion reports from intraoral scans/photographs (Bite2Text).

## Debugging

Set `RADFACT_LITE_DEBUG=1` to log every LLM call (report parsing, finding filtering, entailment) to stderr, including inputs, outputs, and pipeline stage markers.

## New modalities

Add prompt files (`system_message.txt` and `few_shot_examples.json`) under `src/prompts/{report_to_phrases,finding_filter,entailment}/<modality>/` and a value to `ReportType` in `src/rf_types.py`.
