feat: complete pre-ai local completion v3
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"""Review-only group/NCM/product questionnaire CLI; it never imports context."""
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from central.app.ai.questionnaire import build_questionnaire, group_questions, render_csv, render_json, validate_answers
|
||||
from scripts.answer_company_context import _load
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--questions", default="docs/LOCAL_FISCAL_CONTEXT_QUESTIONS_V2.json")
|
||||
parser.add_argument("--answers")
|
||||
parser.add_argument("--output", default="docs/OPERATOR_GROUP_ANSWERS_V3.json")
|
||||
parser.add_argument("--format", choices=("json", "csv"), default="json")
|
||||
parser.add_argument("--confirm", action="store_true")
|
||||
args = parser.parse_args(argv)
|
||||
questions = build_questionnaire([q for q in _load(args.questions) if str(q.get("CATEGORY", "")).upper() != "C"])
|
||||
groups = group_questions(questions)
|
||||
if args.answers:
|
||||
answers = json.loads(Path(args.answers).read_text(encoding="utf-8"))
|
||||
else:
|
||||
answers = {}
|
||||
for group in groups:
|
||||
print(f"\nEMPRESA: {group['database']}\nGRUPO: {group['group'] or group['scope_key']}\nPRODUTOS AFETADOS: {group['affected']['products']}\nCÉLULAS AFETADAS: {group['affected']['cells']}\nEXEMPLOS: {'; '.join(group['examples'])}\nPERGUNTA: {group['question']}\nOPÇÕES: {', '.join(group['options'])}")
|
||||
value = input("RESPOSTA (ou CANCELAR): ").strip()
|
||||
if value.upper() == "CANCELAR":
|
||||
print("cancelado; nada foi persistido")
|
||||
return 0
|
||||
for question_id in group["question_ids"]:
|
||||
answers[question_id] = value
|
||||
result = validate_answers(questions, answers)
|
||||
print(json.dumps({"questions": len(questions), "groups": len(groups), "entries": len(result["entries"])}, ensure_ascii=False))
|
||||
if not args.confirm:
|
||||
print("review only; nothing was persisted")
|
||||
return 0
|
||||
Path(args.output).write_text(render_csv(result) if args.format == "csv" else render_json(result), encoding="utf-8")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user