From 612ac976ee03ad0a51a50912efbd08d54888af4d Mon Sep 17 00:00:00 2001 From: James Braza Date: Tue, 17 Sep 2024 15:23:14 -0700 Subject: [PATCH 1/2] Allowing one to use build_index with defaults --- paperqa/agents/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/paperqa/agents/__init__.py b/paperqa/agents/__init__.py index 389b4ba7..7f6b6e01 100644 --- a/paperqa/agents/__init__.py +++ b/paperqa/agents/__init__.py @@ -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__ @@ -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": index_name = settings.get_index_name() 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) ) From e43f9743c3704cba31d8888e66a7b1ed0cb7d6f3 Mon Sep 17 00:00:00 2001 From: James Braza Date: Tue, 17 Sep 2024 15:28:31 -0700 Subject: [PATCH 2/2] Falling back on None in build_index, for DRY code with get_directory_index --- paperqa/agents/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paperqa/agents/__init__.py b/paperqa/agents/__init__.py index 7f6b6e01..b6b6f86b 100644 --- a/paperqa/agents/__init__.py +++ b/paperqa/agents/__init__.py @@ -123,7 +123,7 @@ def build_index( """Build a PaperQA search index, this will also happen automatically upon using `ask`.""" settings = get_settings(settings) if index_name == "default": - index_name = settings.get_index_name() + index_name = None configure_cli_logging(verbosity=settings.verbosity) if directory: settings.paper_directory = directory