feat: add us-cpa question engine
This commit is contained in:
@@ -7,6 +7,7 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from us_cpa.cases import CaseConflictError, CaseManager
|
||||
from us_cpa.questions import QuestionEngine, render_analysis, render_memo
|
||||
from us_cpa.sources import TaxYearCorpus, bootstrap_irs_catalog
|
||||
|
||||
COMMANDS = (
|
||||
@@ -64,6 +65,7 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
question = subparsers.add_parser("question", help="Answer a tax question.")
|
||||
_add_common_arguments(question)
|
||||
question.add_argument("--question", required=True)
|
||||
question.add_argument("--style", choices=("conversation", "memo"), default="conversation")
|
||||
|
||||
prepare = subparsers.add_parser("prepare", help="Prepare a return case.")
|
||||
_add_common_arguments(prepare)
|
||||
@@ -104,14 +106,37 @@ def main(argv: list[str] | None = None) -> int:
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
if args.command == "question":
|
||||
corpus = TaxYearCorpus()
|
||||
engine = QuestionEngine(corpus=corpus)
|
||||
case_facts: dict[str, Any] = {}
|
||||
if args.case_dir:
|
||||
manager = CaseManager(Path(args.case_dir))
|
||||
if manager.facts_path.exists():
|
||||
case_facts = {
|
||||
key: value["value"]
|
||||
for key, value in json.loads(manager.facts_path.read_text())["facts"].items()
|
||||
}
|
||||
analysis = engine.answer(
|
||||
question=args.question,
|
||||
tax_year=args.tax_year,
|
||||
case_facts=case_facts,
|
||||
)
|
||||
payload = {
|
||||
"command": "question",
|
||||
"format": args.format,
|
||||
"style": args.style,
|
||||
"taxYear": args.tax_year,
|
||||
"caseDir": args.case_dir,
|
||||
"question": args.question,
|
||||
"status": "not_implemented",
|
||||
"status": "answered",
|
||||
"analysis": analysis,
|
||||
}
|
||||
payload["rendered"] = (
|
||||
render_memo(analysis) if args.style == "memo" else render_analysis(analysis)
|
||||
)
|
||||
if args.format == "markdown":
|
||||
print(payload["rendered"])
|
||||
return 0
|
||||
return _emit(payload, args.format)
|
||||
|
||||
if args.command == "extract-docs":
|
||||
|
||||
Reference in New Issue
Block a user