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

Cleaning up #489's implementation #503

Merged
merged 2 commits into from
Sep 28, 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
18 changes: 11 additions & 7 deletions paperqa/agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@
"LiteLLM": logging.DEBUG, # <-- every single LLM call
}

_PAPERQA_ROOT_LOGGER = logging.getLogger(__name__.split(".", maxsplit=1)[0])
_PAPERQA_PKG_ROOT_LOGGER = logging.getLogger(__name__.split(".", maxsplit=1)[0])
_INITIATED_FROM_CLI = False


def is_running_under_cli() -> bool:
"""Check if the current Python process comes from the CLI."""
return any(isinstance(h, RichHandler) for h in _PAPERQA_ROOT_LOGGER.handlers)
return _INITIATED_FROM_CLI


def set_up_rich_handler() -> RichHandler:
def set_up_rich_handler(install: bool = True) -> RichHandler:
"""Add a RichHandler to the paper-qa "root" logger, and return it."""
rich_handler = RichHandler(
rich_tracebacks=True,
Expand All @@ -71,8 +72,10 @@ def set_up_rich_handler() -> RichHandler:
console=Console(force_terminal=True),
)
rich_handler.setFormatter(logging.Formatter("%(message)s", datefmt="[%X]"))
if not is_running_under_cli():
_PAPERQA_ROOT_LOGGER.addHandler(rich_handler)
if install and not any(
isinstance(h, RichHandler) for h in _PAPERQA_PKG_ROOT_LOGGER.handlers
):
_PAPERQA_PKG_ROOT_LOGGER.addHandler(rich_handler)
return rich_handler


Expand Down Expand Up @@ -166,8 +169,8 @@ def save_settings(


def main() -> None:
parser = argparse.ArgumentParser(description="PaperQA CLI")

parser = argparse.ArgumentParser(description="PaperQA CLI")
parser.add_argument(
"--settings",
"-s",
Expand All @@ -177,7 +180,6 @@ def main() -> None:
" last"
),
)

parser.add_argument(
"--index", "-i", default="default", help="Index name to search or create"
)
Expand All @@ -187,6 +189,7 @@ def main() -> None:
)

subparsers.add_parser("view", help="View the chosen settings")

save_parser = subparsers.add_parser("save", help="View the chosen settings")
save_parser.add_argument(
"location", help="Location for new settings (name or an absolute path)"
Expand Down Expand Up @@ -244,4 +247,5 @@ def main() -> None:


if __name__ == "__main__":
_INITIATED_FROM_CLI = True
main()
2 changes: 2 additions & 0 deletions paperqa/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def valid_parsings(self) -> list[ParsingOptions]:


class ParsingSettings(BaseModel):
"""Settings relevant for parsing and chunking documents."""

chunk_size: int = Field(default=3000, description="Number of characters per chunk")
use_doc_details: bool = Field(
default=True, description="Whether to try to get metadata details for a Doc"
Expand Down