Skip to content

Commit 9e2d26d

Browse files
authored
Fixing empty file_location when manifest_file is unset (#1174)
1 parent 470c9fb commit 9e2d26d

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/paperqa/agents/search.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,9 @@ async def process_file(
523523
path=abs_file_path,
524524
fields=["title", "author", "journal", "year"],
525525
settings=settings,
526+
# NOTE if file_location is None in the manifest,
527+
# we want to preserve that
528+
file_location=kwargs.pop("file_location", file_location),
526529
**kwargs,
527530
)
528531
except Exception as e:

src/paperqa/types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,9 @@ class DocDetails(Doc):
746746
" hashing the DOI or a stringifying a UUID."
747747
),
748748
)
749-
file_location: str | os.PathLike | None = None
749+
file_location: str | os.PathLike | None = Field(
750+
default=None, description="Path or location ID of the source document file."
751+
)
750752
license: str | None = Field(
751753
default=None,
752754
description=(

tests/test_agents.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
from paperqa.docs import Docs
6161
from paperqa.prompts import CANNOT_ANSWER_PHRASE, CONTEXT_INNER_PROMPT_NOT_DETAILED
6262
from paperqa.settings import AgentSettings, IndexSettings, Settings
63-
from paperqa.types import Context, Doc, PQASession, Text
63+
from paperqa.types import Context, Doc, DocDetails, PQASession, Text
6464
from paperqa.utils import encode_id, extract_thought, get_year, md5sum
6565

6666

@@ -521,15 +521,22 @@ async def test_propagate_options(agent_test_settings: Settings) -> None:
521521
agent_test_settings.prompts.context_inner = CONTEXT_INNER_PROMPT_NOT_DETAILED
522522
agent_test_settings.answer.evidence_skip_summary = True
523523

524+
docs = Docs()
524525
response = await agent_query(
525526
query="What is a self-explanatory model?",
526527
settings=agent_test_settings,
528+
docs=docs,
527529
agent_type=FAKE_AGENT_TYPE,
528530
)
529531
assert response.status == AgentStatus.SUCCESS, "Agent did not succeed"
530532
result = response.session
531533
assert len(result.answer) > 200, "Answer did not return any results"
532534
assert "###" in result.answer, "Answer did not propagate system prompt"
535+
assert docs.docs, "Expected docs to have been added"
536+
assert all(isinstance(d, DocDetails) for d in docs.docs.values())
537+
assert all(
538+
d.file_location for d in docs.docs.values() # type: ignore[union-attr]
539+
), "Expected file location to be populated"
533540
assert len(result.contexts) >= 2, "Test expects a few contexts"
534541
# Subtract 2 to allow tolerance for chunks with leading/trailing whitespace
535542
num_contexts_sufficient_length = sum(

0 commit comments

Comments
 (0)