1
- from __future__ import annotations
2
-
3
1
import pathlib
4
2
from datetime import datetime
5
- from typing import Any
3
+ from typing import Any , Optional
6
4
7
5
from sqlalchemy import Column , DateTime , func , JSON , desc
8
6
from sqlalchemy .orm import selectinload
9
- from sqlmodel import SQLModel , Field , create_engine , Session , select , Relationship
7
+ from sqlmodel import Field , Relationship , Session , SQLModel , create_engine , select
10
8
11
9
12
10
class MessageDao (SQLModel , table = True ):
13
11
__tablename__ = "message"
14
12
15
13
id : int = Field (default = None , primary_key = True )
16
- chat_id : int | None = Field (foreign_key = "chat.id" )
17
- chat : ChatDao = Relationship (back_populates = "messages" )
14
+ chat_id : Optional [ int ] = Field (foreign_key = "chat.id" )
15
+ chat : " ChatDao" = Relationship (back_populates = "messages" )
18
16
role : str
19
17
content : str
20
18
timestamp : datetime | None = Field (
@@ -23,7 +21,7 @@ class MessageDao(SQLModel, table=True):
23
21
status : str | None
24
22
end_turn : bool | None
25
23
weight : float | None
26
- meta : dict = Field (sa_column = Column (JSON ), default = {})
24
+ meta : dict [ Any , Any ] = Field (sa_column = Column (JSON ), default = {})
27
25
recipient : str | None
28
26
29
27
@@ -39,7 +37,7 @@ class ChatDao(SQLModel, table=True):
39
37
messages : list [MessageDao ] = Relationship (back_populates = "chat" )
40
38
41
39
@staticmethod
42
- def all () -> list [ChatDao ]:
40
+ def all () -> list [" ChatDao" ]:
43
41
with Session (engine ) as session :
44
42
# Create a subquery that finds the maximum
45
43
# (most recent) timestamp for each chat.
@@ -60,7 +58,7 @@ def all() -> list[ChatDao]:
60
58
return list (results )
61
59
62
60
@staticmethod
63
- def from_id (chat_id : str ) -> ChatDao :
61
+ def from_id (chat_id : str ) -> " ChatDao" :
64
62
with Session (engine ) as session :
65
63
statement = (
66
64
select (ChatDao )
0 commit comments