{#if autoScroll === false && messages.length > 0}
{ autoScroll = true; scrollToBottom(); }} >
{/if}
{#if atSelectedModel !== undefined}
model.id === atSelectedModel.id)?.info?.meta ?.profile_image_url ?? ($i18n.language === 'dg-DG' ? `/doge.png` : `${WEBUI_BASE_URL}/static/favicon.png`)} />
Talking to
{atSelectedModel.name}
{ atSelectedModel = undefined; }} >
{/if}
{ const data = e.detail; if (data?.type === 'model') { atSelectedModel = data.data; } chatTextAreaElement?.focus(); }} />
{ if (inputFiles && inputFiles.length > 0) { const _inputFiles = Array.from(inputFiles); inputFilesHandler(_inputFiles); } else { toast.error($i18n.t(`File not found.`)); } filesInputElement.value = ''; }} /> {#if recording}
{ recording = false; await tick(); document.getElementById('chat-textarea')?.focus(); }} on:confirm={async (e) => { const response = e.detail; prompt = `${prompt}${response} `; recording = false; await tick(); document.getElementById('chat-textarea')?.focus(); if ($settings?.speechAutoSend ?? false) { submitPrompt(prompt); } }} /> {:else}
{ // check if selectedModels support image input submitPrompt(prompt); }} >
{#if files.length > 0}
{#each files as file, fileIdx} {#if file.type === 'image'}
{#if atSelectedModel ? visionCapableModels.length === 0 : selectedModels.length !== visionCapableModels.length}
!visionCapableModels.includes(id)) .join(', ') })} >
{/if}
{ files.splice(fileIdx, 1); files = files; }} >
{:else}
{ files.splice(fileIdx, 1); files = files; }} /> {/if} {/each}
{/if}
{ if (availableToolIds.includes(e.id) || ($_user?.role ?? 'user') === 'admin') { a[e.id] = { name: e.name, description: e.meta.description, enabled: false }; } return a; }, {})} uploadFilesHandler={() => { filesInputElement.click(); }} onClose={async () => { await tick(); chatTextAreaElement?.focus(); }} >
{ if ( !$mobile || !( 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0 ) ) { // Prevent Enter key from creating a new line if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); } // Submit the prompt when Enter key is pressed if (prompt !== '' && e.key === 'Enter' && !e.shiftKey) { submitPrompt(prompt); } } }} on:keydown={async (e) => { const isCtrlPressed = e.ctrlKey || e.metaKey; // metaKey is for Cmd key on Mac const commandsContainerElement = document.getElementById('commands-container'); // Check if Ctrl + R is pressed if (prompt === '' && isCtrlPressed && e.key.toLowerCase() === 'r') { e.preventDefault(); console.log('regenerate'); const regenerateButton = [ ...document.getElementsByClassName('regenerate-response-button') ]?.at(-1); regenerateButton?.click(); } if (prompt === '' && e.key == 'ArrowUp') { e.preventDefault(); const userMessageElement = [ ...document.getElementsByClassName('user-message') ]?.at(-1); const editButton = [ ...document.getElementsByClassName('edit-user-message-button') ]?.at(-1); console.log(userMessageElement); userMessageElement.scrollIntoView({ block: 'center' }); editButton?.click(); } if (commandsContainerElement && e.key === 'ArrowUp') { e.preventDefault(); commandsElement.selectUp(); const commandOptionButton = [ ...document.getElementsByClassName('selected-command-option-button') ]?.at(-1); commandOptionButton.scrollIntoView({ block: 'center' }); } if (commandsContainerElement && e.key === 'ArrowDown') { e.preventDefault(); commandsElement.selectDown(); const commandOptionButton = [ ...document.getElementsByClassName('selected-command-option-button') ]?.at(-1); commandOptionButton.scrollIntoView({ block: 'center' }); } if (commandsContainerElement && e.key === 'Enter') { e.preventDefault(); const commandOptionButton = [ ...document.getElementsByClassName('selected-command-option-button') ]?.at(-1); if (e.shiftKey) { prompt = `${prompt}\n`; } else if (commandOptionButton) { commandOptionButton?.click(); } else { document.getElementById('send-message-button')?.click(); } } if (commandsContainerElement && e.key === 'Tab') { e.preventDefault(); const commandOptionButton = [ ...document.getElementsByClassName('selected-command-option-button') ]?.at(-1); commandOptionButton?.click(); } else if (e.key === 'Tab') { const words = findWordIndices(prompt); if (words.length > 0) { const word = words.at(0); const fullPrompt = prompt; prompt = prompt.substring(0, word?.endIndex + 1); await tick(); e.target.scrollTop = e.target.scrollHeight; prompt = fullPrompt; await tick(); e.preventDefault(); e.target.setSelectionRange(word?.startIndex, word.endIndex + 1); } e.target.style.height = ''; e.target.style.height = Math.min(e.target.scrollHeight, 200) + 'px'; } if (e.key === 'Escape') { console.log('Escape'); atSelectedModel = undefined; } }} rows="1" on:input={async (e) => { e.target.style.height = ''; e.target.style.height = Math.min(e.target.scrollHeight, 200) + 'px'; user = null; }} on:focus={async (e) => { e.target.style.height = ''; e.target.style.height = Math.min(e.target.scrollHeight, 200) + 'px'; }} on:paste={async (e) => { const clipboardData = e.clipboardData || window.clipboardData; if (clipboardData && clipboardData.items) { for (const item of clipboardData.items) { if (item.type.indexOf('image') !== -1) { const blob = item.getAsFile(); const reader = new FileReader(); reader.onload = function (e) { files = [ ...files, { type: 'image', url: `${e.target.result}` } ]; }; reader.readAsDataURL(blob); } } } }} />
{#if messages.length == 0 || messages.at(-1).done == true}
{ try { let stream = await navigator.mediaDevices .getUserMedia({ audio: true }) .catch(function (err) { toast.error( $i18n.t( `Permission denied when accessing microphone: {{error}}`, { error: err } ) ); return null; }); if (stream) { recording = true; const tracks = stream.getTracks(); tracks.forEach((track) => track.stop()); } stream = null; } catch { toast.error($i18n.t('Permission denied when accessing microphone')); } }} >
{/if}
{#if messages.length == 0 || messages.at(-1).done == true} {#if prompt === ''}
{ if (selectedModels.length > 1) { toast.error($i18n.t('Select only one model to call')); return; } if ($config.audio.stt.engine === 'web') { toast.error( $i18n.t('Call feature is not supported when using Web STT engine') ); return; } // check if user has access to getUserMedia try { let stream = await navigator.mediaDevices.getUserMedia({ audio: true }); // If the user grants the permission, proceed to show the call overlay if (stream) { const tracks = stream.getTracks(); tracks.forEach((track) => track.stop()); } stream = null; showCallOverlay.set(true); dispatch('call'); } catch (err) { // If the user denies the permission or an error occurs, show an error message toast.error($i18n.t('Permission denied when accessing media devices')); } }} >
{:else}
{/if} {:else}
{ stopResponse(); }} >
{/if}
{/if}
{$i18n.t('LLMs can make mistakes. Verify important information.')}