From 5fcdc333b163e989d6e02d8dadbc6e45127394b0 Mon Sep 17 00:00:00 2001 From: KimiSwitch Dev Date: Thu, 9 Jul 2026 01:04:24 +0800 Subject: [PATCH] feat: apply smart default max_context_size when adding models --- src/App.tsx | 10 ++++++++-- src/components/ProviderEdit.tsx | 6 ++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index f3963f0..6aec3a6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,6 +5,7 @@ import { useConfig } from "./hooks/useConfig"; import { ProviderList } from "./components/ProviderList"; import { ProviderEdit } from "./components/ProviderEdit"; import { useTranslation } from "./i18n"; +import { getDefaultMaxContextSize } from "./lib/model-defaults"; import type { Agent, Model, Provider } from "./types"; const AGENT_STORAGE_KEY = "pi-switch-agent"; @@ -246,7 +247,12 @@ export default function App() { alias = `${m.alias}-${n}`; n++; } - updatedModels[alias] = { ...m, alias, provider: provider.name }; + updatedModels[alias] = { + ...m, + alias, + provider: provider.name, + max_context_size: m.max_context_size ?? getDefaultMaxContextSize(m.model), + }; } let default_model = cfg.default_model; @@ -398,7 +404,7 @@ export default function App() { alias, provider: currentProvider.name, model: "", - max_context_size: 128000, + max_context_size: getDefaultMaxContextSize(alias), display_name: null, role: null, supports_1m: false, diff --git a/src/components/ProviderEdit.tsx b/src/components/ProviderEdit.tsx index 4a86bfd..71e4e57 100644 --- a/src/components/ProviderEdit.tsx +++ b/src/components/ProviderEdit.tsx @@ -1,6 +1,7 @@ import { useEffect, useId, useState } from "react"; import { invoke } from "@tauri-apps/api/core"; import { useTranslation } from "../i18n"; +import { getDefaultMaxContextSize } from "../lib/model-defaults"; import { AgentSettingsPanel } from "./AgentSettingsPanel"; import type { Agent, DiscoveredModel, Model, Provider, ProviderType } from "../types"; @@ -378,14 +379,15 @@ function ModelMapping({ for (const dm of discovered) { if (!selected.has(dm.id)) continue; const alias = dm.id.replace(/[^a-zA-Z0-9_-]/g, "-"); + const max_context_size = dm.max_context_size ?? getDefaultMaxContextSize(dm.id); toAdd.push({ alias, provider: provider.name, model: dm.id, - max_context_size: dm.max_context_size ?? 128000, + max_context_size, display_name: dm.display_name, role: null, - supports_1m: (dm.max_context_size ?? 0) >= 1_000_000, + supports_1m: max_context_size >= 1_000_000, capabilities: [], }); }