From 766ac3e255147cea3219df1f1c718ecbdeb529ce Mon Sep 17 00:00:00 2001 From: JzoNg Date: Wed, 30 Oct 2024 13:43:02 +0800 Subject: [PATCH] model list of provider --- .../account-setting/model-provider-page/index.tsx | 2 +- .../provider-added-card/credential-panel.tsx | 2 +- .../provider-added-card/index.tsx | 12 ++++++------ .../provider-added-card/model-list.tsx | 2 +- .../model-load-balancing-modal.tsx | 4 ++-- web/context/modal-context.tsx | 8 ++++---- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/web/app/components/header/account-setting/model-provider-page/index.tsx b/web/app/components/header/account-setting/model-provider-page/index.tsx index 6e441c3dc9..e3542bc327 100644 --- a/web/app/components/header/account-setting/model-provider-page/index.tsx +++ b/web/app/components/header/account-setting/model-provider-page/index.tsx @@ -91,7 +91,7 @@ const ModelProviderPage = () => { if (configurationMethod === ConfigurationMethodEnum.customizableModel && provider.custom_configuration.status === CustomConfigurationStatusEnum.active) { eventEmitter?.emit({ type: UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST, - payload: provider.provider, + payload: provider, } as any) if (CustomConfigurationModelFixedFields?.__model_type) diff --git a/web/app/components/header/account-setting/model-provider-page/provider-added-card/credential-panel.tsx b/web/app/components/header/account-setting/model-provider-page/provider-added-card/credential-panel.tsx index e7f865f198..ac82dce3bf 100644 --- a/web/app/components/header/account-setting/model-provider-page/provider-added-card/credential-panel.tsx +++ b/web/app/components/header/account-setting/model-provider-page/provider-added-card/credential-panel.tsx @@ -57,7 +57,7 @@ const CredentialPanel: FC = ({ eventEmitter?.emit({ type: UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST, - payload: provider.provider, + payload: provider, } as any) } } diff --git a/web/app/components/header/account-setting/model-provider-page/provider-added-card/index.tsx b/web/app/components/header/account-setting/model-provider-page/provider-added-card/index.tsx index 46ef6add24..7b7702d6b8 100644 --- a/web/app/components/header/account-setting/model-provider-page/provider-added-card/index.tsx +++ b/web/app/components/header/account-setting/model-provider-page/provider-added-card/index.tsx @@ -52,12 +52,12 @@ const ProviderAddedCard: FC = ({ const showQuota = systemConfig.enabled && [...MODEL_PROVIDER_QUOTA_GET_PAID].includes(provider.provider) && !IS_CE_EDITION const showCredential = configurationMethods.includes(ConfigurationMethodEnum.predefinedModel) && isCurrentWorkspaceManager - const getModelList = async (providerName: string) => { + const getModelList = async (pluginID: string, providerName: string) => { if (loading) return try { setLoading(true) - const modelsData = await fetchModelProviderModelList(`/workspaces/current/model-providers/${providerName}/models`) + const modelsData = await fetchModelProviderModelList(`/workspaces/current/model-providers/${pluginID}/${providerName}/models`) setModelList(modelsData.data) setCollapsed(false) setFetched(true) @@ -72,12 +72,12 @@ const ProviderAddedCard: FC = ({ return } - getModelList(provider.provider) + getModelList(provider.plugin_id, provider.provider) } eventEmitter?.useSubscription((v: any) => { - if (v?.type === UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST && v.payload === provider.provider) - getModelList(v.payload) + if (v?.type === UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST && v.payload.provider === provider.provider) + getModelList(v.payload.plugin_id, v.payload.provider) }) return ( @@ -172,7 +172,7 @@ const ProviderAddedCard: FC = ({ models={modelList} onCollapse={() => setCollapsed(true)} onConfig={currentCustomConfigurationModelFixedFields => onOpenModal(ConfigurationMethodEnum.customizableModel, currentCustomConfigurationModelFixedFields)} - onChange={(provider: string) => getModelList(provider)} + onChange={(provider: ModelProvider) => getModelList(provider.plugin_id, provider.provider)} /> ) } diff --git a/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-list.tsx b/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-list.tsx index 5e70a0def1..3b6a4ccbe5 100644 --- a/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-list.tsx +++ b/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-list.tsx @@ -23,7 +23,7 @@ type ModelListProps = { models: ModelItem[] onCollapse: () => void onConfig: (currentCustomConfigurationModelFixedFields?: CustomConfigurationModelFixedFields) => void - onChange?: (provider: string) => void + onChange?: (provider: ModelProvider) => void } const ModelList: FC = ({ provider, diff --git a/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-load-balancing-modal.tsx b/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-load-balancing-modal.tsx index edbb4665e9..84af503af4 100644 --- a/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-load-balancing-modal.tsx +++ b/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-load-balancing-modal.tsx @@ -19,7 +19,7 @@ export type ModelLoadBalancingModalProps = { model: ModelItem open?: boolean onClose?: () => void - onSave?: (provider: string) => void + onSave?: (provider: ModelProvider) => void } // model balancing config modal @@ -94,7 +94,7 @@ const ModelLoadBalancingModal = ({ provider, model, open = false, onClose, onSav if (res.result === 'success') { notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') }) mutate() - onSave?.(provider.provider) + onSave?.(provider) onClose?.() } } diff --git a/web/context/modal-context.tsx b/web/context/modal-context.tsx index 60d53f1e98..c8383ae336 100644 --- a/web/context/modal-context.tsx +++ b/web/context/modal-context.tsx @@ -32,7 +32,7 @@ import OpeningSettingModal from '@/app/components/base/features/new-feature-pane import type { OpeningStatement } from '@/app/components/base/features/types' import type { InputVar } from '@/app/components/workflow/types' -export interface ModalState { +export type ModalState = { payload: T onCancelCallback?: () => void onSaveCallback?: (newPayload: T) => void @@ -43,7 +43,7 @@ export interface ModalState { datasetBindings?: { id: string; name: string }[] } -export interface ModelModalType { +export type ModelModalType = { currentProvider: ModelProvider currentConfigurationMethod: ConfigurationMethodEnum currentCustomConfigurationModelFixedFields?: CustomConfigurationModelFixedFields @@ -52,7 +52,7 @@ export type LoadBalancingEntryModalType = ModelModalType & { entry?: ModelLoadBalancingConfigEntry index?: number } -export interface ModalContextState { +export type ModalContextState = { setShowAccountSettingModal: Dispatch | null>> setShowApiBasedExtensionModal: Dispatch | null>> setShowModerationSettingModal: Dispatch | null>> @@ -90,7 +90,7 @@ export const useModalContext = () => useContext(ModalContext) export const useModalContextSelector = (selector: (state: ModalContextState) => T): T => useContextSelector(ModalContext, selector) -interface ModalContextProviderProps { +type ModalContextProviderProps = { children: React.ReactNode } export const ModalContextProvider = ({