Skip to content

Conversation

mskarlin
Copy link
Collaborator

Users may want custom control over how contexts are generated and munged before inserting into the final answer. This was previously locked into the aquery code, but this exposes it as a configurable function.

We may not be the best, but by god, we'll be the most configurable.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the context string generation logic to make it configurable through a function parameter. Previously, the context generation was hardcoded within the aquery method, but now users can provide custom functions to control how contexts are processed and formatted before being inserted into the final answer.

Key changes:

  • Extracted context string generation logic into a configurable context_str_fn parameter
  • Created a ContextStrFn protocol to define the interface for custom context functions
  • Added a default implementation that preserves the original behavior

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/paperqa/settings.py Adds ContextStrFn protocol and context_str_fn field to AnswerSettings with proper type configuration
src/paperqa/docs.py Refactors aquery method to use configurable context function and extracts original logic to default_context_str_fn
tests/test_paperqa.py Adds test coverage for custom context string function functionality

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 29, 2025
@dosubot dosubot bot added the enhancement New feature or request label Jul 29, 2025
Copy link
Collaborator

@jamesbraza jamesbraza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work overall, thanks for going through the PR comments

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 29, 2025
@mskarlin mskarlin merged commit cbe5d9d into main Aug 5, 2025
7 checks passed
@mskarlin mskarlin deleted the move-context-str-into-custom-fn branch August 5, 2025 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants