feat: added local LLM context length option
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
formatLocalLLMContextLength,
|
||||
LOCAL_LLM_DEFAULT_CONTEXT_LENGTH,
|
||||
normalizeLocalLLMContextLength,
|
||||
} from './localLLMConfig';
|
||||
|
||||
describe('localLLMConfig', () => {
|
||||
it('defaults invalid context lengths to 32768', () => {
|
||||
expect(normalizeLocalLLMContextLength(undefined)).toBe(LOCAL_LLM_DEFAULT_CONTEXT_LENGTH);
|
||||
expect(normalizeLocalLLMContextLength(12345)).toBe(LOCAL_LLM_DEFAULT_CONTEXT_LENGTH);
|
||||
});
|
||||
|
||||
it('formats context lengths using k suffixes', () => {
|
||||
expect(formatLocalLLMContextLength(32768)).toBe('32k');
|
||||
expect(formatLocalLLMContextLength(65536)).toBe('64k');
|
||||
expect(formatLocalLLMContextLength(131072)).toBe('128k');
|
||||
});
|
||||
});
|
||||
@@ -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`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user