From 200d63e5fc93d09b57a14fc4934555fc9358a2e0 Mon Sep 17 00:00:00 2001 From: jialin Date: Wed, 25 Feb 2026 10:26:10 +0800 Subject: [PATCH] fix: add custom config in get-models, test-model --- src/pages/maas-provider/forms/model-item.tsx | 10 ++++- .../maas-provider/forms/supported-models.tsx | 38 ++++++++++++------- .../hooks/use-query-provider-models.tsx | 2 +- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/pages/maas-provider/forms/model-item.tsx b/src/pages/maas-provider/forms/model-item.tsx index 91dc0ec1..eadb8101 100644 --- a/src/pages/maas-provider/forms/model-item.tsx +++ b/src/pages/maas-provider/forms/model-item.tsx @@ -54,7 +54,7 @@ const ModelItem: React.FC = ({ const intl = useIntl(); const form = Form.useFormInstance(); const { runTestModel, loading: testLoading } = useTestProviderModel(); - const { id, action, currentData } = useFormContext(); + const { id, action, currentData, getCustomConfig } = useFormContext(); const [openTip, setOpenTip] = React.useState(false); const generateCurrentAPIKey = (currentAPIKey: string) => { @@ -76,6 +76,7 @@ const ModelItem: React.FC = ({ const handleTestModel = async () => { const proxyConfigEnabled = form.getFieldValue('proxy_enabled'); + const customConfig = getCustomConfig?.(); const res = await runTestModel({ id: generateID(), data: { @@ -87,7 +88,12 @@ const ModelItem: React.FC = ({ ? form.getFieldValue('proxy_url') || null : null, config: { - type: form.getFieldValue(['config', 'type']) || '' + type: form.getFieldValue(['config', 'type']) || '', + openaiCustomUrl: + form.getFieldValue(['config', 'openaiCustomUrl']) || + customConfig?.openaiCustomUrl || + null, + ...customConfig } } }); diff --git a/src/pages/maas-provider/forms/supported-models.tsx b/src/pages/maas-provider/forms/supported-models.tsx index d8eb97c7..89b6822a 100644 --- a/src/pages/maas-provider/forms/supported-models.tsx +++ b/src/pages/maas-provider/forms/supported-models.tsx @@ -2,6 +2,7 @@ import MetadataList from '@/components/metadata-list'; import { PageAction } from '@/config'; import { useIntl } from '@umijs/max'; import { Form } from 'antd'; +import _ from 'lodash'; import { useRef } from 'react'; import { useFormContext } from '../config/form-context'; import { FormData, ProviderModel } from '../config/types'; @@ -17,7 +18,8 @@ const SupportedModels = () => { const prevConfigRef = useRef<{ type: string; api_key: string; - }>({ type: '', api_key: '' }); + openaiCustomUrl: string; + }>({ type: '', api_key: '', openaiCustomUrl: '' }); const { id, action, currentData, getCustomConfig } = useFormContext(); const generateCurrentAPIKey = (currentAPIKey: string) => { @@ -37,10 +39,13 @@ const SupportedModels = () => { return 0; }; - const checkConfigChange = (current: { type: string; api_key: string }) => { + const checkConfigChange = (current: { + type: string; + api_key: string; + openaiCustomUrl: string; + }) => { return ( - (current.type !== prevConfigRef.current.type || - current.api_key !== prevConfigRef.current.api_key) && + !_.isEqual(current, prevConfigRef.current) && current.api_key && current.type ); @@ -53,16 +58,21 @@ const SupportedModels = () => { const proxyConfigEnabled = form.getFieldValue('proxy_enabled'); const currentAPIKey = form.getFieldValue('api_key') || ''; const configType = form.getFieldValue(['config', 'type']); + const openaiCustomUrl = form.getFieldValue(['config', 'openaiCustomUrl']); + const customConfig = getCustomConfig?.(); + + const currentConfig = { + type: configType, + api_key: currentAPIKey, + openaiCustomUrl: customConfig?.openaiCustomUrl || openaiCustomUrl || '' + }; // Avoid repeated requests with the same API key - if ( - open && - checkConfigChange({ type: configType, api_key: currentAPIKey }) - ) { + if (open && checkConfigChange(currentConfig)) { prevConfigRef.current = { - type: configType, - api_key: currentAPIKey + ...currentConfig }; + fetchProviderModels({ id: generateID(), data: { @@ -73,9 +83,8 @@ const SupportedModels = () => { config: { type: form.getFieldValue(['config', 'type']) || '', openaiCustomUrl: - form.getFieldValue(['config', 'openaiCustomUrl']) || - getCustomConfig?.()?.openaiCustomUrl || - null + openaiCustomUrl || customConfig?.openaiCustomUrl || null, + ...customConfig } } }); @@ -83,7 +92,8 @@ const SupportedModels = () => { } catch (error) { prevConfigRef.current = { type: '', - api_key: '' + api_key: '', + openaiCustomUrl: '' }; // If validation fails, reset the provider model list to avoid confusion } diff --git a/src/pages/maas-provider/hooks/use-query-provider-models.tsx b/src/pages/maas-provider/hooks/use-query-provider-models.tsx index 02acd468..4654a8d8 100644 --- a/src/pages/maas-provider/hooks/use-query-provider-models.tsx +++ b/src/pages/maas-provider/hooks/use-query-provider-models.tsx @@ -87,7 +87,7 @@ export const useTestProviderModel = () => { id: number; data: { api_token: string; - config: { type: string }; + config: { type: string; [key: string]: any }; model_name: string; proxy_url: string; };