mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-15 04:18:18 +00:00
refac
This commit is contained in:
parent
3b2b89205e
commit
8ea808850d
2 changed files with 48 additions and 3 deletions
|
|
@ -856,7 +856,7 @@ export const generateTitle = async (
|
|||
export const generateTags = async (
|
||||
token: string = '',
|
||||
model: string,
|
||||
messages: string,
|
||||
messages: object[],
|
||||
chat_id?: string
|
||||
) => {
|
||||
let error = null;
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@
|
|||
} from './Messages/structuredOutput';
|
||||
|
||||
import {
|
||||
addTagById,
|
||||
archiveChatById,
|
||||
compactChatById,
|
||||
createNewChat,
|
||||
|
|
@ -102,6 +103,8 @@
|
|||
updateUserSettings
|
||||
} from '$lib/apis/users';
|
||||
import {
|
||||
generateTitle,
|
||||
generateTags,
|
||||
generateQueries,
|
||||
chatAction,
|
||||
generateMoACompletion,
|
||||
|
|
@ -2226,6 +2229,40 @@
|
|||
const visibleMessageText = (message: any) =>
|
||||
getOutputText(message?.output) || removeAllDetails(message?.content ?? '');
|
||||
|
||||
const generateVoiceChatMetadata = async (
|
||||
_chatId: string,
|
||||
modelId: string,
|
||||
content: string,
|
||||
initialTitle: string
|
||||
) => {
|
||||
const token = localStorage.token;
|
||||
const messages = [{ role: 'user', content }];
|
||||
const autoTitle = $settings?.title?.auto ?? true;
|
||||
const autoTags = $settings?.autoTags ?? true;
|
||||
const title = autoTitle
|
||||
? await generateTitle(token, modelId, messages, _chatId).catch((error) => {
|
||||
console.error('Could not generate voice chat title', error);
|
||||
return null;
|
||||
})
|
||||
: null;
|
||||
const savedChat = await getChatById(token, _chatId);
|
||||
if (savedChat.title === initialTitle) {
|
||||
const updated = await updateChatById(token, _chatId, {
|
||||
title: title || content.slice(0, 100)
|
||||
});
|
||||
if ($chatId === _chatId) {
|
||||
chatTitle.set(updated.title);
|
||||
if (embedded) await onEmbeddedChatTitle?.(_chatId, updated.title);
|
||||
}
|
||||
await refreshChatList(token);
|
||||
}
|
||||
if (autoTags) {
|
||||
const tags = await generateTags(token, modelId, messages, _chatId);
|
||||
for (const tag of tags) await addTagById(token, _chatId, tag);
|
||||
allTags.set(await getAllTags(token));
|
||||
}
|
||||
};
|
||||
|
||||
const addVoiceMessage = async (
|
||||
role: string,
|
||||
content: string,
|
||||
|
|
@ -2270,8 +2307,16 @@
|
|||
}
|
||||
if (history.currentId === parentId) history.currentId = id;
|
||||
history = history;
|
||||
if (!$chatId) await initChatHandler(history);
|
||||
else if (!$temporaryChatEnabled) {
|
||||
if (!$chatId) {
|
||||
const modelId = selectedModelIds[0];
|
||||
const _chatId = await initChatHandler(history);
|
||||
if (!$temporaryChatEnabled) {
|
||||
// Realtime replies need no chat completion; start metadata work at chat creation.
|
||||
void generateVoiceChatMetadata(_chatId, modelId, content, chat.title).catch((error) => {
|
||||
console.error('Could not save voice chat metadata', error);
|
||||
});
|
||||
}
|
||||
} else if (!$temporaryChatEnabled) {
|
||||
// Patch only the new message, so a running backend turn keeps its current output.
|
||||
await updateChatById(localStorage.token, $chatId, {
|
||||
history: { currentId: history.currentId, messages: changedMessages }
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue