forked from ChelseaKR/fare-policy-assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
40 lines (30 loc) · 1.23 KB
/
Copy pathcli.py
File metadata and controls
40 lines (30 loc) · 1.23 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
"""Ask one question from the command line.
uv run python -m assistant.cli "What proof do I need for the veteran fare on MST?"
uv run python -m assistant.cli --offline "..." # mock model, no API key needed
"""
from __future__ import annotations
import argparse
from assistant import config
from assistant.answer import answer_question
from assistant.models import get_model
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("question")
parser.add_argument("--offline", action="store_true", help="use the mock model")
args = parser.parse_args()
cfg = config.Config()
if args.offline:
cfg = config.Config(
models=config.ModelConfig(provider="mock", answer_model="mock", judge_model="mock")
)
model = get_model(cfg.models.provider, cfg.models.answer_model)
result = answer_question(args.question, model=model, cfg=cfg)
print(result.answer)
if result.citations:
print("\nSources:")
for c in result.citations:
print(f" - {c.agency}: {c.title} — {c.url} (fetched {c.fetch_date})")
if result.guard_flags:
print(f"\n[guards: {', '.join(result.guard_flags)}]")
if __name__ == "__main__":
main()