summaryrefslogtreecommitdiff
path: root/modules/responses/responses.py
blob: f89a1feb0c0a60075e5721640f5adf90985c9d65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from dataclasses import dataclass, field
from typing import List, Dict, Any

@dataclass(frozen=True)
class Response:
    name: str
    sentence_texts: List[str]

@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,
                    sentence_texts=response_dict["sentences"]
                )
                for response_name, response_dict in input_dict["responses"].items()
            },
        )