feat(sqlalchemy): format backend
This commit is contained in:
@@ -85,9 +85,7 @@ class ChatTable:
|
||||
"id": id,
|
||||
"user_id": user_id,
|
||||
"title": (
|
||||
form_data.chat["title"]
|
||||
if "title" in form_data.chat
|
||||
else "New Chat"
|
||||
form_data.chat["title"] if "title" in form_data.chat else "New Chat"
|
||||
),
|
||||
"chat": json.dumps(form_data.chat),
|
||||
"created_at": int(time.time()),
|
||||
@@ -197,14 +195,14 @@ class ChatTable:
|
||||
def get_archived_chat_list_by_user_id(
|
||||
self, user_id: str, skip: int = 0, limit: int = 50
|
||||
) -> List[ChatModel]:
|
||||
all_chats = (
|
||||
Session.query(Chat)
|
||||
.filter_by(user_id=user_id, archived=True)
|
||||
.order_by(Chat.updated_at.desc())
|
||||
# .limit(limit).offset(skip)
|
||||
.all()
|
||||
)
|
||||
return [ChatModel.model_validate(chat) for chat in all_chats]
|
||||
all_chats = (
|
||||
Session.query(Chat)
|
||||
.filter_by(user_id=user_id, archived=True)
|
||||
.order_by(Chat.updated_at.desc())
|
||||
# .limit(limit).offset(skip)
|
||||
.all()
|
||||
)
|
||||
return [ChatModel.model_validate(chat) for chat in all_chats]
|
||||
|
||||
def get_chat_list_by_user_id(
|
||||
self,
|
||||
|
||||
@@ -115,9 +115,7 @@ class MemoriesTable:
|
||||
except:
|
||||
return False
|
||||
|
||||
def delete_memory_by_id_and_user_id(
|
||||
self, id: str, user_id: str
|
||||
) -> bool:
|
||||
def delete_memory_by_id_and_user_id(self, id: str, user_id: str) -> bool:
|
||||
try:
|
||||
Session.query(Memory).filter_by(id=id, user_id=user_id).delete()
|
||||
return True
|
||||
|
||||
@@ -140,7 +140,9 @@ class ModelsTable:
|
||||
return None
|
||||
|
||||
def get_all_models(self) -> List[ModelModel]:
|
||||
return [ModelModel.model_validate(model) for model in Session.query(Model).all()]
|
||||
return [
|
||||
ModelModel.model_validate(model) for model in Session.query(Model).all()
|
||||
]
|
||||
|
||||
def get_model_by_id(self, id: str) -> Optional[ModelModel]:
|
||||
try:
|
||||
|
||||
@@ -207,9 +207,7 @@ class TagTable:
|
||||
log.debug(f"res: {res}")
|
||||
Session.commit()
|
||||
|
||||
tag_count = self.count_chat_ids_by_tag_name_and_user_id(
|
||||
tag_name, user_id
|
||||
)
|
||||
tag_count = self.count_chat_ids_by_tag_name_and_user_id(tag_name, user_id)
|
||||
if tag_count == 0:
|
||||
# Remove tag item from Tag col as well
|
||||
Session.query(Tag).filter_by(name=tag_name, user_id=user_id).delete()
|
||||
@@ -230,9 +228,7 @@ class TagTable:
|
||||
log.debug(f"res: {res}")
|
||||
Session.commit()
|
||||
|
||||
tag_count = self.count_chat_ids_by_tag_name_and_user_id(
|
||||
tag_name, user_id
|
||||
)
|
||||
tag_count = self.count_chat_ids_by_tag_name_and_user_id(tag_name, user_id)
|
||||
if tag_count == 0:
|
||||
# Remove tag item from Tag col as well
|
||||
Session.query(Tag).filter_by(name=tag_name, user_id=user_id).delete()
|
||||
|
||||
Reference in New Issue
Block a user