feat: added local LLM context length option

This commit is contained in:
Xiaohan-Tian
2026-05-14 19:44:25 -07:00
parent dbf0c20542
commit a48966d761
13 changed files with 467 additions and 4 deletions
+17
View File
@@ -6,6 +6,10 @@ export const LOCAL_LLM_DISPLAY_NAME = 'Gemma 4 E4B';
export const LOCAL_LLM_LEGACY_FILENAMES = [
'gemma-3n-E4B-it-int4-Web.litertlm',
];
export const LOCAL_LLM_CONTEXT_LENGTH_OPTIONS = [32768, 65536, 131072] as const;
export const LOCAL_LLM_DEFAULT_CONTEXT_LENGTH = 32768;
export type LocalLLMContextLength = typeof LOCAL_LLM_CONTEXT_LENGTH_OPTIONS[number];
export interface LocalLLMRuntimeSupport {
supported: boolean;
@@ -40,3 +44,16 @@ export function detectLocalLLMRuntimeSupport(): LocalLLMRuntimeSupport {
reason,
};
}
export function isLocalLLMContextLength(value: unknown): value is LocalLLMContextLength {
return typeof value === 'number'
&& (LOCAL_LLM_CONTEXT_LENGTH_OPTIONS as readonly number[]).includes(value);
}
export function normalizeLocalLLMContextLength(value: unknown): LocalLLMContextLength {
return isLocalLLMContextLength(value) ? value : LOCAL_LLM_DEFAULT_CONTEXT_LENGTH;
}
export function formatLocalLLMContextLength(value: LocalLLMContextLength): string {
return `${Math.round(value / 1024)}k`;
}