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

build_index with defaults #430

Merged
merged 2 commits into from
Sep 17, 2024
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
14 changes: 8 additions & 6 deletions paperqa/agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from rich.console import Console
from rich.logging import RichHandler

from paperqa.settings import Settings
from paperqa.settings import Settings, get_settings
from paperqa.utils import get_loop, pqa_directory, setup_default_logs
from paperqa.version import __version__

Expand Down Expand Up @@ -116,15 +116,17 @@ def search_query(


def build_index(
index_name: str,
directory: str | os.PathLike,
settings: Settings,
index_name: str | None = None,
directory: str | os.PathLike | None = None,
settings: Settings | None = None,
) -> SearchIndex:
"""Build a PaperQA search index, this will also happen automatically upon using `ask`."""
settings = get_settings(settings)
if index_name == "default":
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this check for None too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was letting None be handled by the wrapped function get_directory_index. I can do this better to make it clear

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just pushed a change to DRY it up with get_directory_index

index_name = settings.get_index_name()
index_name = None
configure_cli_logging(verbosity=settings.verbosity)
settings.paper_directory = directory
if directory:
settings.paper_directory = directory
return get_loop().run_until_complete(
get_directory_index(index_name=index_name, settings=settings)
)
Expand Down