mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-28 21:49:40 +02:00
implement chat/podcast staleness
This commit is contained in:
parent
b02b094a24
commit
aaa6ee22ed
6 changed files with 52 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ from sqlalchemy import (
|
|||
ARRAY,
|
||||
JSON,
|
||||
TIMESTAMP,
|
||||
BigInteger,
|
||||
Boolean,
|
||||
Column,
|
||||
Enum as SQLAlchemyEnum,
|
||||
|
|
@ -157,6 +158,7 @@ class Chat(BaseModel, TimestampMixin):
|
|||
title = Column(String, nullable=False, index=True)
|
||||
initial_connectors = Column(ARRAY(String), nullable=True)
|
||||
messages = Column(JSON, nullable=False)
|
||||
state_version = Column(BigInteger, nullable=False, default=1)
|
||||
|
||||
search_space_id = Column(
|
||||
Integer, ForeignKey("searchspaces.id", ondelete="CASCADE"), nullable=False
|
||||
|
|
@ -203,6 +205,7 @@ class Podcast(BaseModel, TimestampMixin):
|
|||
title = Column(String, nullable=False, index=True)
|
||||
podcast_transcript = Column(JSON, nullable=False, default={})
|
||||
file_location = Column(String(500), nullable=False, default="")
|
||||
chat_state_version = Column(BigInteger, nullable=True)
|
||||
|
||||
search_space_id = Column(
|
||||
Integer, ForeignKey("searchspaces.id", ondelete="CASCADE"), nullable=False
|
||||
|
|
|
|||
|
|
@ -196,6 +196,7 @@ async def read_chats(
|
|||
Chat.initial_connectors,
|
||||
Chat.search_space_id,
|
||||
Chat.created_at,
|
||||
Chat.state_version,
|
||||
)
|
||||
.join(SearchSpace)
|
||||
.filter(SearchSpace.user_id == user.id)
|
||||
|
|
@ -259,6 +260,8 @@ async def update_chat(
|
|||
update_data = chat_update.model_dump(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(db_chat, key, value)
|
||||
# Increment state_version when chat is modified
|
||||
db_chat.state_version = (db_chat.state_version or 0) + 1
|
||||
await session.commit()
|
||||
await session.refresh(db_chat)
|
||||
return db_chat
|
||||
|
|
|
|||
|
|
@ -13,12 +13,14 @@ class ChatBase(BaseModel):
|
|||
initial_connectors: list[str] | None = None
|
||||
messages: list[Any]
|
||||
search_space_id: int
|
||||
state_version: int = 1
|
||||
|
||||
|
||||
class ChatBaseWithoutMessages(BaseModel):
|
||||
type: ChatType
|
||||
title: str
|
||||
search_space_id: int
|
||||
state_version: int = 1
|
||||
|
||||
|
||||
class ClientAttachment(BaseModel):
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ class PodcastBase(BaseModel):
|
|||
podcast_transcript: list[Any]
|
||||
file_location: str = ""
|
||||
search_space_id: int
|
||||
chat_state_version: int | None = None
|
||||
|
||||
|
||||
class PodcastCreate(PodcastBase):
|
||||
|
|
|
|||
|
|
@ -144,6 +144,7 @@ async def generate_chat_podcast(
|
|||
podcast_transcript=serializable_transcript,
|
||||
file_location=result["final_podcast_file_path"],
|
||||
search_space_id=search_space_id,
|
||||
chat_state_version=chat.state_version,
|
||||
)
|
||||
|
||||
# Add to session and commit
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue