nickmuchi commited on
Commit
1ca8371
1 Parent(s): 7fa9a42

Create schemas.py

Browse files
Files changed (1) hide show
  1. schemas.py +22 -0
schemas.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Schemas for the chat app."""
2
+ from pydantic import BaseModel, validator
3
+
4
+
5
+ class ChatResponse(BaseModel):
6
+ """Chat response schema."""
7
+
8
+ sender: str
9
+ message: str
10
+ type: str
11
+
12
+ @validator("sender")
13
+ def sender_must_be_bot_or_you(cls, v):
14
+ if v not in ["bot", "you"]:
15
+ raise ValueError("sender must be bot or you")
16
+ return v
17
+
18
+ @validator("type")
19
+ def validate_message_type(cls, v):
20
+ if v not in ["start", "stream", "end", "error", "info"]:
21
+ raise ValueError("type must be start, stream or end")
22
+ return v