fix: api_key format
This commit is contained in:
@@ -18,7 +18,16 @@ export interface FormData {
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
export interface MaasProviderItem extends FormData {
|
||||
export interface MaasProviderItem {
|
||||
name: string;
|
||||
description: string;
|
||||
proxy_url: string;
|
||||
proxy_timeout: number;
|
||||
config: {
|
||||
type: maasProviderType;
|
||||
openaiCustomUrl?: string;
|
||||
[key: string]: any;
|
||||
};
|
||||
id: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
@@ -28,4 +37,5 @@ export interface MaasProviderItem extends FormData {
|
||||
builtin: boolean;
|
||||
provider_model_count: number;
|
||||
api_token_count: number;
|
||||
api_tokens: { hash: string }[];
|
||||
}
|
||||
|
||||
@@ -65,20 +65,33 @@ const ProviderForm: React.FC<ProviderFormProps> = forwardRef((props, ref) => {
|
||||
}
|
||||
];
|
||||
|
||||
const handleOnFinish = (values: FormData) => {
|
||||
const formatAPIKeys = (values: FormData) => {
|
||||
const apiTokens = values.api_tokens?.filter?.(
|
||||
(item) => item && item.trim() !== ''
|
||||
);
|
||||
const apiTokenList = _.concat([], values.api_key, apiTokens || []);
|
||||
if (action === PageAction.CREATE) {
|
||||
return apiTokenList.map((item: string) => ({ input: item }));
|
||||
}
|
||||
|
||||
const existingTokens = new Set(
|
||||
(currentData?.api_tokens || []).map((item: { hash: string }) => item.hash)
|
||||
);
|
||||
return apiTokenList.map((item: string) =>
|
||||
existingTokens.has(item) ? { hash: item } : { input: item }
|
||||
);
|
||||
};
|
||||
|
||||
const handleOnFinish = (values: FormData) => {
|
||||
const data = {
|
||||
..._.omit(values, ['api_key']),
|
||||
api_tokens: _.concat([], values.api_key, apiTokens || []).map(
|
||||
(item: string) => ({ input: item })
|
||||
),
|
||||
api_tokens: formatAPIKeys(values),
|
||||
config: {
|
||||
type: values.config.type,
|
||||
...yaml2Json(advanceRef.current?.getYamlValue() || '')
|
||||
},
|
||||
models: _.uniqBy(values.models, 'name')
|
||||
models: _.uniqBy(values.models, 'name'),
|
||||
clone_from_id: action === PageAction.COPY ? currentData?.id : undefined
|
||||
};
|
||||
onFinish(data);
|
||||
};
|
||||
|
||||
@@ -21,7 +21,6 @@ import {
|
||||
updateProvider
|
||||
} from './apis';
|
||||
import AddMaasProvider from './components/add-provider-modal';
|
||||
import { maasProviderOptions } from './config/providers';
|
||||
import { FormData, MaasProviderItem as ListItem } from './config/types';
|
||||
import useCreateProvider from './hooks/use-create-provider';
|
||||
import useProviderColumns from './hooks/use-provider-columns';
|
||||
@@ -57,7 +56,7 @@ const MaasProvider: React.FC = () => {
|
||||
|
||||
const handleClickDropdown = () => {
|
||||
openProviderModal(
|
||||
'create',
|
||||
PageAction.CREATE,
|
||||
intl.formatMessage({ id: 'providers.button.add' })
|
||||
);
|
||||
};
|
||||
@@ -88,7 +87,6 @@ const MaasProvider: React.FC = () => {
|
||||
};
|
||||
|
||||
const handleModalCancel = () => {
|
||||
console.log('handleModalCancel');
|
||||
closeProviderModal();
|
||||
};
|
||||
|
||||
@@ -113,7 +111,10 @@ const MaasProvider: React.FC = () => {
|
||||
openProviderModal(
|
||||
PageAction.COPY,
|
||||
intl.formatMessage({ id: 'providers.button.clone' }),
|
||||
row
|
||||
{
|
||||
...row,
|
||||
name: `${row.name}-copy`
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -156,12 +157,6 @@ const MaasProvider: React.FC = () => {
|
||||
handleSearch={handleSearch}
|
||||
handleDeleteByBatch={handleDeleteBatch}
|
||||
handleClickPrimary={handleClickDropdown}
|
||||
actionItems={maasProviderOptions.map((option) => ({
|
||||
...option,
|
||||
icon: (
|
||||
<IconFont type={option.icon as string} style={{ fontSize: 14 }} />
|
||||
)
|
||||
}))}
|
||||
></FilterBar>
|
||||
<ConfigProvider renderEmpty={renderEmpty}>
|
||||
<Table
|
||||
|
||||
Reference in New Issue
Block a user