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

Decomposing Answer.could_not_answer #516

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 1 addition & 4 deletions paperqa/agents/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ async def run_agent(
else:
raise NotImplementedError(f"Didn't yet handle agent type {agent_type}.")

if (
"cannot answer" in answer.answer.lower()
and agent_status != AgentStatus.TRUNCATED
):
if answer.could_not_answer and agent_status != AgentStatus.TRUNCATED:
agent_status = AgentStatus.UNSURE
# stop after, so overall isn't reported as long-running step.
logger.info(
Expand Down
2 changes: 1 addition & 1 deletion paperqa/agents/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ async def gen_answer(self, question: str, state: EnvironmentState) -> str:
embedding_model=self.embedding_model,
)

if "cannot answer" in state.answer.answer.lower():
if state.answer.could_not_answer:
if self.settings.agent.wipe_context_on_answer_failure:
state.answer.contexts = []
state.answer.context = ""
Expand Down
4 changes: 4 additions & 0 deletions paperqa/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ def filter_content_for_user(self) -> None:
for c in self.contexts
]

@property
def could_not_answer(self) -> bool:
return "cannot answer" in self.answer.lower()


class ChunkMetadata(BaseModel):
"""Metadata for chunking algorithm."""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_paperqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ def test_bad_context(stub_data_dir) -> None:
answer = docs.query(
"What do scientist estimate as the planetary composition of Jupyter?"
)
assert "cannot answer" in answer.answer
assert answer.could_not_answer


def test_repeat_keys(stub_data_dir) -> None:
Expand Down
Loading