mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-12-23 09:34:23 +00:00
Refactor ConfigContext hooks
This commit is contained in:
51
webui/src/hooks/useConfig.ts
Normal file
51
webui/src/hooks/useConfig.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { useConfig } from '@/contexts/ConfigContext'
|
||||
|
||||
// Helper hook to get instance default values from config
|
||||
export const useInstanceDefaults = () => {
|
||||
const { config } = useConfig()
|
||||
|
||||
if (!config || !config.instances) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
autoRestart: config.instances.default_auto_restart,
|
||||
maxRestarts: config.instances.default_max_restarts,
|
||||
restartDelay: config.instances.default_restart_delay,
|
||||
onDemandStart: config.instances.default_on_demand_start,
|
||||
}
|
||||
}
|
||||
|
||||
// Helper hook to get specific backend settings by backend type
|
||||
export const useBackendSettings = (backendType: string | undefined) => {
|
||||
const { config } = useConfig()
|
||||
|
||||
if (!config || !config.backends || !backendType) {
|
||||
return null
|
||||
}
|
||||
|
||||
// Map backend type to config key
|
||||
const backendKey = backendType === 'llama_cpp'
|
||||
? 'llama-cpp'
|
||||
: backendType === 'mlx_lm'
|
||||
? 'mlx'
|
||||
: backendType === 'vllm'
|
||||
? 'vllm'
|
||||
: null
|
||||
|
||||
if (!backendKey) {
|
||||
return null
|
||||
}
|
||||
|
||||
const backendConfig = config.backends[backendKey as keyof typeof config.backends]
|
||||
|
||||
if (!backendConfig) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
command: backendConfig.command || '',
|
||||
dockerEnabled: backendConfig.docker?.enabled ?? false,
|
||||
dockerImage: backendConfig.docker?.image || '',
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user