-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathschemas.py
More file actions
51 lines (31 loc) · 1.26 KB
/
schemas.py
File metadata and controls
51 lines (31 loc) · 1.26 KB
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
"""
This file contains the Pydantic schemas that define what our API endpoints expect and return.
The schemas are used to validate the data in requests to the API and responses from it, and to generate documentation.
"""
from typing import List
from uuid import UUID
from pydantic import BaseModel
class MessageCreate(BaseModel):
"""Pydantic schema that defines the structure for creating a new chat message."""
content: str
role: str
session_id: str
class Message(MessageCreate):
"""Pydantic schema that defines the structure for a chat message fetched from the database."""
id: UUID
owner_id: UUID
class Config:
"""Read data even if it is not a dict, but an ORM model (or any other arbitrary object)."""
from_attributes = True
class ChatCreate(BaseModel):
"""Pydantic schema that defines the structure for creating a new chat."""
username: str
messages: List[MessageCreate] = []
session_id: str
class Chat(ChatCreate):
"""Pydantic schema that defines the structure for a chat fetched from the database."""
id: UUID
messages: List[Message] = []
class Config:
"""Read data even if it is not a dict, but an ORM model (or any other arbitrary object)."""
from_attributes = True