refac
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
};
|
||||
|
||||
let chatConfig = {
|
||||
CONTEXT_COMPACTION_MODEL: '',
|
||||
ENABLE_CONTEXT_COMPACTION: false,
|
||||
CONTEXT_COMPACTION_TOKEN_THRESHOLD: 80000,
|
||||
CONTEXT_COMPACTION_TOKEN_CAP: 80000,
|
||||
@@ -71,6 +72,27 @@
|
||||
|
||||
let models: any[] | null = null;
|
||||
$: modelOptions = models ?? [];
|
||||
const normalizeModelSelection = (modelId: string | null | undefined) => {
|
||||
if (!modelId) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const model = modelOptions.find((m: any) => m.id === modelId);
|
||||
if (!model) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (
|
||||
model?.access_grants &&
|
||||
!model.access_grants.some(
|
||||
(g: any) => g.principal_type === 'user' && g.principal_id === '*' && g.permission === 'read'
|
||||
)
|
||||
) {
|
||||
toast.error($i18n.t('This model is not publicly available. Please select another model.'));
|
||||
}
|
||||
|
||||
return model.id;
|
||||
};
|
||||
const inputClass =
|
||||
'w-full h-7 rounded-lg border border-gray-100/50 bg-gray-50/40 px-2 text-xs text-gray-700 outline-hidden transition-colors placeholder:text-gray-300 focus:border-blue-400 dark:border-white/[0.04] dark:bg-white/[0.03] dark:text-gray-300 dark:placeholder:text-gray-700 dark:focus:border-blue-500';
|
||||
const textareaClass =
|
||||
@@ -150,30 +172,7 @@
|
||||
className="w-full"
|
||||
placeholder={$i18n.t('Select a model')}
|
||||
on:change={() => {
|
||||
if (taskConfig.TASK_MODEL) {
|
||||
const model = modelOptions.find((m: any) => m.id === taskConfig.TASK_MODEL);
|
||||
if (model) {
|
||||
if (
|
||||
model?.access_grants &&
|
||||
!model.access_grants.some(
|
||||
(g: any) =>
|
||||
g.principal_type === 'user' &&
|
||||
g.principal_id === '*' &&
|
||||
g.permission === 'read'
|
||||
)
|
||||
) {
|
||||
toast.error(
|
||||
$i18n.t(
|
||||
'This model is not publicly available. Please select another model.'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
taskConfig.TASK_MODEL = model.id;
|
||||
} else {
|
||||
taskConfig.TASK_MODEL = '';
|
||||
}
|
||||
}
|
||||
taskConfig.TASK_MODEL = normalizeModelSelection(taskConfig.TASK_MODEL);
|
||||
}}
|
||||
>
|
||||
<option value="" selected>{$i18n.t('Current Model')}</option>
|
||||
@@ -192,32 +191,9 @@
|
||||
className="w-full"
|
||||
placeholder={$i18n.t('Select a model')}
|
||||
on:change={() => {
|
||||
if (taskConfig.TASK_MODEL_EXTERNAL) {
|
||||
const model = modelOptions.find(
|
||||
(m: any) => m.id === taskConfig.TASK_MODEL_EXTERNAL
|
||||
);
|
||||
if (model) {
|
||||
if (
|
||||
model?.access_grants &&
|
||||
!model.access_grants.some(
|
||||
(g: any) =>
|
||||
g.principal_type === 'user' &&
|
||||
g.principal_id === '*' &&
|
||||
g.permission === 'read'
|
||||
)
|
||||
) {
|
||||
toast.error(
|
||||
$i18n.t(
|
||||
'This model is not publicly available. Please select another model.'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
taskConfig.TASK_MODEL_EXTERNAL = model.id;
|
||||
} else {
|
||||
taskConfig.TASK_MODEL_EXTERNAL = '';
|
||||
}
|
||||
}
|
||||
taskConfig.TASK_MODEL_EXTERNAL = normalizeModelSelection(
|
||||
taskConfig.TASK_MODEL_EXTERNAL
|
||||
);
|
||||
}}
|
||||
>
|
||||
<option value="" selected>{$i18n.t('Current Model')}</option>
|
||||
@@ -245,6 +221,32 @@
|
||||
</AdminSettingRow>
|
||||
|
||||
{#if chatConfig.ENABLE_CONTEXT_COMPACTION}
|
||||
<AdminSettingField
|
||||
label={$i18n.t('Context Compaction Model')}
|
||||
description={$i18n.t(
|
||||
'Choose a dedicated model for context compaction summaries. Current Model follows the active chat model.'
|
||||
)}
|
||||
>
|
||||
<SettingsSelect
|
||||
bind:value={chatConfig.CONTEXT_COMPACTION_MODEL}
|
||||
className="w-full"
|
||||
placeholder={$i18n.t('Select a model')}
|
||||
on:change={() => {
|
||||
chatConfig.CONTEXT_COMPACTION_MODEL = normalizeModelSelection(
|
||||
chatConfig.CONTEXT_COMPACTION_MODEL
|
||||
);
|
||||
}}
|
||||
>
|
||||
<option value="" selected>{$i18n.t('Current Model')}</option>
|
||||
{#each modelOptions as model}
|
||||
<option value={model.id} class="bg-gray-100 dark:bg-gray-700">
|
||||
{model.name}
|
||||
{model?.connection_type === 'local' ? `(${$i18n.t('Local')})` : ''}
|
||||
</option>
|
||||
{/each}
|
||||
</SettingsSelect>
|
||||
</AdminSettingField>
|
||||
|
||||
<AdminSettingField
|
||||
label={$i18n.t('Token Threshold')}
|
||||
description={$i18n.t(
|
||||
|
||||
Reference in New Issue
Block a user