Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing evidence counted in gather_evidence's response message #809

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions paperqa/agents/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,12 @@ async def gather_evidence(self, question: str, state: EnvironmentState) -> str:

logger.info(f"{self.TOOL_FN_NAME} starting for question {question!r}.")
original_question = state.session.question
l1_all = l1_relevant = l0 = len(state.session.contexts)

try:
# Swap out the question with the more specific question
# TODO: remove this swap, as it prevents us from supporting parallel calls
state.session.question = question
l0 = len(state.session.contexts)

# TODO: refactor answer out of this...
state.session = await state.docs.aget_evidence(
Expand All @@ -244,7 +245,14 @@ async def gather_evidence(self, question: str, state: EnvironmentState) -> str:
f"{self.TOOL_FN_NAME}_aget_evidence"
),
)
l1 = len(state.session.contexts)
l1_all = len(state.session.contexts)
l1_relevant = len(
[
c
for c in state.session.contexts
if c.score > state.RELEVANT_SCORE_CUTOFF
]
)
finally:
state.session.question = original_question

Expand Down Expand Up @@ -275,7 +283,10 @@ async def gather_evidence(self, question: str, state: EnvironmentState) -> str:
)
)

return f"Added {l1 - l0} pieces of evidence.{best_evidence}\n\n" + status
return (
f"Added {l1_all - l0} pieces of evidence, {l1_relevant - l0} of which were"
f" relevant.{best_evidence}\n\n" + status
)


class GenerateAnswer(NamedTool):
Expand Down
Loading