-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.py
76 lines (65 loc) · 1.88 KB
/
response.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from dataclasses import dataclass
@dataclass
class Prediction:
label: str
score: float
def to_json(self):
return {"label": self.label, "score": self.score}
@dataclass
class PredictionResponse:
intents: list[Prediction]
def to_json(self):
return {"intents": [intent.to_json() for intent in self.intents]}
@dataclass
class ErrorResponse:
label: str
message: str
def to_json(self):
return {"label": self.label, "message": self.message}
swagger_specs_dict = {
"parameters": [
{
"name": "text",
"in": "body",
"description": "The text to predict the intent for",
"required": True,
"schema": {"type": "object", "properties": {"text": {"type": "string"}}},
}
],
"definitions": {
"Prediction": {
"type": "object",
"properties": {
"label": {"type": "string"},
"score": {"type": "number", "format": "float"},
},
},
"PredictionResponse": {
"type": "object",
"properties": {
"intents": {
"type": "array",
"items": {"$ref": "#/definitions/Prediction"},
}
},
},
"ErrorResponse": {
"type": "object",
"properties": {"label": {"type": "string"}, "message": {"type": "string"}},
},
},
"responses": {
"200": {
"description": "Successful prediction",
"schema": {"$ref": "#/definitions/PredictionResponse"},
},
"400": {
"description": "Bad request",
"schema": {"$ref": "#/definitions/ErrorResponse"},
},
"500": {
"description": "Internal server error",
"schema": {"$ref": "#/definitions/ErrorResponse"},
},
},
}