mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 01:48:04 +08:00
chore: avoid unnecessary loading for the model selector in agent node
This commit is contained in:
@ -67,42 +67,71 @@ const AgentModelTrigger: FC<AgentModelTriggerProps> = ({
|
|||||||
}
|
}
|
||||||
}, [modelProviders, providerName])
|
}, [modelProviders, providerName])
|
||||||
const [pluginInfo, setPluginInfo] = useState<PluginInfoFromMarketPlace | null>(null)
|
const [pluginInfo, setPluginInfo] = useState<PluginInfoFromMarketPlace | null>(null)
|
||||||
const [isPluginChecked, setIsPluginChecked] = useState(false)
|
const [isPluginChecked, setIsPluginChecked] = useState(!!modelProvider)
|
||||||
const [installed, setInstalled] = useState(false)
|
const [installed, setInstalled] = useState(false)
|
||||||
const [inModelList, setInModelList] = useState(false)
|
const [inModelList, setInModelList] = useState(false)
|
||||||
const invalidateInstalledPluginList = useInvalidateInstalledPluginList()
|
const invalidateInstalledPluginList = useInvalidateInstalledPluginList()
|
||||||
const handleOpenModal = useModelModalHandler()
|
const handleOpenModal = useModelModalHandler()
|
||||||
|
const checkPluginInfo = useMemo(async () => {
|
||||||
|
if (!providerName || !modelId)
|
||||||
|
return null
|
||||||
|
|
||||||
|
const parts = providerName.split('/')
|
||||||
|
try {
|
||||||
|
const pluginInfo = await fetchPluginInfoFromMarketPlace({
|
||||||
|
org: parts[0],
|
||||||
|
name: parts[1],
|
||||||
|
})
|
||||||
|
if (pluginInfo.data.plugin.category === PluginType.model)
|
||||||
|
return pluginInfo.data.plugin
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
// pass
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}, [providerName, modelId])
|
||||||
|
|
||||||
|
const checkModelList = useMemo(async () => {
|
||||||
|
if (!modelId || !currentProvider)
|
||||||
|
return false
|
||||||
|
|
||||||
|
try {
|
||||||
|
const modelsData = await fetchModelProviderModelList(
|
||||||
|
`/workspaces/current/model-providers/${currentProvider?.provider}/models`,
|
||||||
|
)
|
||||||
|
return !!modelsData.data.find(item => item.model === modelId)
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
// pass
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}, [modelId, currentProvider])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
let isSubscribed = true
|
||||||
if (modelId && currentProvider) {
|
|
||||||
try {
|
const initializeChecks = async () => {
|
||||||
const modelsData = await fetchModelProviderModelList(`/workspaces/current/model-providers/${currentProvider?.provider}/models`)
|
if (!isPluginChecked) {
|
||||||
if (modelId && modelsData.data.find(item => item.model === modelId))
|
const [pluginResult, modelListResult] = await Promise.all([
|
||||||
setInModelList(true)
|
checkPluginInfo,
|
||||||
}
|
checkModelList,
|
||||||
catch (error) {
|
])
|
||||||
// pass
|
|
||||||
|
if (isSubscribed) {
|
||||||
|
if (pluginResult)
|
||||||
|
setPluginInfo(pluginResult)
|
||||||
|
setInModelList(modelListResult)
|
||||||
|
setIsPluginChecked(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (providerName) {
|
}
|
||||||
const parts = providerName.split('/')
|
|
||||||
const org = parts[0]
|
initializeChecks()
|
||||||
const name = parts[1]
|
|
||||||
try {
|
return () => {
|
||||||
const pluginInfo = await fetchPluginInfoFromMarketPlace({ org, name })
|
isSubscribed = false
|
||||||
if (pluginInfo.data.plugin.category === PluginType.model)
|
}
|
||||||
setPluginInfo(pluginInfo.data.plugin)
|
}, [checkPluginInfo, checkModelList, isPluginChecked, modelId, currentProvider])
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
// pass
|
|
||||||
}
|
|
||||||
setIsPluginChecked(true)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
setIsPluginChecked(true)
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
}, [providerName, modelId, currentProvider])
|
|
||||||
|
|
||||||
if (modelId && !isPluginChecked)
|
if (modelId && !isPluginChecked)
|
||||||
return <Loading />
|
return <Loading />
|
||||||
|
|||||||
Reference in New Issue
Block a user