Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
10f27eba
"src/git@developer.sourcefind.cn:gaoqiong/migraphx.git" did not exist on "bcb2c0a41888db9de70b54a163f88884e6d44510"
Commit
10f27eba
authored
Apr 27, 2024
by
Timothy J. Baek
Browse files
refac: naming
parent
7b913ea0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
28 deletions
+37
-28
backend/apps/web/models/chats.py
backend/apps/web/models/chats.py
+14
-18
backend/apps/web/routers/chats.py
backend/apps/web/routers/chats.py
+23
-10
No files found.
backend/apps/web/models/chats.py
View file @
10f27eba
...
...
@@ -191,7 +191,7 @@ class ChatTable:
except
:
return
None
def
get_archived_chat_list
s
_by_user_id
(
def
get_archived_chat_list_by_user_id
(
self
,
user_id
:
str
,
skip
:
int
=
0
,
limit
:
int
=
50
)
->
List
[
ChatModel
]:
return
[
...
...
@@ -204,7 +204,7 @@ class ChatTable:
# .offset(skip)
]
def
get_chat_list
s
_by_user_id
(
def
get_chat_list_by_user_id
(
self
,
user_id
:
str
,
skip
:
int
=
0
,
limit
:
int
=
50
)
->
List
[
ChatModel
]:
return
[
...
...
@@ -217,7 +217,7 @@ class ChatTable:
# .offset(skip)
]
def
get_chat_list
s
_by_chat_ids
(
def
get_chat_list_by_chat_ids
(
self
,
chat_ids
:
List
[
str
],
skip
:
int
=
0
,
limit
:
int
=
50
)
->
List
[
ChatModel
]:
return
[
...
...
@@ -228,20 +228,6 @@ class ChatTable:
.
order_by
(
Chat
.
updated_at
.
desc
())
]
def
get_all_chats
(
self
)
->
List
[
ChatModel
]:
return
[
ChatModel
(
**
model_to_dict
(
chat
))
for
chat
in
Chat
.
select
().
order_by
(
Chat
.
updated_at
.
desc
())
]
def
get_all_chats_by_user_id
(
self
,
user_id
:
str
)
->
List
[
ChatModel
]:
return
[
ChatModel
(
**
model_to_dict
(
chat
))
for
chat
in
Chat
.
select
()
.
where
(
Chat
.
user_id
==
user_id
)
.
order_by
(
Chat
.
updated_at
.
desc
())
]
def
get_chat_by_id
(
self
,
id
:
str
)
->
Optional
[
ChatModel
]:
try
:
chat
=
Chat
.
get
(
Chat
.
id
==
id
)
...
...
@@ -271,7 +257,17 @@ class ChatTable:
def
get_chats
(
self
,
skip
:
int
=
0
,
limit
:
int
=
50
)
->
List
[
ChatModel
]:
return
[
ChatModel
(
**
model_to_dict
(
chat
))
for
chat
in
Chat
.
select
().
limit
(
limit
).
offset
(
skip
)
for
chat
in
Chat
.
select
().
order_by
(
Chat
.
updated_at
.
desc
())
# .limit(limit).offset(skip)
]
def
get_chats_by_user_id
(
self
,
user_id
:
str
)
->
List
[
ChatModel
]:
return
[
ChatModel
(
**
model_to_dict
(
chat
))
for
chat
in
Chat
.
select
()
.
where
(
Chat
.
user_id
==
user_id
)
.
order_by
(
Chat
.
updated_at
.
desc
())
# .limit(limit).offset(skip)
]
def
delete_chat_by_id_and_user_id
(
self
,
id
:
str
,
user_id
:
str
)
->
bool
:
...
...
backend/apps/web/routers/chats.py
View file @
10f27eba
...
...
@@ -36,15 +36,28 @@ log.setLevel(SRC_LOG_LEVELS["MODELS"])
router
=
APIRouter
()
############################
# GetChat
s
# GetChat
List
############################
@
router
.
get
(
"/"
,
response_model
=
List
[
ChatTitleIdResponse
])
async
def
get_user_chats
(
@
router
.
get
(
"/list"
,
response_model
=
List
[
ChatTitleIdResponse
])
async
def
get_session_user_chat_list
(
user
=
Depends
(
get_current_user
),
skip
:
int
=
0
,
limit
:
int
=
50
):
return
Chats
.
get_chat_lists_by_user_id
(
user
.
id
,
skip
,
limit
)
return
Chats
.
get_chat_list_by_user_id
(
user
.
id
,
skip
,
limit
)
############################
# GetUserChatList
############################
@
router
.
get
(
"/list/user/{user_id}"
,
response_model
=
List
[
ChatTitleIdResponse
])
async
def
get_user_chat_list_by_user_id
(
user_id
:
str
,
user
=
Depends
(
get_admin_user
),
skip
:
int
=
0
,
limit
:
int
=
50
):
return
Chats
.
get_chat_list_by_user_id
(
user_id
,
skip
,
limit
)
############################
...
...
@@ -53,22 +66,22 @@ async def get_user_chats(
@
router
.
get
(
"/archived"
,
response_model
=
List
[
ChatTitleIdResponse
])
async
def
get_archived_user_chat
s
(
async
def
get_archived_
session_
user_chat
_list
(
user
=
Depends
(
get_current_user
),
skip
:
int
=
0
,
limit
:
int
=
50
):
return
Chats
.
get_archived_chat_list
s
_by_user_id
(
user
.
id
,
skip
,
limit
)
return
Chats
.
get_archived_chat_list_by_user_id
(
user
.
id
,
skip
,
limit
)
############################
# Get
All
Chats
# GetChats
############################
@
router
.
get
(
"/all"
,
response_model
=
List
[
ChatResponse
])
async
def
get_
all_
user_chats
(
user
=
Depends
(
get_current_user
)):
async
def
get_user_chats
(
user
=
Depends
(
get_current_user
)):
return
[
ChatResponse
(
**
{
**
chat
.
model_dump
(),
"chat"
:
json
.
loads
(
chat
.
chat
)})
for
chat
in
Chats
.
get_
all_
chats_by_user_id
(
user
.
id
)
for
chat
in
Chats
.
get_chats_by_user_id
(
user
.
id
)
]
...
...
@@ -86,7 +99,7 @@ async def get_all_user_chats_in_db(user=Depends(get_admin_user)):
)
return
[
ChatResponse
(
**
{
**
chat
.
model_dump
(),
"chat"
:
json
.
loads
(
chat
.
chat
)})
for
chat
in
Chats
.
get_
all_
chats
()
for
chat
in
Chats
.
get_chats
()
]
...
...
@@ -138,7 +151,7 @@ async def get_user_chats_by_tag_name(
for
chat_id_tag
in
Tags
.
get_chat_ids_by_tag_name_and_user_id
(
tag_name
,
user
.
id
)
]
chats
=
Chats
.
get_chat_list
s
_by_chat_ids
(
chat_ids
,
skip
,
limit
)
chats
=
Chats
.
get_chat_list_by_chat_ids
(
chat_ids
,
skip
,
limit
)
if
len
(
chats
)
==
0
:
Tags
.
delete_tag_by_tag_name_and_user_id
(
tag_name
,
user
.
id
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment