blob: 1836deb545234dfeb4b698cd8a236bf9cbaffc26 (
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
30
31
32
33
34
35
36
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()
},
)
|