diff --git a/src/pages/maas-provider/config/types.ts b/src/pages/maas-provider/config/types.ts index 427cfc6b..6d0c17ed 100644 --- a/src/pages/maas-provider/config/types.ts +++ b/src/pages/maas-provider/config/types.ts @@ -12,6 +12,7 @@ export interface FormData { api_key: string; proxy_url: string; proxy_timeout: number; + proxy_enabled?: boolean; config: { type: maasProviderType; openaiCustomUrl?: string; diff --git a/src/pages/maas-provider/forms/model-item.tsx b/src/pages/maas-provider/forms/model-item.tsx index 21bdadf8..aae73e8d 100644 --- a/src/pages/maas-provider/forms/model-item.tsx +++ b/src/pages/maas-provider/forms/model-item.tsx @@ -75,6 +75,7 @@ const ModelItem: React.FC = ({ }; const handleTestModel = async () => { + const proxyConfigEnabled = form.getFieldValue('proxy_enabled'); const res = await runTestModel({ id: generateID(), data: { @@ -82,7 +83,9 @@ const ModelItem: React.FC = ({ api_token: generateCurrentAPIKey( form.getFieldValue('api_key') ) as string, - proxy_url: form.getFieldValue('proxy_url') || undefined, + proxy_url: proxyConfigEnabled + ? form.getFieldValue('proxy_url') || undefined + : null, config: { type: form.getFieldValue(['config', 'type']) || '' } diff --git a/src/pages/maas-provider/forms/supported-models.tsx b/src/pages/maas-provider/forms/supported-models.tsx index cbb21366..0a3077d1 100644 --- a/src/pages/maas-provider/forms/supported-models.tsx +++ b/src/pages/maas-provider/forms/supported-models.tsx @@ -1,6 +1,5 @@ import MetadataList from '@/components/metadata-list'; import { PageAction } from '@/config'; -import useAppUtils from '@/hooks/use-app-utils'; import { useIntl } from '@umijs/max'; import { Form } from 'antd'; import { useRef } from 'react'; @@ -15,8 +14,10 @@ const SupportedModels = () => { useQueryProviderModels(); const form = Form.useFormInstance(); const modelList = Form.useWatch('models', form) || []; - const prevAPIKeyRef = useRef(''); - const { getRuleMessage } = useAppUtils(); + const prevConfigRef = useRef<{ + type: string; + api_key: string; + }>({ type: '', api_key: '' }); const { id, action, currentData } = useFormContext(); const generateCurrentAPIKey = (currentAPIKey: string) => { @@ -36,15 +37,31 @@ const SupportedModels = () => { return 0; }; + const checkConfigChange = (current: { type: string; api_key: string }) => { + return ( + (current.type !== prevConfigRef.current.type || + current.api_key !== prevConfigRef.current.api_key) && + current.api_key && + current.type + ); + }; + const handleOpenChange = async (open: boolean) => { try { await form.validateFields(['api_key', ['config', 'type']]); const currentAPIKey = form.getFieldValue('api_key') || ''; + const configType = form.getFieldValue(['config', 'type']); // Avoid repeated requests with the same API key - if (open && prevAPIKeyRef.current !== currentAPIKey && currentAPIKey) { - prevAPIKeyRef.current = currentAPIKey; + if ( + open && + checkConfigChange({ type: configType, api_key: currentAPIKey }) + ) { + prevConfigRef.current = { + type: configType, + api_key: currentAPIKey + }; fetchProviderModels({ id: generateID(), data: { @@ -57,7 +74,11 @@ const SupportedModels = () => { }); } } catch (error) { - prevAPIKeyRef.current = ''; + prevConfigRef.current = { + type: '', + api_key: '' + }; + // If validation fails, reset the provider model list to avoid confusion } }; diff --git a/src/pages/model-routes/index.tsx b/src/pages/model-routes/index.tsx index c3e7c67c..7f897624 100644 --- a/src/pages/model-routes/index.tsx +++ b/src/pages/model-routes/index.tsx @@ -318,7 +318,7 @@ const ModelRoutes: React.FC = () => { loading={dataSource.loading} loadend={dataSource.loadend} dataSource={dataSource.dataList} - image={} + image={} filters={_.omit(queryParams, ['sort_by'])} noFoundText={intl.formatMessage({ id: 'noresult.routes.nofound' diff --git a/src/pages/playground/hooks/use-chat-completion.ts b/src/pages/playground/hooks/use-chat-completion.ts index dafa587b..5a001f32 100644 --- a/src/pages/playground/hooks/use-chat-completion.ts +++ b/src/pages/playground/hooks/use-chat-completion.ts @@ -53,9 +53,9 @@ export default function useChatCompletion( } const deltaReasoningContent = - _.get(chunk, 'choices.0.delta.reasoning_content', '') === null - ? '' - : _.get(chunk, 'choices.0.delta.reasoning_content', ''); + _.get(chunk, 'choices.0.delta.reasoning_content', '') || + _.get(chunk, 'choices.0.delta.reasoning', '') || + ''; const deltaContent = _.get(chunk, 'choices.0.delta.content', '') === null