mirror of
https://github.com/open-webui/open-webui
synced 2025-06-25 17:57:20 +00:00
refac: input prompt
This commit is contained in:
parent
77fa11098a
commit
feaf434d4e
@ -21,7 +21,12 @@
|
|||||||
TTSWorker
|
TTSWorker
|
||||||
} from '$lib/stores';
|
} from '$lib/stores';
|
||||||
|
|
||||||
import { blobToFile, compressImage, createMessagesList, findWordIndices } from '$lib/utils';
|
import {
|
||||||
|
blobToFile,
|
||||||
|
compressImage,
|
||||||
|
createMessagesList,
|
||||||
|
extractCurlyBraceWords
|
||||||
|
} from '$lib/utils';
|
||||||
import { transcribeAudio } from '$lib/apis/audio';
|
import { transcribeAudio } from '$lib/apis/audio';
|
||||||
import { uploadFile } from '$lib/apis/files';
|
import { uploadFile } from '$lib/apis/files';
|
||||||
import { generateAutoCompletion } from '$lib/apis';
|
import { generateAutoCompletion } from '$lib/apis';
|
||||||
@ -631,6 +636,7 @@
|
|||||||
{#if $settings?.richTextInput ?? true}
|
{#if $settings?.richTextInput ?? true}
|
||||||
<div
|
<div
|
||||||
class="scrollbar-hidden text-left bg-transparent dark:text-gray-100 outline-hidden w-full pt-3 px-1 resize-none h-fit max-h-80 overflow-auto"
|
class="scrollbar-hidden text-left bg-transparent dark:text-gray-100 outline-hidden w-full pt-3 px-1 resize-none h-fit max-h-80 overflow-auto"
|
||||||
|
id="chat-input-container"
|
||||||
>
|
>
|
||||||
<RichTextInput
|
<RichTextInput
|
||||||
bind:this={chatInputElement}
|
bind:this={chatInputElement}
|
||||||
@ -977,7 +983,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (e.key === 'Tab') {
|
if (e.key === 'Tab') {
|
||||||
const words = findWordIndices(prompt);
|
const words = extractCurlyBraceWords(prompt);
|
||||||
|
|
||||||
if (words.length > 0) {
|
if (words.length > 0) {
|
||||||
const word = words.at(0);
|
const word = words.at(0);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { prompts, settings, user } from '$lib/stores';
|
import { prompts, settings, user } from '$lib/stores';
|
||||||
import {
|
import {
|
||||||
findWordIndices,
|
extractCurlyBraceWords,
|
||||||
getUserPosition,
|
getUserPosition,
|
||||||
getFormattedDate,
|
getFormattedDate,
|
||||||
getFormattedTime,
|
getFormattedTime,
|
||||||
@ -127,29 +127,32 @@
|
|||||||
const lastWord = lastLineWords.pop();
|
const lastWord = lastLineWords.pop();
|
||||||
|
|
||||||
if ($settings?.richTextInput ?? true) {
|
if ($settings?.richTextInput ?? true) {
|
||||||
lastLineWords.push(`${text.replace(/</g, '<').replace(/>/g, '>')}`);
|
lastLineWords.push(
|
||||||
|
`${text.replace(/</g, '<').replace(/>/g, '>').replaceAll('\n', '<br/>')}`
|
||||||
|
);
|
||||||
|
|
||||||
lines.push(lastLineWords.join(' '));
|
lines.push(lastLineWords.join(' '));
|
||||||
|
prompt = lines.join('<br/>');
|
||||||
} else {
|
} else {
|
||||||
lastLineWords.push(text);
|
lastLineWords.push(text);
|
||||||
lines.push(lastLineWords.join(' '));
|
lines.push(lastLineWords.join(' '));
|
||||||
}
|
|
||||||
|
|
||||||
prompt = lines.join('\n');
|
prompt = lines.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
const chatInputContainerElement = document.getElementById('chat-input-container');
|
const chatInputContainerElement = document.getElementById('chat-input-container');
|
||||||
const chatInputElement = document.getElementById('chat-input');
|
const chatInputElement = document.getElementById('chat-input');
|
||||||
|
|
||||||
await tick();
|
await tick();
|
||||||
if (chatInputContainerElement) {
|
if (chatInputContainerElement) {
|
||||||
chatInputContainerElement.style.height = '';
|
chatInputContainerElement.scrollTop = chatInputContainerElement.scrollHeight;
|
||||||
chatInputContainerElement.style.height =
|
|
||||||
Math.min(chatInputContainerElement.scrollHeight, 200) + 'px';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await tick();
|
await tick();
|
||||||
if (chatInputElement) {
|
if (chatInputElement) {
|
||||||
chatInputElement.focus();
|
chatInputElement.focus();
|
||||||
chatInputElement.dispatchEvent(new Event('input'));
|
chatInputElement.dispatchEvent(new Event('input'));
|
||||||
|
|
||||||
|
chatInputElement.scrollTop = chatInputElement.scrollHeight;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
import { createEventDispatcher, tick, getContext, onMount, onDestroy } from 'svelte';
|
import { createEventDispatcher, tick, getContext, onMount, onDestroy } from 'svelte';
|
||||||
import { config, settings } from '$lib/stores';
|
import { config, settings } from '$lib/stores';
|
||||||
import { blobToFile, calculateSHA256, findWordIndices } from '$lib/utils';
|
import { blobToFile, calculateSHA256, extractCurlyBraceWords } from '$lib/utils';
|
||||||
|
|
||||||
import { transcribeAudio } from '$lib/apis/audio';
|
import { transcribeAudio } from '$lib/apis/audio';
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
import { getChatList, updateChatById } from '$lib/apis/chats';
|
import { getChatList, updateChatById } from '$lib/apis/chats';
|
||||||
import { copyToClipboard, findWordIndices } from '$lib/utils';
|
import { copyToClipboard, extractCurlyBraceWords } from '$lib/utils';
|
||||||
|
|
||||||
import Message from './Messages/Message.svelte';
|
import Message from './Messages/Message.svelte';
|
||||||
import Loader from '../common/Loader.svelte';
|
import Loader from '../common/Loader.svelte';
|
||||||
@ -406,19 +406,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
prompt = text;
|
prompt = text;
|
||||||
|
|
||||||
await tick();
|
|
||||||
|
|
||||||
const chatInputContainerElement = document.getElementById('chat-input-container');
|
|
||||||
if (chatInputContainerElement) {
|
|
||||||
prompt = p;
|
|
||||||
|
|
||||||
chatInputContainerElement.style.height = '';
|
|
||||||
chatInputContainerElement.style.height =
|
|
||||||
Math.min(chatInputContainerElement.scrollHeight, 200) + 'px';
|
|
||||||
chatInputContainerElement.focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
await tick();
|
await tick();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
import { config, user, models as _models, temporaryChatEnabled } from '$lib/stores';
|
import { config, user, models as _models, temporaryChatEnabled } from '$lib/stores';
|
||||||
import { sanitizeResponseContent, findWordIndices } from '$lib/utils';
|
import { sanitizeResponseContent, extractCurlyBraceWords } from '$lib/utils';
|
||||||
import { WEBUI_BASE_URL } from '$lib/constants';
|
import { WEBUI_BASE_URL } from '$lib/constants';
|
||||||
|
|
||||||
import Suggestions from './Suggestions.svelte';
|
import Suggestions from './Suggestions.svelte';
|
||||||
@ -65,9 +65,7 @@
|
|||||||
const chatInputElement = document.getElementById('chat-input');
|
const chatInputElement = document.getElementById('chat-input');
|
||||||
|
|
||||||
if (chatInputContainerElement) {
|
if (chatInputContainerElement) {
|
||||||
chatInputContainerElement.style.height = '';
|
chatInputContainerElement.scrollTop = chatInputContainerElement.scrollHeight;
|
||||||
chatInputContainerElement.style.height =
|
|
||||||
Math.min(chatInputContainerElement.scrollHeight, 200) + 'px';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await tick();
|
await tick();
|
||||||
|
@ -361,14 +361,14 @@ export const compareVersion = (latest, current) => {
|
|||||||
}) < 0;
|
}) < 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const findWordIndices = (text) => {
|
export const extractCurlyBraceWords = (text) => {
|
||||||
const regex = /\[([^\]]+)\]/g;
|
const regex = /\{\{([^}]+)\}\}/g;
|
||||||
const matches = [];
|
const matches = [];
|
||||||
let match;
|
let match;
|
||||||
|
|
||||||
while ((match = regex.exec(text)) !== null) {
|
while ((match = regex.exec(text)) !== null) {
|
||||||
matches.push({
|
matches.push({
|
||||||
word: match[1],
|
word: match[1].trim(),
|
||||||
startIndex: match.index,
|
startIndex: match.index,
|
||||||
endIndex: regex.lastIndex - 1
|
endIndex: regex.lastIndex - 1
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user