summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/config.py18
-rw-r--r--modules/responses/__init__.py0
-rw-r--r--modules/responses/responses.py37
3 files changed, 50 insertions, 5 deletions
diff --git a/modules/config.py b/modules/config.py
index 83243a0..b0fc624 100644
--- a/modules/config.py
+++ b/modules/config.py
@@ -14,21 +14,29 @@ class Config:
self.input_mode = ""
self.intents_dir = ""
+ self.responses_dir = ""
self.applications_dir = ""
self.lock = ""
- def update(self, **entries):
+ def update(self, **entries) -> None:
self.__dict__.update(entries)
- if not self.intents_dir.startswith("/"):
- self.intents_dir = os.path.join(os.path.dirname(__main__.__file__), self.intents_dir)
+ self.intents_dir = Config.__convert_to_absolute_path(self.intents_dir)
+ self.responses_dir = Config.__convert_to_absolute_path(self.responses_dir)
- def validate(self):
+ @staticmethod
+ def __convert_to_absolute_path(path: str) -> str:
+ if not path.startswith("/"):
+ path = os.path.join(os.path.dirname(__main__.__file__), path)
+
+ return path
+
+ def validate(self) -> None:
if self.input_mode not in self.INPUT_MODES:
sys.exit(f"Invalid input_mode '{self.input_mode}', valid options: {", ".join(self.INPUT_MODES)}")
-def load_config():
+def load_config() -> Config:
config = Config()
with open(os.path.join(os.path.dirname(__main__.__file__), "config.yaml")) as stream:
config.update(**yaml.safe_load(stream))
diff --git a/modules/responses/__init__.py b/modules/responses/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/modules/responses/__init__.py
diff --git a/modules/responses/responses.py b/modules/responses/responses.py
new file mode 100644
index 0000000..1836deb
--- /dev/null
+++ b/modules/responses/responses.py
@@ -0,0 +1,37 @@
+from dataclasses import dataclass, field
+from typing import List, Dict, Any
+
+@dataclass(frozen=True)
+class ResponseData:
+ sentence_texts: List[str]
+
+@dataclass(frozen=True)
+class Response:
+ name: str
+ data: List[ResponseData] = field(default_factory=list)
+
+@dataclass(frozen=True)
+class Responses:
+ responses: Dict[str, Response]
+
+ @staticmethod
+ def from_dict(input_dict: Dict[str, Any]) -> "Responses":
+ # responses:
+ # ResponseName:
+ # data:
+ # - sentences:
+ # - "<sentence>"
+ return Responses(
+ responses={
+ response_name: Response(
+ name=response_name,
+ data=[
+ ResponseData(
+ sentence_texts=data_dict["sentences"],
+ )
+ for data_dict in response_dict["data"]
+ ],
+ )
+ for response_name, response_dict in input_dict["responses"].items()
+ },
+ ) \ No newline at end of file