mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-15 22:06:52 +08:00
feat: multiple model configuration (#2196)
Co-authored-by: Joel <iamjoel007@gmail.com>
This commit is contained in:
54
web/app/components/app/configuration/debug/hooks.tsx
Normal file
54
web/app/components/app/configuration/debug/hooks.tsx
Normal file
@@ -0,0 +1,54 @@
|
||||
import {
|
||||
useCallback,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react'
|
||||
import type {
|
||||
DebugWithSingleOrMultipleModelConfigs,
|
||||
ModelAndParameter,
|
||||
} from './types'
|
||||
|
||||
export const useDebugWithSingleOrMultipleModel = (appId: string) => {
|
||||
const localeDebugWithSingleOrMultipleModelConfigs = localStorage.getItem('app-debug-with-single-or-multiple-models')
|
||||
|
||||
const debugWithSingleOrMultipleModelConfigs = useRef<DebugWithSingleOrMultipleModelConfigs>({})
|
||||
|
||||
if (localeDebugWithSingleOrMultipleModelConfigs) {
|
||||
try {
|
||||
debugWithSingleOrMultipleModelConfigs.current = JSON.parse(localeDebugWithSingleOrMultipleModelConfigs) || {}
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
const [
|
||||
debugWithMultipleModel,
|
||||
setDebugWithMultipleModel,
|
||||
] = useState(debugWithSingleOrMultipleModelConfigs.current[appId]?.multiple || false)
|
||||
|
||||
const [
|
||||
multipleModelConfigs,
|
||||
setMultipleModelConfigs,
|
||||
] = useState(debugWithSingleOrMultipleModelConfigs.current[appId]?.configs || [])
|
||||
|
||||
const handleMultipleModelConfigsChange = useCallback((
|
||||
multiple: boolean,
|
||||
modelConfigs: ModelAndParameter[],
|
||||
) => {
|
||||
const value = {
|
||||
multiple,
|
||||
configs: modelConfigs,
|
||||
}
|
||||
debugWithSingleOrMultipleModelConfigs.current[appId] = value
|
||||
localStorage.setItem('app-debug-with-single-or-multiple-models', JSON.stringify(debugWithSingleOrMultipleModelConfigs.current))
|
||||
setDebugWithMultipleModel(value.multiple)
|
||||
setMultipleModelConfigs(value.configs)
|
||||
}, [appId])
|
||||
|
||||
return {
|
||||
debugWithMultipleModel,
|
||||
multipleModelConfigs,
|
||||
handleMultipleModelConfigsChange,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user