Spaces:
Running
Running
Merge pull request #24 from The-Obstacle-Is-The-Way/fix/research-report-references-default
Browse files- src/utils/models.py +2 -1
- tests/unit/utils/test_models.py +57 -0
src/utils/models.py
CHANGED
|
@@ -213,7 +213,8 @@ class ResearchReport(BaseModel):
|
|
| 213 |
conclusion: str = Field(description="Overall conclusion")
|
| 214 |
|
| 215 |
references: list[dict[str, str]] = Field(
|
| 216 |
-
|
|
|
|
| 217 |
)
|
| 218 |
|
| 219 |
# Metadata
|
|
|
|
| 213 |
conclusion: str = Field(description="Overall conclusion")
|
| 214 |
|
| 215 |
references: list[dict[str, str]] = Field(
|
| 216 |
+
default_factory=list,
|
| 217 |
+
description="Formatted references with title, authors, source, URL",
|
| 218 |
)
|
| 219 |
|
| 220 |
# Metadata
|
tests/unit/utils/test_models.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Unit tests for data models."""
|
| 2 |
+
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
from src.utils.models import ReportSection, ResearchReport
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
@pytest.mark.unit
|
| 9 |
+
class TestResearchReport:
|
| 10 |
+
"""Tests for ResearchReport model."""
|
| 11 |
+
|
| 12 |
+
def test_references_has_default(self) -> None:
|
| 13 |
+
"""ResearchReport should allow creation without references field.
|
| 14 |
+
|
| 15 |
+
This is critical because LLMs don't always return the references
|
| 16 |
+
field, and we shouldn't fail validation when it's missing.
|
| 17 |
+
"""
|
| 18 |
+
report = ResearchReport(
|
| 19 |
+
title="Test Report",
|
| 20 |
+
executive_summary="A" * 100, # min_length=100
|
| 21 |
+
research_question="Does drug X help condition Y?",
|
| 22 |
+
methodology=ReportSection(title="Methods", content="We searched..."),
|
| 23 |
+
hypotheses_tested=[{"hypothesis": "test", "supported": True}],
|
| 24 |
+
mechanistic_findings=ReportSection(title="Mechanisms", content="Found..."),
|
| 25 |
+
clinical_findings=ReportSection(title="Clinical", content="Trials show..."),
|
| 26 |
+
drug_candidates=["Drug A"],
|
| 27 |
+
limitations=["Small sample"],
|
| 28 |
+
conclusion="Promising results.",
|
| 29 |
+
sources_searched=["pubmed"],
|
| 30 |
+
total_papers_reviewed=10,
|
| 31 |
+
search_iterations=2,
|
| 32 |
+
confidence_score=0.8,
|
| 33 |
+
# NOTE: references intentionally omitted
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
# Should have empty list as default
|
| 37 |
+
assert report.references == []
|
| 38 |
+
|
| 39 |
+
def test_references_can_be_provided(self) -> None:
|
| 40 |
+
"""ResearchReport should accept references when provided."""
|
| 41 |
+
refs = [{"title": "Paper 1", "url": "https://example.com"}]
|
| 42 |
+
report = ResearchReport(
|
| 43 |
+
title="Test Report",
|
| 44 |
+
executive_summary="A" * 100,
|
| 45 |
+
research_question="Does drug X help condition Y?",
|
| 46 |
+
methodology=ReportSection(title="Methods", content="We searched..."),
|
| 47 |
+
hypotheses_tested=[],
|
| 48 |
+
mechanistic_findings=ReportSection(title="Mechanisms", content="Found..."),
|
| 49 |
+
clinical_findings=ReportSection(title="Clinical", content="Trials show..."),
|
| 50 |
+
drug_candidates=[],
|
| 51 |
+
limitations=[],
|
| 52 |
+
conclusion="Results.",
|
| 53 |
+
confidence_score=0.5,
|
| 54 |
+
references=refs,
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
assert report.references == refs
|