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: # - "" 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() }, )