"""Score a System One request with Drex-Max (text and/or images).""" import argparse import json import sys from pathlib import Path HERE = Path(__file__).resolve().parent sys.path.insert(0, str(HERE / "code")) from drex_max.model import DecisionModel, answer # noqa: E402 EXAMPLE = { "state": {"ticket": "I was charged twice for order A-104. Receipt photo attached."}, "questions": { "team": { "type": "choice", "instructions": "Which team handles this?", "criteria": { "billing": "Charges and refunds", "shipping": "Delivery", "other": None, }, }, "refund": {"type": "noul", "instructions": "Does the customer ask for a refund?"}, }, } def main(): p = argparse.ArgumentParser() p.add_argument("--model", default=str(HERE)) p.add_argument("--request", default=None) p.add_argument("--device", default="cuda") a = p.parse_args() req = json.load(open(a.request)) if a.request else EXAMPLE model = DecisionModel(a.model, device=a.device) images = req.get("images") or [] out = {} for qid, q in req["questions"].items(): row = {"state": req["state"], "question": q} if images: row["images"] = images out[qid] = answer(q, model.predict([row])[0]) print(json.dumps(out, indent=2)) if __name__ == "__main__": main()