{#if loaded}
{#if autoScroll === false && history?.currentId}
{/if}
{#if atSelectedModel !== undefined || selectedToolIds.length > 0 || webSearchEnabled || ($settings?.webSearch ?? false) === 'always' || imageGenerationEnabled || codeInterpreterEnabled}
{#if selectedToolIds.length > 0}
{#each selectedToolIds.map((id) => { return $tools ? $tools.find((t) => t.id === id) : { id: id, name: id }; }) as tool, toolIdx (toolIdx)} {tool.name} {#if toolIdx !== selectedToolIds.length - 1} , {/if} {/each}
{/if} {#if webSearchEnabled || ($config?.features?.enable_web_search && ($settings?.webSearch ?? false)) === 'always'}
{$i18n.t('Search the internet')}
{/if} {#if imageGenerationEnabled}
{$i18n.t('Generate an image')}
{/if} {#if codeInterpreterEnabled}
{$i18n.t('Execute code for analysis')}
{/if} {#if atSelectedModel !== undefined}
model profile 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}
{/if}
{/if} { dispatch('upload', e.detail); }} on:select={(e) => { const data = e.detail; if (data?.type === 'model') { atSelectedModel = data.data; } const chatInputElement = document.getElementById('chat-input'); chatInputElement?.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-input')?.focus(); }} on:confirm={async (e) => { const { text, filename } = e.detail; prompt = `${prompt}${text} `; recording = false; await tick(); document.getElementById('chat-input')?.focus(); if ($settings?.speechAutoSend ?? false) { dispatch('submit', prompt); } }} /> {:else}
{ // check if selectedModels support image input dispatch('submit', prompt); }} >
{#if files.length > 0}
{#each files as file, fileIdx} {#if file.type === 'image'}
input {#if atSelectedModel ? visionCapableModels.length === 0 : selectedModels.length !== visionCapableModels.length} !visionCapableModels.includes(id)) .join(', ') })} > {/if}
{:else} { if (file.type !== 'collection' && !file?.collection) { if (file.id) { // This will handle both file deletion and Chroma cleanup await deleteFileById(localStorage.token, file.id); } } // Remove from UI state files.splice(fileIdx, 1); files = files; }} on:click={() => { console.log(file); }} /> {/if} {/each}
{/if}
{#if $settings?.richTextInput ?? true}
0 || navigator.msMaxTouchPoints > 0 ))} placeholder={placeholder ? placeholder : $i18n.t('Send a Message')} largeTextAsFile={$settings?.largeTextAsFile ?? false} autocomplete={$config?.features.enable_autocomplete_generation} generateAutoCompletion={async (text) => { if (selectedModelIds.length === 0 || !selectedModelIds.at(0)) { toast.error($i18n.t('Please select a model first.')); } const res = await generateAutoCompletion( localStorage.token, selectedModelIds.at(0), text, history?.currentId ? createMessagesList(history, history.currentId) : null ).catch((error) => { console.log(error); return null; }); console.log(res); return res; }} oncompositionstart={() => (isComposing = true)} oncompositionend={() => (isComposing = false)} on:keydown={async (e) => { e = e.detail.event; const isCtrlPressed = e.ctrlKey || e.metaKey; // metaKey is for Cmd key on Mac const commandsContainerElement = document.getElementById('commands-container'); if (e.key === 'Escape') { stopResponse(); } // Command/Ctrl + Shift + Enter to submit a message pair if (isCtrlPressed && e.key === 'Enter' && e.shiftKey) { e.preventDefault(); createMessagePair(prompt); } // 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); if (userMessageElement) { userMessageElement.scrollIntoView({ block: 'center' }); const editButton = [ ...document.getElementsByClassName('edit-user-message-button') ]?.at(-1); editButton?.click(); } } if (commandsContainerElement) { 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 === 'Tab') { e.preventDefault(); const commandOptionButton = [ ...document.getElementsByClassName('selected-command-option-button') ]?.at(-1); commandOptionButton?.click(); } if (commandsContainerElement && e.key === 'Enter') { e.preventDefault(); const commandOptionButton = [ ...document.getElementsByClassName('selected-command-option-button') ]?.at(-1); if (commandOptionButton) { commandOptionButton?.click(); } else { document.getElementById('send-message-button')?.click(); } } } else { if ( !$mobile || !( 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0 ) ) { if (isComposing) { return; } // Uses keyCode '13' for Enter key for chinese/japanese keyboards. // // Depending on the user's settings, it will send the message // either when Enter is pressed or when Ctrl+Enter is pressed. const enterPressed = ($settings?.ctrlEnterToSend ?? false) ? (e.key === 'Enter' || e.keyCode === 13) && isCtrlPressed : (e.key === 'Enter' || e.keyCode === 13) && !e.shiftKey; if (enterPressed) { e.preventDefault(); if (prompt !== '' || files.length > 0) { dispatch('submit', prompt); } } } } if (e.key === 'Escape') { console.log('Escape'); atSelectedModel = undefined; selectedToolIds = []; webSearchEnabled = false; imageGenerationEnabled = false; } }} on:paste={async (e) => { e = e.detail.event; console.log(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); } else if (item.type === 'text/plain') { if ($settings?.largeTextAsFile ?? false) { const text = clipboardData.getData('text/plain'); if (text.length > PASTED_TEXT_CHARACTER_LIMIT) { e.preventDefault(); const blob = new Blob([text], { type: 'text/plain' }); const file = new File([blob], `Pasted_Text_${Date.now()}.txt`, { type: 'text/plain' }); await uploadFileHandler(file, true); } } } } } }} />
{:else}