refac
This commit is contained in:
@@ -1,6 +1,63 @@
|
||||
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
||||
import { getTimeRange } from '$lib/utils';
|
||||
|
||||
export const getChatConfig = async (token: string) => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/config`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
...(token && { authorization: `Bearer ${token}` })
|
||||
}
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
export const updateChatConfig = async (token: string, config: object) => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/config`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
...(token && { authorization: `Bearer ${token}` })
|
||||
},
|
||||
body: JSON.stringify(config)
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
export const createNewChat = async (token: string, chat: object, folderId: string | null) => {
|
||||
let error = null;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { getModels, getTaskConfig, updateTaskConfig } from '$lib/apis';
|
||||
import { getChatConfig, updateChatConfig } from '$lib/apis/chats';
|
||||
import { config, settings } from '$lib/stores';
|
||||
import { createEventDispatcher, onMount, getContext } from 'svelte';
|
||||
import { toast } from 'svelte-sonner';
|
||||
@@ -36,8 +37,17 @@
|
||||
VOICE_MODE_PROMPT_TEMPLATE: ''
|
||||
};
|
||||
|
||||
let chatConfig = {
|
||||
ENABLE_CONTEXT_COMPACTION: false,
|
||||
CONTEXT_COMPACTION_TOKEN_THRESHOLD: 80000,
|
||||
CONTEXT_COMPACTION_PROMPT_TEMPLATE: ''
|
||||
};
|
||||
|
||||
const updateInterfaceHandler = async () => {
|
||||
taskConfig = await updateTaskConfig(localStorage.token, taskConfig);
|
||||
[taskConfig, chatConfig] = await Promise.all([
|
||||
updateTaskConfig(localStorage.token, taskConfig),
|
||||
updateChatConfig(localStorage.token, chatConfig)
|
||||
]);
|
||||
};
|
||||
|
||||
let workspaceModels = null;
|
||||
@@ -47,7 +57,10 @@
|
||||
|
||||
const init = async () => {
|
||||
try {
|
||||
taskConfig = await getTaskConfig(localStorage.token);
|
||||
[taskConfig, chatConfig] = await Promise.all([
|
||||
getTaskConfig(localStorage.token),
|
||||
getChatConfig(localStorage.token)
|
||||
]);
|
||||
|
||||
workspaceModels = await getBaseModels(localStorage.token);
|
||||
baseModels = await getModels(localStorage.token, null, false);
|
||||
@@ -84,7 +97,7 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if models !== null && taskConfig}
|
||||
{#if models !== null && taskConfig && chatConfig}
|
||||
<form
|
||||
class="flex flex-col h-full justify-between space-y-3 text-sm"
|
||||
on:submit|preventDefault={() => {
|
||||
@@ -210,6 +223,63 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class=" border-gray-100/30 dark:border-gray-850/30 my-3" />
|
||||
|
||||
<div class="mb-2.5 flex w-full items-center justify-between">
|
||||
<div class=" self-center text-xs font-medium">
|
||||
{$i18n.t('Context Compaction')}
|
||||
</div>
|
||||
|
||||
<Switch bind:state={chatConfig.ENABLE_CONTEXT_COMPACTION} />
|
||||
</div>
|
||||
|
||||
{#if chatConfig.ENABLE_CONTEXT_COMPACTION}
|
||||
<div class="mb-2.5">
|
||||
<div class=" mb-1 text-xs font-medium">{$i18n.t('Token Threshold')}</div>
|
||||
|
||||
<Tooltip
|
||||
content={$i18n.t(
|
||||
'Older messages are summarized when estimated context exceeds this token limit.'
|
||||
)}
|
||||
placement="top-start"
|
||||
>
|
||||
<input
|
||||
type="number"
|
||||
min="1"
|
||||
step="1"
|
||||
class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-hidden"
|
||||
bind:value={chatConfig.CONTEXT_COMPACTION_TOKEN_THRESHOLD}
|
||||
/>
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
<div class="mb-2.5">
|
||||
<div class=" mb-1 text-xs font-medium">{$i18n.t('Context Compaction Prompt')}</div>
|
||||
|
||||
<Tooltip
|
||||
content={$i18n.t('Leave empty to use the default prompt, or enter a custom prompt')}
|
||||
placement="top-start"
|
||||
>
|
||||
<Textarea
|
||||
bind:value={chatConfig.CONTEXT_COMPACTION_PROMPT_TEMPLATE}
|
||||
placeholder={$i18n.t(
|
||||
'Leave empty to use the default prompt, or enter a custom prompt'
|
||||
)}
|
||||
/>
|
||||
</Tooltip>
|
||||
<div class="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
{$i18n.t('Available variables')}:
|
||||
<code>{'{{PREVIOUS_SUMMARY}}'}</code>,
|
||||
<code>{'{{COMPACTED_MESSAGES}}'}</code>,
|
||||
<code>{'{{RECENT_MESSAGES}}'}</code>,
|
||||
<code>{'{{MESSAGES}}'}</code>,
|
||||
<code>{'{{CURRENT_DATE}}'}</code>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<hr class=" border-gray-100/30 dark:border-gray-850/30 my-3" />
|
||||
|
||||
<div class="mb-2.5 flex w-full items-center justify-between">
|
||||
<div class=" self-center text-xs font-medium">
|
||||
{$i18n.t('Title Generation')}
|
||||
|
||||
Reference in New Issue
Block a user