# pick_tool.py — a free System 1 model picks the tool for a message, on this computer.
#
#   pip install openthai-systemone
#   python pick_tool.py
#
# The first run downloads the model, about 1.5 GB, once. It runs on the CPU.
# The choosing happens here: no message is sent to a service.
from openthai_systemone import Choice, SystemOneClient

# What each helper is for. The model reads these words, so they matter: change
# one and the picks can change. If you do, test again on NEW messages.
HELPERS = {
    "coin_price": "the price of a cryptocurrency coin, like Bitcoin or ETH, in Thai baht",
    "wikipedia": "a fact about a person, place, thing or history, from an encyclopedia",
    "web_search": "news, weather, or anything happening today or recently, found on the web",
    "make_map": "showing where a place is, or a map of a place",
    "make_page": "making or building a new web page or HTML page",
    "chat": "greetings, thanks, small talk, jokes, or help practising or correcting English",
}
MESSAGES = ["ขอดูแผนที่ปาย", "บิตคอยน์ตอนนี้กี่บาท", "Tell me a joke about cats.",
            "ค้นหาร้านกาแฟแถวนิมมาน"]

model = SystemOneClient("iapp/OpenThai-SystemOne", device="cpu")
question = {"tool": Choice(instructions="Which helper should answer this message?",
                           criteria=HELPERS)}

for message in MESSAGES:
    answer = model.system_one(state=message, questions=question).answers["tool"]
    print(f"{message}\n    -> {answer.choice}  ({answer.probabilities[answer.choice]:.2f})")
