diff options
author | Botond Hende <nettingman@gmail.com> | 2024-11-27 22:52:45 +0100 |
---|---|---|
committer | Botond Hende <nettingman@gmail.com> | 2024-11-27 22:52:45 +0100 |
commit | 744961a1538fbb0d821c5d2a332d65fd8c6b1290 (patch) | |
tree | c64cd50642aea8d91f366cad3b2811ba5d6fada9 /modules/responses/responses.py | |
parent | 9a79c535edb655ca490c2b231aad2466951caf7f (diff) |
responses basic datastructure and deserialization
Diffstat (limited to 'modules/responses/responses.py')
-rw-r--r-- | modules/responses/responses.py | 37 |
1 files changed, 37 insertions, 0 deletions
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 |