-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
64 lines (55 loc) · 1.69 KB
/
cli.py
File metadata and controls
64 lines (55 loc) · 1.69 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from pathlib import Path
import json
import typer
from embedding_pipe import build_vector_store
from retrieval_pipe import get_character_info
app = typer.Typer(help="LangChain Mistral character info extractor")
@app.command("compute-embeddings")
def compute_embeddings(
books_dir: str = typer.Option(
"./stories",
"--books-dir",
"-b",
help="Directory containing .txt story files.",
),
db_path: str = typer.Option(
"./db",
"--db-path",
"-d",
help="Directory to load the Chroma vector store.",
),
):
try:
build_vector_store(books_dir, db_path)
typer.echo("[INFO] Vector store built and persisted successfully.")
except FileNotFoundError as e:
typer.echo(f"[ERROR] {e}")
raise typer.Exit(code=1)
except Exception as e:
typer.echo(f"[ERROR] Unexpected error: {e}")
raise typer.Exit(code=1)
@app.command("get-character-info")
def get_character_info_cmd(
name: str = typer.Argument(..., help="Character name to look up."),
db_path: str = typer.Option(
"./db",
"--db-path",
"-d",
help="Directory where the Chroma vector store is persisted.",
),
):
try:
result = get_character_info(name, db_path)
except FileNotFoundError as e:
typer.echo(f"[ERROR] {e}")
raise typer.Exit(code=1)
except Exception as e:
typer.echo(f"[ERROR] Unexpected error: {e}")
raise typer.Exit(code=1)
try:
parsed = json.loads(result)
typer.echo(json.dumps(parsed, indent=2, ensure_ascii=False))
except json.JSONDecodeError:
typer.echo(result)
if __name__ == "__main__":
app()