Skip to content

fix: make pgai --help faster #605

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

Merged
merged 1 commit into from
Apr 7, 2025
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
21 changes: 8 additions & 13 deletions projects/pgai/pgai/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,19 @@
from typing import Any

import click
import docling.utils.model_downloader
import structlog
from ddtrace import tracer
from dotenv import load_dotenv
from pytimeparse import parse # type: ignore

import pgai

from .__init__ import __version__
from .vectorizer import Processor
from .vectorizer.parsing import DOCLING_CACHE_DIR

load_dotenv()

structlog.configure(wrapper_class=structlog.make_filtering_bound_logger(logging.INFO))
log = structlog.get_logger()


class VectorizerNotFoundError(Exception):
pass


class ApiKeyNotFoundError(Exception):
pass


def asbool(value: str | None):
"""Convert the given String to a boolean object.

Expand Down Expand Up @@ -97,6 +84,10 @@ def shutdown_handler(signum: int, _frame: Any):

@click.command(name="download-models")
def download_models():
import docling.utils.model_downloader

from .vectorizer.parsing import DOCLING_CACHE_DIR

docling.utils.model_downloader.download_models(
progress=True,
output_dir=DOCLING_CACHE_DIR, # pyright: ignore [reportUndefinedVariable]
Expand Down Expand Up @@ -192,6 +183,8 @@ async def async_run_vectorizer_worker(
concurrency: int | None,
exit_on_error: bool | None,
) -> None:
from .vectorizer import Processor

# gracefully handle being asked to shut down
signal.signal(signal.SIGINT, shutdown_handler)
signal.signal(signal.SIGTERM, shutdown_handler)
Expand Down Expand Up @@ -247,4 +240,6 @@ def cli():
help="If True, raise an error when the extension already exists and is at the latest version.", # noqa: E501
)
def install(db_url: str, strict: bool) -> None:
import pgai

pgai.install(db_url, strict=strict)