| const { eventEmitter } = useEventEmitterContextContext() | const { eventEmitter } = useEventEmitterContextContext() | ||||
| const updateModelProviders = useUpdateModelProviders() | const updateModelProviders = useUpdateModelProviders() | ||||
| const updateModelList = useUpdateModelList() | const updateModelList = useUpdateModelList() | ||||
| const handleRefreshModel = useCallback((provider: ModelProvider, configurationMethod: ConfigurationMethodEnum, CustomConfigurationModelFixedFields?: CustomConfigurationModelFixedFields) => { | |||||
| const handleRefreshModel = useCallback(( | |||||
| provider: ModelProvider, | |||||
| CustomConfigurationModelFixedFields?: CustomConfigurationModelFixedFields, | |||||
| refreshModelList?: boolean, | |||||
| ) => { | |||||
| updateModelProviders() | updateModelProviders() | ||||
| provider.supported_model_types.forEach((type) => { | provider.supported_model_types.forEach((type) => { | ||||
| updateModelList(type) | updateModelList(type) | ||||
| }) | }) | ||||
| if (configurationMethod === ConfigurationMethodEnum.customizableModel | |||||
| && provider.custom_configuration.status === CustomConfigurationStatusEnum.active) { | |||||
| if (refreshModelList && provider.custom_configuration.status === CustomConfigurationStatusEnum.active) { | |||||
| eventEmitter?.emit({ | eventEmitter?.emit({ | ||||
| type: UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST, | type: UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST, | ||||
| payload: provider.provider, | payload: provider.provider, |
| type: 'success', | type: 'success', | ||||
| message: t('common.api.actionSuccess'), | message: t('common.api.actionSuccess'), | ||||
| }) | }) | ||||
| handleRefreshModel(provider, configurationMethod, undefined) | |||||
| handleRefreshModel(provider, undefined, true) | |||||
| } | } | ||||
| finally { | finally { | ||||
| handleSetDoingAction(false) | handleSetDoingAction(false) | ||||
| type: 'success', | type: 'success', | ||||
| message: t('common.api.actionSuccess'), | message: t('common.api.actionSuccess'), | ||||
| }) | }) | ||||
| handleRefreshModel(provider, configurationMethod, undefined) | |||||
| handleRefreshModel(provider, undefined, true) | |||||
| onRemove?.(pendingOperationCredentialId.current ?? '') | onRemove?.(pendingOperationCredentialId.current ?? '') | ||||
| closeConfirmDelete() | closeConfirmDelete() | ||||
| } | } | ||||
| if (res.result === 'success') { | if (res.result === 'success') { | ||||
| notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') }) | notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') }) | ||||
| handleRefreshModel(provider, configurationMethod, undefined) | |||||
| handleRefreshModel(provider, undefined, !payload.credential_id) | |||||
| } | } | ||||
| } | } | ||||
| finally { | finally { |
| ) | ) | ||||
| if (res.result === 'success') { | if (res.result === 'success') { | ||||
| notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') }) | notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') }) | ||||
| handleRefreshModel(provider, configurateMethod, currentCustomConfigurationModelFixedFields) | |||||
| handleRefreshModel(provider, currentCustomConfigurationModelFixedFields, false) | |||||
| onSave?.(provider.provider) | onSave?.(provider.provider) | ||||
| onClose?.() | onClose?.() | ||||
| } | } |