Spaces:
Running
Running
Commit ·
9059e2e
1
Parent(s): d638e5b
Chat Messages send and receive and also load the history
Browse files- app/db/models_chat.py +1 -1
- app/routers/chat_ws.py +2 -2
app/db/models_chat.py
CHANGED
|
@@ -19,7 +19,7 @@ class ChatMessage(Base):
|
|
| 19 |
# user OR assistant
|
| 20 |
role = Column(String(20), nullable=False)
|
| 21 |
|
| 22 |
-
|
| 23 |
|
| 24 |
created_at = Column(
|
| 25 |
DateTime(timezone=True),
|
|
|
|
| 19 |
# user OR assistant
|
| 20 |
role = Column(String(20), nullable=False)
|
| 21 |
|
| 22 |
+
content = Column(Text, nullable=False)
|
| 23 |
|
| 24 |
created_at = Column(
|
| 25 |
DateTime(timezone=True),
|
app/routers/chat_ws.py
CHANGED
|
@@ -500,7 +500,7 @@ def save_chat(db: Session, user_id: int, role: str, message: str):
|
|
| 500 |
chat = ChatMessage(
|
| 501 |
user_id=user_id,
|
| 502 |
role=role,
|
| 503 |
-
|
| 504 |
)
|
| 505 |
|
| 506 |
db.add(chat)
|
|
@@ -524,7 +524,7 @@ def get_chat_history(
|
|
| 524 |
response.append({
|
| 525 |
"id": chat.id,
|
| 526 |
"role": chat.role,
|
| 527 |
-
"message": chat.
|
| 528 |
"created_at": chat.created_at
|
| 529 |
})
|
| 530 |
|
|
|
|
| 500 |
chat = ChatMessage(
|
| 501 |
user_id=user_id,
|
| 502 |
role=role,
|
| 503 |
+
content=message
|
| 504 |
)
|
| 505 |
|
| 506 |
db.add(chat)
|
|
|
|
| 524 |
response.append({
|
| 525 |
"id": chat.id,
|
| 526 |
"role": chat.role,
|
| 527 |
+
"message": chat.content,
|
| 528 |
"created_at": chat.created_at
|
| 529 |
})
|
| 530 |
|