forked from open-webui/open-webui
fix: error handling
This commit is contained in:
parent
a74d47b6fc
commit
fdb6499bfa
1 changed files with 36 additions and 26 deletions
|
@ -133,6 +133,10 @@
|
||||||
selectedModels = [''];
|
selectedModels = [''];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selectedModels = selectedModels.map((modelId) =>
|
||||||
|
$models.map((m) => m.id).includes(modelId) ? modelId : ''
|
||||||
|
);
|
||||||
|
|
||||||
let _settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
|
let _settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
|
||||||
settings.set({
|
settings.set({
|
||||||
..._settings
|
..._settings
|
||||||
|
@ -151,6 +155,10 @@
|
||||||
const submitPrompt = async (userPrompt, _user = null) => {
|
const submitPrompt = async (userPrompt, _user = null) => {
|
||||||
console.log('submitPrompt', $chatId);
|
console.log('submitPrompt', $chatId);
|
||||||
|
|
||||||
|
selectedModels = selectedModels.map((modelId) =>
|
||||||
|
$models.map((m) => m.id).includes(modelId) ? modelId : ''
|
||||||
|
);
|
||||||
|
|
||||||
if (selectedModels.includes('')) {
|
if (selectedModels.includes('')) {
|
||||||
toast.error('Model not selected');
|
toast.error('Model not selected');
|
||||||
} else if (messages.length != 0 && messages.at(-1).done != true) {
|
} else if (messages.length != 0 && messages.at(-1).done != true) {
|
||||||
|
@ -282,36 +290,38 @@
|
||||||
selectedModels.map(async (modelId) => {
|
selectedModels.map(async (modelId) => {
|
||||||
const model = $models.filter((m) => m.id === modelId).at(0);
|
const model = $models.filter((m) => m.id === modelId).at(0);
|
||||||
|
|
||||||
// Create response message
|
if (model) {
|
||||||
let responseMessageId = uuidv4();
|
// Create response message
|
||||||
let responseMessage = {
|
let responseMessageId = uuidv4();
|
||||||
parentId: parentId,
|
let responseMessage = {
|
||||||
id: responseMessageId,
|
parentId: parentId,
|
||||||
childrenIds: [],
|
id: responseMessageId,
|
||||||
role: 'assistant',
|
childrenIds: [],
|
||||||
content: '',
|
role: 'assistant',
|
||||||
model: model.id,
|
content: '',
|
||||||
timestamp: Math.floor(Date.now() / 1000) // Unix epoch
|
model: model.id,
|
||||||
};
|
timestamp: Math.floor(Date.now() / 1000) // Unix epoch
|
||||||
|
};
|
||||||
|
|
||||||
// Add message to history and Set currentId to messageId
|
// Add message to history and Set currentId to messageId
|
||||||
history.messages[responseMessageId] = responseMessage;
|
history.messages[responseMessageId] = responseMessage;
|
||||||
history.currentId = responseMessageId;
|
history.currentId = responseMessageId;
|
||||||
|
|
||||||
// Append messageId to childrenIds of parent message
|
// Append messageId to childrenIds of parent message
|
||||||
if (parentId !== null) {
|
if (parentId !== null) {
|
||||||
history.messages[parentId].childrenIds = [
|
history.messages[parentId].childrenIds = [
|
||||||
...history.messages[parentId].childrenIds,
|
...history.messages[parentId].childrenIds,
|
||||||
responseMessageId
|
responseMessageId
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model?.external) {
|
if (model?.external) {
|
||||||
await sendPromptOpenAI(model, prompt, responseMessageId, _chatId);
|
await sendPromptOpenAI(model, prompt, responseMessageId, _chatId);
|
||||||
} else if (model) {
|
} else if (model) {
|
||||||
await sendPromptOllama(model, prompt, responseMessageId, _chatId);
|
await sendPromptOllama(model, prompt, responseMessageId, _chatId);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
toast.error(`Model ${model.id} not found`);
|
toast.error(`Model ${modelId} not found`);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue