This commit is contained in:
Timothy Jaeryang Baek 2025-02-03 15:20:27 -08:00
parent db0ff839dd
commit e3214d08b5
2 changed files with 27 additions and 20 deletions

View File

@ -880,13 +880,14 @@ export const getChangelog = async () => {
return res; return res;
}; };
export const getVersionUpdates = async () => { export const getVersionUpdates = async (token: string) => {
let error = null; let error = null;
const res = await fetch(`${WEBUI_BASE_URL}/api/version/updates`, { const res = await fetch(`${WEBUI_BASE_URL}/api/version/updates`, {
method: 'GET', method: 'GET',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
} }
}) })
.then(async (res) => { .then(async (res) => {

View File

@ -827,14 +827,14 @@
} }
}; };
const createMessagesList = (responseMessageId) => { const createMessagesList = (history, responseMessageId) => {
if (responseMessageId === null) { if (responseMessageId === null) {
return []; return [];
} }
const message = history.messages[responseMessageId]; const message = history.messages[responseMessageId];
if (message?.parentId) { if (message?.parentId) {
return [...createMessagesList(message.parentId), message]; return [...createMessagesList(history, message.parentId), message];
} else { } else {
return [message]; return [message];
} }
@ -896,7 +896,7 @@
}; };
const chatActionHandler = async (chatId, actionId, modelId, responseMessageId, event = null) => { const chatActionHandler = async (chatId, actionId, modelId, responseMessageId, event = null) => {
const messages = createMessagesList(responseMessageId); const messages = createMessagesList(history, responseMessageId);
const res = await chatAction(localStorage.token, actionId, { const res = await chatAction(localStorage.token, actionId, {
model: modelId, model: modelId,
@ -965,7 +965,7 @@
const modelId = selectedModels[0]; const modelId = selectedModels[0];
const model = $models.filter((m) => m.id === modelId).at(0); const model = $models.filter((m) => m.id === modelId).at(0);
const messages = createMessagesList(history.currentId); const messages = createMessagesList(history, history.currentId);
const parentMessage = messages.length !== 0 ? messages.at(-1) : null; const parentMessage = messages.length !== 0 ? messages.at(-1) : null;
const userMessageId = uuidv4(); const userMessageId = uuidv4();
@ -1210,7 +1210,12 @@
); );
history.messages[message.id] = message; history.messages[message.id] = message;
await chatCompletedHandler(chatId, message.model, message.id, createMessagesList(message.id)); await chatCompletedHandler(
chatId,
message.model,
message.id,
createMessagesList(history, message.id)
);
} }
console.log(data); console.log(data);
@ -1226,7 +1231,7 @@
const submitPrompt = async (userPrompt, { _raw = false } = {}) => { const submitPrompt = async (userPrompt, { _raw = false } = {}) => {
console.log('submitPrompt', userPrompt, $chatId); console.log('submitPrompt', userPrompt, $chatId);
const messages = createMessagesList(history.currentId); const messages = createMessagesList(history, history.currentId);
const _selectedModels = selectedModels.map((modelId) => const _selectedModels = selectedModels.map((modelId) =>
$models.map((m) => m.id).includes(modelId) ? modelId : '' $models.map((m) => m.id).includes(modelId) ? modelId : ''
); );
@ -1325,7 +1330,7 @@
saveSessionSelectedModels(); saveSessionSelectedModels();
await sendPrompt(userPrompt, userMessageId, { newChat: true }); sendPrompt(userPrompt, userMessageId, { newChat: true });
}; };
const sendPrompt = async ( const sendPrompt = async (
@ -1333,6 +1338,8 @@
parentId: string, parentId: string,
{ modelId = null, modelIdx = null, newChat = false } = {} { modelId = null, modelIdx = null, newChat = false } = {}
) => { ) => {
const _chatId = JSON.parse(JSON.stringify($chatId));
// Create new chat if newChat is true and first user message // Create new chat if newChat is true and first user message
if ( if (
newChat && newChat &&
@ -1341,7 +1348,7 @@
) { ) {
await initChatHandler(); await initChatHandler();
} else { } else {
await saveChatHandler($chatId); await saveChatHandler(_chatId);
} }
// If modelId is provided, use it, else use selected model // If modelId is provided, use it, else use selected model
@ -1390,16 +1397,15 @@
await tick(); await tick();
// Save chat after all messages have been created // Save chat after all messages have been created
await saveChatHandler($chatId); saveChatHandler(_chatId);
const _chatId = JSON.parse(JSON.stringify($chatId));
await Promise.all( await Promise.all(
selectedModelIds.map(async (modelId, _modelIdx) => { selectedModelIds.map(async (modelId, _modelIdx) => {
console.log('modelId', modelId); console.log('modelId', modelId);
const model = $models.filter((m) => m.id === modelId).at(0); const model = $models.filter((m) => m.id === modelId).at(0);
if (model) { if (model) {
const messages = createMessagesList(parentId); const messages = createMessagesList(history, parentId);
// If there are image files, check if model is vision capable // If there are image files, check if model is vision capable
const hasImages = messages.some((message) => const hasImages = messages.some((message) =>
message?.files?.some((file) => file.type === 'image') message?.files?.some((file) => file.type === 'image')
@ -1444,7 +1450,7 @@
const chatEventEmitter = await getChatEventEmitter(model.id, _chatId); const chatEventEmitter = await getChatEventEmitter(model.id, _chatId);
scrollToBottom(); scrollToBottom();
await sendPromptSocket(model, responseMessageId, _chatId); await sendPromptSocket(history, model, responseMessageId, _chatId);
if (chatEventEmitter) clearInterval(chatEventEmitter); if (chatEventEmitter) clearInterval(chatEventEmitter);
} else { } else {
@ -1457,7 +1463,7 @@
chats.set(await getChatList(localStorage.token, $currentChatPage)); chats.set(await getChatList(localStorage.token, $currentChatPage));
}; };
const sendPromptSocket = async (model, responseMessageId, _chatId) => { const sendPromptSocket = async (history, model, responseMessageId, _chatId) => {
const responseMessage = history.messages[responseMessageId]; const responseMessage = history.messages[responseMessageId];
const userMessage = history.messages[responseMessage.parentId]; const userMessage = history.messages[responseMessage.parentId];
@ -1507,7 +1513,7 @@
}` }`
} }
: undefined, : undefined,
...createMessagesList(responseMessageId).map((message) => ({ ...createMessagesList(history, responseMessageId).map((message) => ({
...message, ...message,
content: removeDetailsWithReasoning(message.content) content: removeDetailsWithReasoning(message.content)
})) }))
@ -1742,7 +1748,7 @@
.at(0); .at(0);
if (model) { if (model) {
await sendPromptSocket(model, responseMessage.id, _chatId); await sendPromptSocket(history, model, responseMessage.id, _chatId);
} }
} }
}; };
@ -1803,7 +1809,7 @@
system: $settings.system ?? undefined, system: $settings.system ?? undefined,
params: params, params: params,
history: history, history: history,
messages: createMessagesList(history.currentId), messages: createMessagesList(history, history.currentId),
tags: [], tags: [],
timestamp: Date.now() timestamp: Date.now()
}); });
@ -1825,7 +1831,7 @@
chat = await updateChatById(localStorage.token, _chatId, { chat = await updateChatById(localStorage.token, _chatId, {
models: selectedModels, models: selectedModels,
history: history, history: history,
messages: createMessagesList(history.currentId), messages: createMessagesList(history, history.currentId),
params: params, params: params,
files: chatFiles files: chatFiles
}); });
@ -1933,7 +1939,7 @@
{/if} {/if}
<div class="flex flex-col flex-auto z-10 w-full"> <div class="flex flex-col flex-auto z-10 w-full">
{#if $settings?.landingPageMode === 'chat' || createMessagesList(history.currentId).length > 0} {#if $settings?.landingPageMode === 'chat' || createMessagesList(history, history.currentId).length > 0}
<div <div
class=" pb-2.5 flex flex-col justify-between w-full flex-auto overflow-auto h-0 max-w-full z-10 scrollbar-hidden" class=" pb-2.5 flex flex-col justify-between w-full flex-auto overflow-auto h-0 max-w-full z-10 scrollbar-hidden"
id="messages-container" id="messages-container"