From a585d159a5acf03d0d75fc39d74ff5ee24e28b8a Mon Sep 17 00:00:00 2001 From: Botond Hende Date: Wed, 16 Oct 2024 17:32:13 +0200 Subject: name based intent handling --- __main__.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 __main__.py (limited to '__main__.py') diff --git a/__main__.py b/__main__.py new file mode 100644 index 0000000..79d6a23 --- /dev/null +++ b/__main__.py @@ -0,0 +1,47 @@ +import sys +import yaml + +from pathlib import Path +from .modules.hassil.recognize import recognize +from .modules.hassil.util import merge_dict +from .modules.hassil.intents import Intents, TextSlotList + +from .modules.intents import * + + +def main(): + input_dict = {"intents": {}} + + yaml_path = Path(sys.argv[1]) + yaml_file_paths = yaml_path.glob("*.yaml") + + slot_lists = {} + + for yaml_file_path in yaml_file_paths: + with open(yaml_file_path, "r", encoding="utf-8") as yaml_file: + merge_dict(input_dict, yaml.safe_load(yaml_file)) + + intents = Intents.from_dict(input_dict) + + try: + for line in sys.stdin: + line = line.strip() + if not line: + continue + + result = recognize(line, intents, slot_lists=slot_lists) + if result is not None: + result_dict = { + "intent": result.intent.name, + **{e.name: e.value for e in result.entities_list}, + } + print(result_dict) + handler = getattr(globals()[result_dict["domain"]], result_dict["intent"]) + handler(result_dict) + else: + print("") + except KeyboardInterrupt: + pass + +if __name__ == '__main__': + main() \ No newline at end of file -- cgit v1.2.3-70-g09d2