fix: provider proxy_url set null when disabled
This commit is contained in:
@@ -12,6 +12,7 @@ export interface FormData {
|
||||
api_key: string;
|
||||
proxy_url: string;
|
||||
proxy_timeout: number;
|
||||
proxy_enabled?: boolean;
|
||||
config: {
|
||||
type: maasProviderType;
|
||||
openaiCustomUrl?: string;
|
||||
|
||||
@@ -75,6 +75,7 @@ const ModelItem: React.FC<ModelItemProps> = ({
|
||||
};
|
||||
|
||||
const handleTestModel = async () => {
|
||||
const proxyConfigEnabled = form.getFieldValue('proxy_enabled');
|
||||
const res = await runTestModel({
|
||||
id: generateID(),
|
||||
data: {
|
||||
@@ -82,7 +83,9 @@ const ModelItem: React.FC<ModelItemProps> = ({
|
||||
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']) || ''
|
||||
}
|
||||
|
||||
@@ -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<FormData>();
|
||||
const modelList = Form.useWatch('models', form) || [];
|
||||
const prevAPIKeyRef = useRef<string>('');
|
||||
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
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -318,7 +318,7 @@ const ModelRoutes: React.FC = () => {
|
||||
loading={dataSource.loading}
|
||||
loadend={dataSource.loadend}
|
||||
dataSource={dataSource.dataList}
|
||||
image={<IconFont type="icon-extension-outline" />}
|
||||
image={<IconFont type="icon-captive_portal" />}
|
||||
filters={_.omit(queryParams, ['sort_by'])}
|
||||
noFoundText={intl.formatMessage({
|
||||
id: 'noresult.routes.nofound'
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user