char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: Linting & Formatting scripts (#26819)92d1bb0c9

char/aliceai-t5-moe
1.3 KiB53 linesraw
1/**
2 * Type-safe configuration helpers
3 *
4 * Provides utilities for safely accessing and modifying configuration objects
5 * with dynamic keys while maintaining TypeScript type safety.
6 */
7
8/**
9 * Type-safe helper to access config properties dynamically
10 * Provides better type safety than direct casting to Record
11 */
12export function setConfigValue<T extends SettingsConfigType>(
13	config: T,
14	key: string,
15	value: unknown
16): void {
17	if (key in config) {
18		(config as Record<string, unknown>)[key] = value;
19	}
20}
21
22/**
23 * Type-safe helper to get config values dynamically
24 */
25export function getConfigValue<T extends SettingsConfigType>(
26	config: T,
27	key: string
28): string | number | boolean | undefined {
29	const value = (config as Record<string, unknown>)[key];
30
31	return value as string | number | boolean | undefined;
32}
33
34/**
35 * Convert a SettingsConfigType to a ParameterRecord for specific keys
36 * Useful for parameter synchronization operations
37 */
38export function configToParameterRecord<T extends SettingsConfigType>(
39	config: T,
40	keys: string[]
41): Record<string, string | number | boolean> {
42	const record: Record<string, string | number | boolean> = {};
43
44	for (const key of keys) {
45		const value = getConfigValue(config, key);
46
47		if (value !== undefined) {
48			record[key] = value;
49		}
50	}
51
52	return record;
53}