LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。
TypeScript
feat: configurable context window size with preset slider (4K → 1M)
nash_su9785ed9975d2
diff --git a/src/components/chat/chat-panel.tsx b/src/components/chat/chat-panel.tsxindex 63ae0217..b026402c 100644--- a/src/components/chat/chat-panel.tsx+++ b/src/components/chat/chat-panel.tsx@@ -88,8 +88,9 @@ export function ChatPanel() {graphExpansions.sort((a, b) => b.relevance - a.relevance)// --- Phase 3 & 4: Budget control with priority queue ---- const TOTAL_BUDGET = 30_000- const MAX_PAGE_SIZE = 8_000+ // Use ~60% of max context for page content, rest for prompt + history + response+ const TOTAL_BUDGET = Math.floor(llmConfig.maxContextSize * 0.6)+ const MAX_PAGE_SIZE = Math.min(Math.floor(TOTAL_BUDGET * 0.3), 30_000)let usedChars = 0type PageEntry = { title: string; path: string; content: string; priority: number }diff --git a/src/components/settings/settings-view.tsx b/src/components/settings/settings-view.tsxindex eed5f8bc..87ab1c36 100644--- a/src/components/settings/settings-view.tsx+++ b/src/components/settings/settings-view.tsx@@ -32,6 +32,7 @@ export function SettingsView() {const [model, setModel] = useState(llmConfig.model)const [ollamaUrl, setOllamaUrl] = useState(llmConfig.ollamaUrl)const [customEndpoint, setCustomEndpoint] = useState(llmConfig.customEndpoint)+ const [maxContextSize, setMaxContextSize] = useState(llmConfig.maxContextSize ?? 204800)const [searchProvider, setSearchProvider] = useState(searchApiConfig.provider)const [searchApiKey, setSearchApiKey] = useState(searchApiConfig.apiKey)const [saved, setSaved] = useState(false)@@ -54,7 +55,7 @@ export function SettingsView() {async function handleSave() {const { saveLlmConfig, saveSearchApiConfig } = await import("@/lib/project-store")- const newConfig = { provider, apiKey, model, ollamaUrl, customEndpoint }+ const newConfig = { provider, apiKey, model, ollamaUrl, customEndpoint, maxContextSize }const newSearchConfig = { provider: searchProvider, apiKey: searchApiKey }setSearchApiConfig(newSearchConfig)await saveSearchApiConfig(newSearchConfig)@@ -203,6 +204,18 @@ export function SettingsView() {</div></div>+ {/* Context Window Size */}+ <div className="space-y-4 rounded-lg border p-4">+ <h3 className="font-semibold">Context Window</h3>+ <p className="text-xs text-muted-foreground">+ Maximum context size sent to the LLM. Larger context allows more wiki pages in each query but costs more tokens.+ </p>++ <div className="space-y-3">+ <ContextSizeSelector value={maxContextSize} onChange={setMaxContextSize} />+ </div>+ </div>+{/* Web Search API section */}<div className="space-y-4 rounded-lg border p-4"><h3 className="font-semibold">Web Search (Deep Research)</h3>@@ -254,3 +267,65 @@ export function SettingsView() {</div>)}++// Context size presets matching common model context windows+const CONTEXT_PRESETS = [+ { value: 4096, label: "4K" },+ { value: 8192, label: "8K" },+ { value: 16384, label: "16K" },+ { value: 32768, label: "32K" },+ { value: 65536, label: "64K" },+ { value: 131072, label: "128K" },+ { value: 204800, label: "200K" },+ { value: 262144, label: "256K" },+ { value: 524288, label: "512K" },+ { value: 1000000, label: "1M" },+]++function ContextSizeSelector({ value, onChange }: { value: number; onChange: (v: number) => void }) {+ // Find closest preset index+ const closestIndex = CONTEXT_PRESETS.reduce((best, preset, i) => {+ return Math.abs(preset.value - value) < Math.abs(CONTEXT_PRESETS[best].value - value) ? i : best+ }, 0)++ return (+ <div>+ <div className="flex items-center justify-between mb-2">+ <span className="text-sm font-medium">{formatSize(value)}</span>+ <span className="text-xs text-muted-foreground">+ ~{Math.floor(value * 0.6 / 1000)}K chars for wiki content+ </span>+ </div>+ <input+ type="range"+ min={0}+ max={CONTEXT_PRESETS.length - 1}+ step={1}+ value={closestIndex}+ onChange={(e) => onChange(CONTEXT_PRESETS[parseInt(e.target.value)].value)}+ className="w-full h-2 rounded-lg appearance-none cursor-pointer accent-primary"+ style={{ background: `linear-gradient(to right, #4f46e5 ${(closestIndex / (CONTEXT_PRESETS.length - 1)) * 100}%, #e5e7eb ${(closestIndex / (CONTEXT_PRESETS.length - 1)) * 100}%)` }}+ />+ <div className="flex justify-between mt-1">+ {CONTEXT_PRESETS.map((preset, i) => (+ <button+ key={preset.value}+ type="button"+ onClick={() => onChange(preset.value)}+ className={`text-[9px] px-0.5 ${+ i === closestIndex ? "text-primary font-bold" : "text-muted-foreground/50"+ }`}+ >+ {preset.label}+ </button>+ ))}+ </div>+ </div>+ )+}++function formatSize(chars: number): string {+ if (chars >= 1000000) return `${(chars / 1000000).toFixed(1)}M characters`+ if (chars >= 1000) return `${Math.round(chars / 1000)}K characters`+ return `${chars} characters`+}diff --git a/src/stores/wiki-store.ts b/src/stores/wiki-store.tsindex 3ee3d669..275038f1 100644--- a/src/stores/wiki-store.ts+++ b/src/stores/wiki-store.ts@@ -7,6 +7,7 @@ interface LlmConfig {model: stringollamaUrl: stringcustomEndpoint: string+ maxContextSize: number // max context window in characters}interface SearchApiConfig {@@ -46,6 +47,7 @@ export const useWikiStore = create<WikiState>((set) => ({llmConfig: {provider: "openai",apiKey: "",+ maxContextSize: 204800,model: "",ollamaUrl: "http://localhost:11434",customEndpoint: "",