mirror of
https://github.com/open-webui/computer.git
synced 2026-11-26 23:29:25 -05:00
refac
This commit is contained in:
1 parent
ead88de032
commit
c4a1dbc89d
4 files changed
+45
-10
No files matched your search
@@ -11,6 +11,7 @@
|
||||
import { t } from '$lib/i18n';
|
||||
import Icon from '../Icon.svelte';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
import ModelSelector from '$lib/components/common/ModelSelector.svelte';
|
||||
|
||||
type ParamRow = { key: string; value: string };
|
||||
type ModelEntry = {
|
||||
@@ -34,6 +35,9 @@
|
||||
let globalExpanded = $state(false);
|
||||
let showVariables = $state(false);
|
||||
|
||||
// Default model
|
||||
let defaultModelId = $state('');
|
||||
|
||||
// Context compaction
|
||||
let compactTokenThreshold = $state(80000);
|
||||
let compactDirty = $state(false);
|
||||
@@ -105,10 +109,11 @@ Files:
|
||||
loading = false;
|
||||
}
|
||||
|
||||
// Load context compaction threshold from admin config
|
||||
// Load admin config (default model, context compaction)
|
||||
try {
|
||||
const adminCfg = await getAdminConfig();
|
||||
compactTokenThreshold = Number(adminCfg['chat.compact_token_threshold']) || 80000;
|
||||
defaultModelId = typeof adminCfg['chat.default_model'] === 'string' ? adminCfg['chat.default_model'] : '';
|
||||
} catch {}
|
||||
});
|
||||
|
||||
@@ -158,11 +163,12 @@ Files:
|
||||
globalDirty = false;
|
||||
models.forEach((m) => (m.dirty = false));
|
||||
|
||||
// Save context compaction threshold
|
||||
if (compactDirty) {
|
||||
await updateConfig({ 'chat.compact_token_threshold': compactTokenThreshold });
|
||||
compactDirty = false;
|
||||
}
|
||||
// Save default model
|
||||
await updateConfig({
|
||||
'chat.compact_token_threshold': compactTokenThreshold,
|
||||
'chat.default_model': defaultModelId
|
||||
});
|
||||
compactDirty = false;
|
||||
|
||||
toast.success($t('settings.saved'));
|
||||
} catch {
|
||||
@@ -276,6 +282,17 @@ Files:
|
||||
{$t('admin.models')}
|
||||
</h2>
|
||||
|
||||
<!-- Default model -->
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-2">
|
||||
{$t('models.defaultModel')}
|
||||
</h3>
|
||||
<div class="mb-1">
|
||||
<ModelSelector bind:selectedModel={defaultModelId} preferAbove={false} align="start" />
|
||||
</div>
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mb-5">
|
||||
{$t('models.defaultModelHint')}
|
||||
</p>
|
||||
|
||||
<!-- Context compaction -->
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-2">{$t('admin.contextCompaction')}</h3>
|
||||
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
|
||||
interface Props {
|
||||
selectedModel: string;
|
||||
preferAbove?: boolean;
|
||||
align?: 'start' | 'end';
|
||||
}
|
||||
let { selectedModel = $bindable() }: Props = $props();
|
||||
let { selectedModel = $bindable(), preferAbove = true, align = 'end' }: Props = $props();
|
||||
|
||||
let btnEl: HTMLButtonElement | undefined = $state();
|
||||
let searchInputEl: HTMLInputElement | undefined = $state();
|
||||
@@ -76,10 +78,10 @@
|
||||
items={menuItems}
|
||||
anchor={btnEl}
|
||||
onclose={() => (open = false)}
|
||||
preferAbove={true}
|
||||
preferAbove={preferAbove}
|
||||
maxHeight="15rem"
|
||||
className="w-48"
|
||||
align="end"
|
||||
align={align}
|
||||
>
|
||||
{#snippet header()}
|
||||
<div class="flex items-center gap-1.5 h-6 px-2 mt-0.5">
|
||||
|
||||
@@ -307,6 +307,9 @@
|
||||
"admin.browserFirecrawlBaseUrlHint": "Change for self-hosted Firecrawl instances",
|
||||
|
||||
"admin.models": "Models",
|
||||
"models.defaultModel": "Default model",
|
||||
"models.defaultModelNone": "None (use first available)",
|
||||
"models.defaultModelHint": "Pre-selected model for new chats and gateway requests.",
|
||||
"models.defaults": "Defaults",
|
||||
"models.noDefaults": "No global defaults",
|
||||
"models.noParams": "No parameters",
|
||||
|
||||
+14
-1
@@ -588,7 +588,8 @@ async def _resolve_model(workspace: str) -> tuple[dict, str, str]:
|
||||
Priority:
|
||||
1. Gateway model selected in Settings > Gateway
|
||||
2. Workspace-specific model override (.cptr/model)
|
||||
3. First enabled connection's first model (with auto-discovery)
|
||||
3. Default model from Settings > Models (chat.default_model)
|
||||
4. First enabled connection's first model (with auto-discovery)
|
||||
|
||||
Returns (connection_dict, bare_model, full_model_id).
|
||||
"""
|
||||
@@ -621,6 +622,18 @@ async def _resolve_model(workspace: str) -> tuple[dict, str, str]:
|
||||
model_override,
|
||||
)
|
||||
|
||||
# Try the default model (set in Settings > Models)
|
||||
default_model = await Config.get("chat.default_model")
|
||||
if isinstance(default_model, str) and default_model.strip():
|
||||
try:
|
||||
connection, bare = await _resolve_connection(default_model.strip())
|
||||
return connection, bare, default_model.strip()
|
||||
except Exception:
|
||||
logger.warning(
|
||||
"[openai-compat] Default model '%s' not found, falling back",
|
||||
default_model,
|
||||
)
|
||||
|
||||
# Fall back to the first enabled connection + its first model
|
||||
from cptr.routers.chat import _fetch_provider_models
|
||||
|
||||
|
||||
Reference in new issue
Block a user