mirror of
https://github.com/open-webui/open-webui
synced 2025-05-17 03:54:02 +00:00
enh: chat "clone" i18n
This commit is contained in:
parent
8c7e52e5a1
commit
c021aba094
@ -444,15 +444,21 @@ async def pin_chat_by_id(id: str, user=Depends(get_verified_user)):
|
|||||||
############################
|
############################
|
||||||
|
|
||||||
|
|
||||||
|
class CloneForm(BaseModel):
|
||||||
|
title: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
@router.post("/{id}/clone", response_model=Optional[ChatResponse])
|
@router.post("/{id}/clone", response_model=Optional[ChatResponse])
|
||||||
async def clone_chat_by_id(id: str, user=Depends(get_verified_user)):
|
async def clone_chat_by_id(
|
||||||
|
form_data: CloneForm, id: str, user=Depends(get_verified_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:
|
||||||
updated_chat = {
|
updated_chat = {
|
||||||
**chat.chat,
|
**chat.chat,
|
||||||
"originalChatId": chat.id,
|
"originalChatId": chat.id,
|
||||||
"branchPointMessageId": chat.chat["history"]["currentId"],
|
"branchPointMessageId": chat.chat["history"]["currentId"],
|
||||||
"title": f"Clone of {chat.title}",
|
"title": form_data.title if form_data.title else f"Clone of {chat.title}",
|
||||||
}
|
}
|
||||||
|
|
||||||
chat = Chats.insert_new_chat(user.id, ChatForm(**{"chat": updated_chat}))
|
chat = Chats.insert_new_chat(user.id, ChatForm(**{"chat": updated_chat}))
|
||||||
|
@ -580,7 +580,7 @@ export const toggleChatPinnedStatusById = async (token: string, id: string) => {
|
|||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const cloneChatById = async (token: string, id: string) => {
|
export const cloneChatById = async (token: string, id: string, title?: string) => {
|
||||||
let error = null;
|
let error = null;
|
||||||
|
|
||||||
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/${id}/clone`, {
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/${id}/clone`, {
|
||||||
@ -589,7 +589,10 @@ export const cloneChatById = async (token: string, id: string) => {
|
|||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
...(token && { authorization: `Bearer ${token}` })
|
...(token && { authorization: `Bearer ${token}` })
|
||||||
}
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
...(title && { title: title })
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
if (!res.ok) throw await res.json();
|
if (!res.ok) throw await res.json();
|
||||||
|
@ -87,7 +87,13 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const cloneChatHandler = async (id) => {
|
const cloneChatHandler = async (id) => {
|
||||||
const res = await cloneChatById(localStorage.token, id).catch((error) => {
|
const res = await cloneChatById(
|
||||||
|
localStorage.token,
|
||||||
|
id,
|
||||||
|
$i18n.t('Clone of {{TITLE}}', {
|
||||||
|
TITLE: title
|
||||||
|
})
|
||||||
|
).catch((error) => {
|
||||||
toast.error(`${error}`);
|
toast.error(`${error}`);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user