fix: provider proxy_url set null when disabled
This commit is contained in:
@@ -12,6 +12,7 @@ export interface FormData {
|
|||||||
api_key: string;
|
api_key: string;
|
||||||
proxy_url: string;
|
proxy_url: string;
|
||||||
proxy_timeout: number;
|
proxy_timeout: number;
|
||||||
|
proxy_enabled?: boolean;
|
||||||
config: {
|
config: {
|
||||||
type: maasProviderType;
|
type: maasProviderType;
|
||||||
openaiCustomUrl?: string;
|
openaiCustomUrl?: string;
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ const ModelItem: React.FC<ModelItemProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleTestModel = async () => {
|
const handleTestModel = async () => {
|
||||||
|
const proxyConfigEnabled = form.getFieldValue('proxy_enabled');
|
||||||
const res = await runTestModel({
|
const res = await runTestModel({
|
||||||
id: generateID(),
|
id: generateID(),
|
||||||
data: {
|
data: {
|
||||||
@@ -82,7 +83,9 @@ const ModelItem: React.FC<ModelItemProps> = ({
|
|||||||
api_token: generateCurrentAPIKey(
|
api_token: generateCurrentAPIKey(
|
||||||
form.getFieldValue('api_key')
|
form.getFieldValue('api_key')
|
||||||
) as string,
|
) as string,
|
||||||
proxy_url: form.getFieldValue('proxy_url') || undefined,
|
proxy_url: proxyConfigEnabled
|
||||||
|
? form.getFieldValue('proxy_url') || undefined
|
||||||
|
: null,
|
||||||
config: {
|
config: {
|
||||||
type: form.getFieldValue(['config', 'type']) || ''
|
type: form.getFieldValue(['config', 'type']) || ''
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import MetadataList from '@/components/metadata-list';
|
import MetadataList from '@/components/metadata-list';
|
||||||
import { PageAction } from '@/config';
|
import { PageAction } from '@/config';
|
||||||
import useAppUtils from '@/hooks/use-app-utils';
|
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Form } from 'antd';
|
import { Form } from 'antd';
|
||||||
import { useRef } from 'react';
|
import { useRef } from 'react';
|
||||||
@@ -15,8 +14,10 @@ const SupportedModels = () => {
|
|||||||
useQueryProviderModels();
|
useQueryProviderModels();
|
||||||
const form = Form.useFormInstance<FormData>();
|
const form = Form.useFormInstance<FormData>();
|
||||||
const modelList = Form.useWatch('models', form) || [];
|
const modelList = Form.useWatch('models', form) || [];
|
||||||
const prevAPIKeyRef = useRef<string>('');
|
const prevConfigRef = useRef<{
|
||||||
const { getRuleMessage } = useAppUtils();
|
type: string;
|
||||||
|
api_key: string;
|
||||||
|
}>({ type: '', api_key: '' });
|
||||||
const { id, action, currentData } = useFormContext();
|
const { id, action, currentData } = useFormContext();
|
||||||
|
|
||||||
const generateCurrentAPIKey = (currentAPIKey: string) => {
|
const generateCurrentAPIKey = (currentAPIKey: string) => {
|
||||||
@@ -36,15 +37,31 @@ const SupportedModels = () => {
|
|||||||
return 0;
|
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) => {
|
const handleOpenChange = async (open: boolean) => {
|
||||||
try {
|
try {
|
||||||
await form.validateFields(['api_key', ['config', 'type']]);
|
await form.validateFields(['api_key', ['config', 'type']]);
|
||||||
|
|
||||||
const currentAPIKey = form.getFieldValue('api_key') || '';
|
const currentAPIKey = form.getFieldValue('api_key') || '';
|
||||||
|
const configType = form.getFieldValue(['config', 'type']);
|
||||||
|
|
||||||
// Avoid repeated requests with the same API key
|
// Avoid repeated requests with the same API key
|
||||||
if (open && prevAPIKeyRef.current !== currentAPIKey && currentAPIKey) {
|
if (
|
||||||
prevAPIKeyRef.current = currentAPIKey;
|
open &&
|
||||||
|
checkConfigChange({ type: configType, api_key: currentAPIKey })
|
||||||
|
) {
|
||||||
|
prevConfigRef.current = {
|
||||||
|
type: configType,
|
||||||
|
api_key: currentAPIKey
|
||||||
|
};
|
||||||
fetchProviderModels({
|
fetchProviderModels({
|
||||||
id: generateID(),
|
id: generateID(),
|
||||||
data: {
|
data: {
|
||||||
@@ -57,7 +74,11 @@ const SupportedModels = () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} 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}
|
loading={dataSource.loading}
|
||||||
loadend={dataSource.loadend}
|
loadend={dataSource.loadend}
|
||||||
dataSource={dataSource.dataList}
|
dataSource={dataSource.dataList}
|
||||||
image={<IconFont type="icon-extension-outline" />}
|
image={<IconFont type="icon-captive_portal" />}
|
||||||
filters={_.omit(queryParams, ['sort_by'])}
|
filters={_.omit(queryParams, ['sort_by'])}
|
||||||
noFoundText={intl.formatMessage({
|
noFoundText={intl.formatMessage({
|
||||||
id: 'noresult.routes.nofound'
|
id: 'noresult.routes.nofound'
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ export default function useChatCompletion(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const deltaReasoningContent =
|
const deltaReasoningContent =
|
||||||
_.get(chunk, 'choices.0.delta.reasoning_content', '') === null
|
_.get(chunk, 'choices.0.delta.reasoning_content', '') ||
|
||||||
? ''
|
_.get(chunk, 'choices.0.delta.reasoning', '') ||
|
||||||
: _.get(chunk, 'choices.0.delta.reasoning_content', '');
|
'';
|
||||||
|
|
||||||
const deltaContent =
|
const deltaContent =
|
||||||
_.get(chunk, 'choices.0.delta.content', '') === null
|
_.get(chunk, 'choices.0.delta.content', '') === null
|
||||||
|
|||||||
Reference in New Issue
Block a user