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
dd9cbd0a
Commit
dd9cbd0a
authored
Apr 02, 2024
by
Timothy J. Baek
Browse files
feat: update shared chat
parent
865c2683
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
10 deletions
+23
-10
backend/apps/web/models/chats.py
backend/apps/web/models/chats.py
+19
-1
backend/apps/web/routers/chats.py
backend/apps/web/routers/chats.py
+2
-2
src/lib/components/chat/ShareChatModal.svelte
src/lib/components/chat/ShareChatModal.svelte
+2
-7
No files found.
backend/apps/web/models/chats.py
View file @
dd9cbd0a
...
@@ -98,7 +98,7 @@ class ChatTable:
...
@@ -98,7 +98,7 @@ class ChatTable:
except
:
except
:
return
None
return
None
def
insert_shared_chat
(
self
,
chat_id
:
str
)
->
Optional
[
ChatModel
]:
def
insert_shared_chat
_by_chat_id
(
self
,
chat_id
:
str
)
->
Optional
[
ChatModel
]:
# Get the existing chat to share
# Get the existing chat to share
chat
=
Chat
.
get
(
Chat
.
id
==
chat_id
)
chat
=
Chat
.
get
(
Chat
.
id
==
chat_id
)
# Check if the chat is already shared
# Check if the chat is already shared
...
@@ -122,6 +122,24 @@ class ChatTable:
...
@@ -122,6 +122,24 @@ class ChatTable:
return
shared_chat
if
(
shared_result
and
result
)
else
None
return
shared_chat
if
(
shared_result
and
result
)
else
None
def
update_shared_chat_by_chat_id
(
self
,
chat_id
:
str
)
->
Optional
[
ChatModel
]:
try
:
print
(
"update_shared_chat_by_id"
)
chat
=
Chat
.
get
(
Chat
.
id
==
chat_id
)
print
(
chat
)
query
=
Chat
.
update
(
title
=
chat
.
title
,
chat
=
chat
.
chat
,
).
where
(
Chat
.
id
==
chat
.
share_id
)
query
.
execute
()
chat
=
Chat
.
get
(
Chat
.
id
==
chat
.
share_id
)
return
ChatModel
(
**
model_to_dict
(
chat
))
except
:
return
None
def
delete_shared_chat_by_chat_id
(
self
,
chat_id
:
str
)
->
bool
:
def
delete_shared_chat_by_chat_id
(
self
,
chat_id
:
str
)
->
bool
:
try
:
try
:
query
=
Chat
.
delete
().
where
(
Chat
.
user_id
==
f
"shared-
{
chat_id
}
"
)
query
=
Chat
.
delete
().
where
(
Chat
.
user_id
==
f
"shared-
{
chat_id
}
"
)
...
...
backend/apps/web/routers/chats.py
View file @
dd9cbd0a
...
@@ -199,12 +199,12 @@ async def share_chat_by_id(id: str, user=Depends(get_current_user)):
...
@@ -199,12 +199,12 @@ async def share_chat_by_id(id: str, user=Depends(get_current_user)):
chat
=
Chats
.
get_chat_by_id_and_user_id
(
id
,
user
.
id
)
chat
=
Chats
.
get_chat_by_id_and_user_id
(
id
,
user
.
id
)
if
chat
:
if
chat
:
if
chat
.
share_id
:
if
chat
.
share_id
:
shared_chat
=
Chats
.
get_chat_by_id_and_user_id
(
chat
.
share_id
,
"shared"
)
shared_chat
=
Chats
.
update_shared_chat_by_chat_id
(
chat
.
id
)
return
ChatResponse
(
return
ChatResponse
(
**
{
**
shared_chat
.
model_dump
(),
"chat"
:
json
.
loads
(
shared_chat
.
chat
)}
**
{
**
shared_chat
.
model_dump
(),
"chat"
:
json
.
loads
(
shared_chat
.
chat
)}
)
)
shared_chat
=
Chats
.
insert_shared_chat
(
chat
.
id
)
shared_chat
=
Chats
.
insert_shared_chat
_by_chat_id
(
chat
.
id
)
if
not
shared_chat
:
if
not
shared_chat
:
raise
HTTPException
(
raise
HTTPException
(
status_code
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
,
status_code
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
,
...
...
src/lib/components/chat/ShareChatModal.svelte
View file @
dd9cbd0a
...
@@ -18,13 +18,8 @@
...
@@ -18,13 +18,8 @@
const shareLocalChat = async () => {
const shareLocalChat = async () => {
const _chat = chat;
const _chat = chat;
let chatShareUrl = '';
const sharedChat = await shareChatById(localStorage.token, $chatId);
if (_chat.share_id) {
const chatShareUrl = `${window.location.origin}/s/${sharedChat.id}`;
chatShareUrl = `${window.location.origin}/s/${_chat.share_id}`;
} else {
const sharedChat = await shareChatById(localStorage.token, $chatId);
chatShareUrl = `${window.location.origin}/s/${sharedChat.id}`;
}
toast.success($i18n.t('Copied shared conversation URL to clipboard!'));
toast.success($i18n.t('Copied shared conversation URL to clipboard!'));
copyToClipboard(chatShareUrl);
copyToClipboard(chatShareUrl);
...
...
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