mirror of
https://github.com/open-webui/open-webui
synced 2024-11-16 05:24:02 +00:00
add func to get chat list with more specific sql query
This commit is contained in:
parent
63eda0fe42
commit
2b78e613a4
@ -244,6 +244,32 @@ class ChatTable:
|
|||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
return [ChatModel.model_validate(chat) for chat in all_chats]
|
return [ChatModel.model_validate(chat) for chat in all_chats]
|
||||||
|
def get_chat_title_id_list_by_user_id(
|
||||||
|
self,
|
||||||
|
user_id: str,
|
||||||
|
include_archived: bool = False,
|
||||||
|
skip: int = 0,
|
||||||
|
limit: int = 50,
|
||||||
|
) -> List[ChatTitleIdResponse]:
|
||||||
|
with get_db() as db:
|
||||||
|
query = db.query(Chat).filter_by(user_id=user_id)
|
||||||
|
if not include_archived:
|
||||||
|
query = query.filter_by(archived=False)
|
||||||
|
|
||||||
|
all_chats = (
|
||||||
|
query.order_by(Chat.updated_at.desc())
|
||||||
|
# limit cols
|
||||||
|
.with_entities(Chat.id, Chat.title, Chat.updated_at, Chat.created_at)
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
# result has to be destrctured from sqlalchemy `row` and mapped to a dict since the `ChatModel`is not the returned dataclass.
|
||||||
|
return list(map(lambda row: ChatTitleIdResponse.model_validate({
|
||||||
|
"id": row[0],
|
||||||
|
"title": row[1],
|
||||||
|
"updated_at": row[2],
|
||||||
|
"created_at": row[3]
|
||||||
|
}), all_chats))
|
||||||
|
|
||||||
|
|
||||||
def get_chat_list_by_chat_ids(
|
def get_chat_list_by_chat_ids(
|
||||||
self, chat_ids: List[str], skip: int = 0, limit: int = 50
|
self, chat_ids: List[str], skip: int = 0, limit: int = 50
|
||||||
|
Loading…
Reference in New Issue
Block a user