mirror of
https://github.com/open-webui/open-webui
synced 2025-01-18 00:30:51 +00:00
refac: sticky new chat selected models behaviour
This commit is contained in:
parent
36712c1597
commit
c92091721b
@ -141,6 +141,21 @@
|
|||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: if (selectedModels) {
|
||||||
|
saveSessionSelectedModels();
|
||||||
|
}
|
||||||
|
|
||||||
|
const saveSessionSelectedModels = () => {
|
||||||
|
if (selectedModels.length === 0 || (selectedModels.length === 1 && selectedModels[0] === '')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (chatIdProp === '') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sessionStorage.selectedModels = JSON.stringify(selectedModels);
|
||||||
|
console.log('saveSessionSelectedModels', selectedModels, sessionStorage.selectedModels);
|
||||||
|
};
|
||||||
|
|
||||||
const showMessage = async (message) => {
|
const showMessage = async (message) => {
|
||||||
const _chatId = JSON.parse(JSON.stringify($chatId));
|
const _chatId = JSON.parse(JSON.stringify($chatId));
|
||||||
let _messageId = JSON.parse(JSON.stringify(message.id));
|
let _messageId = JSON.parse(JSON.stringify(message.id));
|
||||||
@ -300,6 +315,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
|
console.log('mounted');
|
||||||
window.addEventListener('message', onMessageHandler);
|
window.addEventListener('message', onMessageHandler);
|
||||||
$socket?.on('chat-events', chatEventHandler);
|
$socket?.on('chat-events', chatEventHandler);
|
||||||
|
|
||||||
@ -420,6 +436,55 @@
|
|||||||
//////////////////////////
|
//////////////////////////
|
||||||
|
|
||||||
const initNewChat = async () => {
|
const initNewChat = async () => {
|
||||||
|
if (sessionStorage.selectedModels) {
|
||||||
|
selectedModels = JSON.parse(sessionStorage.selectedModels);
|
||||||
|
sessionStorage.removeItem('selectedModels');
|
||||||
|
} else {
|
||||||
|
if ($page.url.searchParams.get('models')) {
|
||||||
|
selectedModels = $page.url.searchParams.get('models')?.split(',');
|
||||||
|
} else if ($page.url.searchParams.get('model')) {
|
||||||
|
const urlModels = $page.url.searchParams.get('model')?.split(',');
|
||||||
|
|
||||||
|
if (urlModels.length === 1) {
|
||||||
|
const m = $models.find((m) => m.id === urlModels[0]);
|
||||||
|
if (!m) {
|
||||||
|
const modelSelectorButton = document.getElementById('model-selector-0-button');
|
||||||
|
if (modelSelectorButton) {
|
||||||
|
modelSelectorButton.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
const modelSelectorInput = document.getElementById('model-search-input');
|
||||||
|
if (modelSelectorInput) {
|
||||||
|
modelSelectorInput.focus();
|
||||||
|
modelSelectorInput.value = urlModels[0];
|
||||||
|
modelSelectorInput.dispatchEvent(new Event('input'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
selectedModels = urlModels;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
selectedModels = urlModels;
|
||||||
|
}
|
||||||
|
} else if ($settings?.models) {
|
||||||
|
selectedModels = $settings?.models;
|
||||||
|
} else if ($config?.default_models) {
|
||||||
|
console.log($config?.default_models.split(',') ?? '');
|
||||||
|
selectedModels = $config?.default_models.split(',');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedModels = selectedModels.filter((modelId) => $models.map((m) => m.id).includes(modelId));
|
||||||
|
if (selectedModels.length === 0 || (selectedModels.length === 1 && selectedModels[0] === '')) {
|
||||||
|
if ($models.length > 0) {
|
||||||
|
selectedModels = [$models[0].id];
|
||||||
|
} else {
|
||||||
|
selectedModels = [''];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(selectedModels);
|
||||||
|
|
||||||
await showControls.set(false);
|
await showControls.set(false);
|
||||||
await showCallOverlay.set(false);
|
await showCallOverlay.set(false);
|
||||||
await showOverview.set(false);
|
await showOverview.set(false);
|
||||||
@ -442,51 +507,6 @@
|
|||||||
chatFiles = [];
|
chatFiles = [];
|
||||||
params = {};
|
params = {};
|
||||||
|
|
||||||
if ($page.url.searchParams.get('models')) {
|
|
||||||
selectedModels = $page.url.searchParams.get('models')?.split(',');
|
|
||||||
} else if ($page.url.searchParams.get('model')) {
|
|
||||||
const urlModels = $page.url.searchParams.get('model')?.split(',');
|
|
||||||
|
|
||||||
if (urlModels.length === 1) {
|
|
||||||
const m = $models.find((m) => m.id === urlModels[0]);
|
|
||||||
if (!m) {
|
|
||||||
const modelSelectorButton = document.getElementById('model-selector-0-button');
|
|
||||||
if (modelSelectorButton) {
|
|
||||||
modelSelectorButton.click();
|
|
||||||
await tick();
|
|
||||||
|
|
||||||
const modelSelectorInput = document.getElementById('model-search-input');
|
|
||||||
if (modelSelectorInput) {
|
|
||||||
modelSelectorInput.focus();
|
|
||||||
modelSelectorInput.value = urlModels[0];
|
|
||||||
modelSelectorInput.dispatchEvent(new Event('input'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
selectedModels = urlModels;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
selectedModels = urlModels;
|
|
||||||
}
|
|
||||||
} else if ($settings?.models) {
|
|
||||||
selectedModels = $settings?.models;
|
|
||||||
} else if ($config?.default_models) {
|
|
||||||
console.log($config?.default_models.split(',') ?? '');
|
|
||||||
selectedModels = $config?.default_models.split(',');
|
|
||||||
}
|
|
||||||
|
|
||||||
selectedModels = selectedModels.filter((modelId) => $models.map((m) => m.id).includes(modelId));
|
|
||||||
|
|
||||||
if (selectedModels.length === 0 || (selectedModels.length === 1 && selectedModels[0] === '')) {
|
|
||||||
if ($models.length > 0) {
|
|
||||||
selectedModels = [$models[0].id];
|
|
||||||
} else {
|
|
||||||
selectedModels = [''];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(selectedModels);
|
|
||||||
|
|
||||||
if ($page.url.searchParams.get('youtube')) {
|
if ($page.url.searchParams.get('youtube')) {
|
||||||
uploadYoutubeTranscription(
|
uploadYoutubeTranscription(
|
||||||
`https://www.youtube.com/watch?v=${$page.url.searchParams.get('youtube')}`
|
`https://www.youtube.com/watch?v=${$page.url.searchParams.get('youtube')}`
|
||||||
|
@ -468,7 +468,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
console.log('ResponseMessage mounted');
|
// console.log('ResponseMessage mounted');
|
||||||
|
|
||||||
await tick();
|
await tick();
|
||||||
});
|
});
|
||||||
|
@ -83,7 +83,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
console.log('UserMessage mounted');
|
// console.log('UserMessage mounted');
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user