mirror of
https://github.com/open-webui/open-webui
synced 2025-01-19 01:06:45 +00:00
feat: chat controls integration
This commit is contained in:
parent
9cea5f75bb
commit
30e2ec7544
@ -97,6 +97,8 @@
|
||||
currentId: null
|
||||
};
|
||||
|
||||
let params = {};
|
||||
|
||||
$: if (history.currentId !== null) {
|
||||
let _messages = [];
|
||||
|
||||
@ -230,6 +232,7 @@
|
||||
messages: {},
|
||||
currentId: null
|
||||
};
|
||||
params = {};
|
||||
|
||||
if ($page.url.searchParams.get('models')) {
|
||||
selectedModels = $page.url.searchParams.get('models')?.split(',');
|
||||
@ -299,11 +302,7 @@
|
||||
await settings.set(JSON.parse(localStorage.getItem('settings') ?? '{}'));
|
||||
}
|
||||
|
||||
await settings.set({
|
||||
...$settings,
|
||||
system: chatContent.system ?? $settings.system,
|
||||
params: chatContent.options ?? $settings.params
|
||||
});
|
||||
params = chatContent?.params ?? {};
|
||||
|
||||
autoScroll = true;
|
||||
await tick();
|
||||
@ -516,9 +515,7 @@
|
||||
title: $i18n.t('New Chat'),
|
||||
models: selectedModels,
|
||||
system: $settings.system ?? undefined,
|
||||
options: {
|
||||
...($settings.params ?? {})
|
||||
},
|
||||
params: params,
|
||||
messages: messages,
|
||||
history: history,
|
||||
tags: [],
|
||||
@ -616,11 +613,11 @@
|
||||
scrollToBottom();
|
||||
|
||||
const messagesBody = [
|
||||
$settings.system || (responseMessage?.userContext ?? null)
|
||||
params?.system || $settings.system || (responseMessage?.userContext ?? null)
|
||||
? {
|
||||
role: 'system',
|
||||
content: `${promptTemplate(
|
||||
$settings?.system ?? '',
|
||||
params?.system ?? $settings?.system ?? '',
|
||||
$user.name,
|
||||
$settings?.userLocation
|
||||
? await getAndUpdateUserLocation(localStorage.token)
|
||||
@ -705,15 +702,16 @@
|
||||
model: model.id,
|
||||
messages: messagesBody,
|
||||
options: {
|
||||
...($settings.params ?? {}),
|
||||
...(params ?? $settings.params ?? {}),
|
||||
stop:
|
||||
$settings?.params?.stop ?? undefined
|
||||
? $settings.params.stop.map((str) =>
|
||||
params?.stop ?? $settings?.params?.stop ?? undefined
|
||||
? (params?.stop ?? $settings.params.stop).map((str) =>
|
||||
decodeURIComponent(JSON.parse('"' + str.replace(/\"/g, '\\"') + '"'))
|
||||
)
|
||||
: undefined,
|
||||
num_predict: $settings?.params?.max_tokens ?? undefined,
|
||||
repeat_penalty: $settings?.params?.frequency_penalty ?? undefined
|
||||
num_predict: params?.max_tokens ?? $settings?.params?.max_tokens ?? undefined,
|
||||
repeat_penalty:
|
||||
params?.frequency_penalty ?? $settings?.params?.frequency_penalty ?? undefined
|
||||
},
|
||||
format: $settings.requestFormat ?? undefined,
|
||||
keep_alive: $settings.keepAlive ?? undefined,
|
||||
@ -849,7 +847,8 @@
|
||||
chat = await updateChatById(localStorage.token, _chatId, {
|
||||
messages: messages,
|
||||
history: history,
|
||||
models: selectedModels
|
||||
models: selectedModels,
|
||||
params: params
|
||||
});
|
||||
await chats.set(await getChatList(localStorage.token));
|
||||
}
|
||||
@ -959,11 +958,11 @@
|
||||
}
|
||||
: undefined,
|
||||
messages: [
|
||||
$settings.system || (responseMessage?.userContext ?? null)
|
||||
params?.system || $settings.system || (responseMessage?.userContext ?? null)
|
||||
? {
|
||||
role: 'system',
|
||||
content: `${promptTemplate(
|
||||
$settings?.system ?? '',
|
||||
params?.system ?? $settings?.system ?? '',
|
||||
$user.name,
|
||||
$settings?.userLocation
|
||||
? await getAndUpdateUserLocation(localStorage.token)
|
||||
@ -1008,17 +1007,18 @@
|
||||
: message?.raContent ?? message.content
|
||||
})
|
||||
})),
|
||||
seed: $settings?.params?.seed ?? undefined,
|
||||
seed: params?.seed ?? $settings?.params?.seed ?? undefined,
|
||||
stop:
|
||||
$settings?.params?.stop ?? undefined
|
||||
? $settings.params.stop.map((str) =>
|
||||
params?.stop ?? $settings?.params?.stop ?? undefined
|
||||
? (params?.stop ?? $settings.params.stop).map((str) =>
|
||||
decodeURIComponent(JSON.parse('"' + str.replace(/\"/g, '\\"') + '"'))
|
||||
)
|
||||
: undefined,
|
||||
temperature: $settings?.params?.temperature ?? undefined,
|
||||
top_p: $settings?.params?.top_p ?? undefined,
|
||||
frequency_penalty: $settings?.params?.frequency_penalty ?? undefined,
|
||||
max_tokens: $settings?.params?.max_tokens ?? undefined,
|
||||
temperature: params?.temperature ?? $settings?.params?.temperature ?? undefined,
|
||||
top_p: params?.top_p ?? $settings?.params?.top_p ?? undefined,
|
||||
frequency_penalty:
|
||||
params?.frequency_penalty ?? $settings?.params?.frequency_penalty ?? undefined,
|
||||
max_tokens: params?.max_tokens ?? $settings?.params?.max_tokens ?? undefined,
|
||||
tool_ids: selectedToolIds.length > 0 ? selectedToolIds : undefined,
|
||||
files: files.length > 0 ? files : undefined,
|
||||
session_id: $socket?.id,
|
||||
@ -1124,7 +1124,8 @@
|
||||
chat = await updateChatById(localStorage.token, _chatId, {
|
||||
models: selectedModels,
|
||||
messages: messages,
|
||||
history: history
|
||||
history: history,
|
||||
params: params
|
||||
});
|
||||
await chats.set(await getChatList(localStorage.token));
|
||||
}
|
||||
@ -1460,9 +1461,11 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-col flex-auto z-10 {showControls ? 'lg:pr-[24rem]' : ''}">
|
||||
<div class="flex flex-col flex-auto z-10">
|
||||
<div
|
||||
class=" pb-2.5 flex flex-col justify-between w-full flex-auto overflow-auto h-0 max-w-full z-10 scrollbar-hidden"
|
||||
class=" pb-2.5 flex flex-col justify-between w-full flex-auto overflow-auto h-0 max-w-full z-10 scrollbar-hidden {showControls
|
||||
? 'lg:pr-[24rem]'
|
||||
: ''}"
|
||||
id="messages-container"
|
||||
bind:this={messagesContainerElement}
|
||||
on:scroll={(e) => {
|
||||
@ -1488,7 +1491,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="">
|
||||
<div class={showControls ? 'lg:pr-[24rem]' : ''}>
|
||||
<MessageInput
|
||||
bind:files
|
||||
bind:prompt
|
||||
@ -1511,6 +1514,7 @@
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<ChatControls bind:show={showControls} />
|
||||
|
||||
<ChatControls bind:show={showControls} bind:params />
|
||||
</div>
|
||||
{/if}
|
||||
|
@ -6,8 +6,10 @@
|
||||
|
||||
export let show = false;
|
||||
|
||||
let largeScreen = false;
|
||||
export let chatId = null;
|
||||
export let params = {};
|
||||
|
||||
let largeScreen = false;
|
||||
onMount(() => {
|
||||
// listen to resize 1024px
|
||||
const mediaQuery = window.matchMedia('(min-width: 1024px)');
|
||||
@ -35,12 +37,13 @@
|
||||
<div class=" absolute bottom-0 right-0 z-20 h-full pointer-events-none">
|
||||
<div class="pr-4 pt-14 pb-8 w-[24rem] h-full" in:slide={{ duration: 200, axis: 'x' }}>
|
||||
<div
|
||||
class="w-full h-full px-5 py-4 dark:bg-gray-850 border border-gray-100 dark:border-gray-800 rounded-xl shadow-lg z-50 pointer-events-auto"
|
||||
class="w-full h-full px-5 py-4 shadow-lg dark:bg-gray-850 border border-gray-50 dark:border-gray-800 rounded-xl z-50 pointer-events-auto overflow-y-auto scrollbar-hidden"
|
||||
>
|
||||
<Controls
|
||||
on:close={() => {
|
||||
show = false;
|
||||
}}
|
||||
bind:params
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@ -48,11 +51,12 @@
|
||||
{/if}
|
||||
{:else}
|
||||
<Modal bind:show>
|
||||
<div class=" px-5 py-4 h-full">
|
||||
<div class=" px-6 py-4 h-full">
|
||||
<Controls
|
||||
on:close={() => {
|
||||
show = false;
|
||||
}}
|
||||
bind:params
|
||||
/>
|
||||
</div>
|
||||
</Modal>
|
||||
|
@ -1,16 +1,19 @@
|
||||
<script>
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
|
||||
import { createEventDispatcher, getContext } from 'svelte';
|
||||
const dispatch = createEventDispatcher();
|
||||
const i18n = getContext('i18n');
|
||||
|
||||
import XMark from '$lib/components/icons/XMark.svelte';
|
||||
import AdvancedParams from '../Settings/Advanced/AdvancedParams.svelte';
|
||||
|
||||
export let params = {};
|
||||
</script>
|
||||
|
||||
<div class=" dark:text-white">
|
||||
<div class="mb-2 flex justify-between items-center">
|
||||
<div class=" text-lg font-medium font-primary">Chat Controls</div>
|
||||
|
||||
<div>
|
||||
<div class=" flex justify-between dark:text-gray-100 mb-2">
|
||||
<div class=" text-lg font-medium self-center font-primary">{$i18n.t('Chat Controls')}</div>
|
||||
<button
|
||||
class="self-center"
|
||||
on:click={() => {
|
||||
dispatch('close');
|
||||
}}
|
||||
@ -18,7 +21,29 @@
|
||||
<XMark className="size-4" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class=" dark:text-gray-200 text-sm font-primary">
|
||||
<div>
|
||||
<div class="mb-1.5 font-medium">System Prompt</div>
|
||||
|
||||
<div>
|
||||
<textarea
|
||||
bind:value={params.system}
|
||||
class="w-full rounded-lg px-4 py-3 text-sm dark:text-gray-300 dark:bg-gray-850 border dark:border-gray-800 outline-none resize-none"
|
||||
rows="3"
|
||||
placeholder="Enter system prompt"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>coming soon</div>
|
||||
<hr class="my-2 dark:border-gray-800" />
|
||||
|
||||
<div>
|
||||
<div class="mb-1.5 font-medium">Advanced Params</div>
|
||||
|
||||
<div>
|
||||
<AdvancedParams bind:params />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -44,7 +44,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('Seed')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.seed = (params?.seed ?? null) === null ? 0 : null;
|
||||
@ -79,7 +79,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('Stop Sequence')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.stop = (params?.stop ?? null) === null ? '' : null;
|
||||
@ -113,7 +113,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('Temperature')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.temperature = (params?.temperature ?? null) === null ? 0.8 : null;
|
||||
@ -159,7 +159,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('Mirostat')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.mirostat = (params?.mirostat ?? null) === null ? 0 : null;
|
||||
@ -205,7 +205,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('Mirostat Eta')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.mirostat_eta = (params?.mirostat_eta ?? null) === null ? 0.1 : null;
|
||||
@ -251,7 +251,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('Mirostat Tau')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.mirostat_tau = (params?.mirostat_tau ?? null) === null ? 5.0 : null;
|
||||
@ -297,7 +297,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('Top K')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.top_k = (params?.top_k ?? null) === null ? 40 : null;
|
||||
@ -343,7 +343,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('Top P')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.top_p = (params?.top_p ?? null) === null ? 0.9 : null;
|
||||
@ -389,7 +389,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('Frequency Penalty')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.frequency_penalty = (params?.frequency_penalty ?? null) === null ? 1.1 : null;
|
||||
@ -435,7 +435,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('Repeat Last N')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.repeat_last_n = (params?.repeat_last_n ?? null) === null ? 64 : null;
|
||||
@ -481,7 +481,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('Tfs Z')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.tfs_z = (params?.tfs_z ?? null) === null ? 1 : null;
|
||||
@ -527,7 +527,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('Context Length')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.num_ctx = (params?.num_ctx ?? null) === null ? 2048 : null;
|
||||
@ -572,7 +572,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('Batch Size (num_batch)')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.num_batch = (params?.num_batch ?? null) === null ? 512 : null;
|
||||
@ -619,7 +619,7 @@
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.num_keep = (params?.num_keep ?? null) === null ? 24 : null;
|
||||
@ -664,7 +664,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('Max Tokens (num_predict)')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.max_tokens = (params?.max_tokens ?? null) === null ? 128 : null;
|
||||
@ -711,7 +711,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('use_mmap (Ollama)')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.use_mmap = (params?.use_mmap ?? null) === null ? true : null;
|
||||
@ -731,7 +731,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('use_mlock (Ollama)')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.use_mlock = (params?.use_mlock ?? null) === null ? true : null;
|
||||
@ -751,7 +751,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('num_thread (Ollama)')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.num_thread = (params?.num_thread ?? null) === null ? 2 : null;
|
||||
@ -797,7 +797,7 @@
|
||||
<div class=" self-center text-xs font-medium">{$i18n.t('Template')}</div>
|
||||
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded transition"
|
||||
class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
params.template = (params?.template ?? null) === null ? '' : null;
|
||||
|
@ -63,7 +63,7 @@
|
||||
<div
|
||||
class=" m-auto rounded-2xl max-w-full {sizeToWidth(
|
||||
size
|
||||
)} mx-2 bg-gray-50 dark:bg-gray-900 shadow-3xl"
|
||||
)} mx-2 bg-gray-50 dark:bg-gray-900 shadow-3xl max-h-[100dvh] overflow-y-auto scrollbar-hidden"
|
||||
in:flyAndScale
|
||||
on:mousedown={(e) => {
|
||||
e.stopPropagation();
|
||||
|
@ -22,7 +22,7 @@
|
||||
};
|
||||
</script>
|
||||
|
||||
<div class="flex {showTagInput ? 'flex-row-reverse' : ''}">
|
||||
<div class="px-0.5 flex {showTagInput ? 'flex-row-reverse' : ''}">
|
||||
{#if showTagInput}
|
||||
<div class="flex items-center">
|
||||
<input
|
||||
|
Loading…
Reference in New Issue
Block a user