fix: add custom config in get-models, test-model
This commit is contained in:
@@ -54,7 +54,7 @@ const ModelItem: React.FC<ModelItemProps> = ({
|
||||
const intl = useIntl();
|
||||
const form = Form.useFormInstance<FormData>();
|
||||
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<ModelItemProps> = ({
|
||||
|
||||
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<ModelItemProps> = ({
|
||||
? 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
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user