File size: 1,187 Bytes
54f5afe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""RAGLite CLI."""

import os

import typer

from raglite._config import RAGLiteConfig

cli = typer.Typer()


@cli.callback()
def main() -> None:
    """RAGLite CLI."""


@cli.command()
def chainlit(
    db_url: str = typer.Option(RAGLiteConfig().db_url, help="Database URL"),
    llm: str = typer.Option(RAGLiteConfig().llm, help="LiteLLM LLM"),
    embedder: str = typer.Option(RAGLiteConfig().embedder, help="LiteLLM embedder"),
) -> None:
    """Serve a Chainlit frontend."""
    # Set the environment variables for the Chainlit frontend.
    os.environ["RAGLITE_DB_URL"] = os.environ.get("RAGLITE_DB_URL", db_url)
    os.environ["RAGLITE_LLM"] = os.environ.get("RAGLITE_LLM", llm)
    os.environ["RAGLITE_EMBEDDER"] = os.environ.get("RAGLITE_EMBEDDER", embedder)
    # Import Chainlit here as it's an optional dependency.
    try:
        from chainlit.cli import run_chainlit
    except ImportError as error:
        error_message = "To serve a Chainlit frontend, please install the `chainlit` extra."
        raise ImportError(error_message) from error
    # Serve the frontend.
    run_chainlit(__file__.replace("_cli.py", "_chainlit.py"))


if __name__ == "__main__":
    cli()