File size: 1,316 Bytes
21c55a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f24832a
 
 
 
 
21c55a3
 
 
 
 
 
 
 
 
89a41e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# src/models/session.py

from datetime import datetime

from pydantic import BaseModel, ConfigDict, Field

from src.models.common import BaseMongoModel, PyObjectId


class Message(BaseModel):
	"""A Pydantic sub-model for a single message within a session."""
	# This _id is an integer, not an ObjectId, so we don't use PyObjectId here.
	id: int = Field(..., alias="_id")
	sent_by_user: bool
	content: str
	timestamp: datetime

	# Use a standard config for this sub-model
	model_config = ConfigDict(
		frozen=True,
		from_attributes=True,
		populate_by_name=True
	)

class Session(BaseMongoModel):
	"""A Pydantic model for a chat session, including nested messages."""
	account_id: PyObjectId
	patient_id: PyObjectId
	title: str
	created_at: datetime
	updated_at: datetime
	messages: list[Message] = Field(default_factory=list)

# --- API Request Models ---

class SessionCreateRequest(BaseModel):
	account_id: str
	patient_id: str
	title: str | None = "New Chat"


class ChatRequest(BaseModel):
	"""Request model for sending a message to a session."""
	account_id: str # For context, though session_id implies this
	patient_id: str # For context, though session_id implies this
	message: str

# --- API Response Models ---

class ChatResponse(BaseModel):
	"""Response model for a chat interaction."""
	response: str