mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-09-05 23:57:19 +08:00
feat: update AIProvider structure to include has_api_key and adjust API key handling in settings
This commit is contained in:
@@ -140,7 +140,7 @@ def serialize_provider(provider: AIProvider) -> Dict[str, Any]:
|
|||||||
"provider_type": provider.provider_type,
|
"provider_type": provider.provider_type,
|
||||||
"api_format": provider.api_format,
|
"api_format": provider.api_format,
|
||||||
"base_url": provider.base_url,
|
"base_url": provider.base_url,
|
||||||
"api_key": provider.api_key,
|
"has_api_key": bool(provider.api_key),
|
||||||
"logo_url": provider.logo_url,
|
"logo_url": provider.logo_url,
|
||||||
"extra_config": provider.extra_config or {},
|
"extra_config": provider.extra_config or {},
|
||||||
"created_at": provider.created_at,
|
"created_at": provider.created_at,
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ export interface AIProviderPayload {
|
|||||||
extra_config?: Record<string, unknown> | null;
|
extra_config?: Record<string, unknown> | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AIProvider extends Omit<AIProviderPayload, 'extra_config'> {
|
export interface AIProvider extends Omit<AIProviderPayload, 'extra_config' | 'api_key'> {
|
||||||
id: number;
|
id: number;
|
||||||
|
has_api_key: boolean;
|
||||||
extra_config: Record<string, unknown>;
|
extra_config: Record<string, unknown>;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ export default function AiSettingsTab() {
|
|||||||
identifier: existing.identifier,
|
identifier: existing.identifier,
|
||||||
api_format: existing.api_format,
|
api_format: existing.api_format,
|
||||||
base_url: existing.base_url ?? undefined,
|
base_url: existing.base_url ?? undefined,
|
||||||
api_key: existing.api_key ?? undefined,
|
api_key: '',
|
||||||
logo_url: existing.logo_url ?? undefined,
|
logo_url: existing.logo_url ?? undefined,
|
||||||
provider_type: existing.provider_type ?? undefined,
|
provider_type: existing.provider_type ?? undefined,
|
||||||
});
|
});
|
||||||
@@ -345,10 +345,12 @@ export default function AiSettingsTab() {
|
|||||||
identifier: (values.identifier || '').trim(),
|
identifier: (values.identifier || '').trim(),
|
||||||
api_format: values.api_format,
|
api_format: values.api_format,
|
||||||
base_url: trimmedBaseUrl ? trimmedBaseUrl : null,
|
base_url: trimmedBaseUrl ? trimmedBaseUrl : null,
|
||||||
api_key: trimmedApiKey ? trimmedApiKey : null,
|
|
||||||
logo_url: trimmedLogoUrl ? trimmedLogoUrl : null,
|
logo_url: trimmedLogoUrl ? trimmedLogoUrl : null,
|
||||||
provider_type: trimmedProviderType ? trimmedProviderType : null,
|
provider_type: trimmedProviderType ? trimmedProviderType : null,
|
||||||
};
|
};
|
||||||
|
if (trimmedApiKey) {
|
||||||
|
payload.api_key = trimmedApiKey;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (providerModal.editing) {
|
if (providerModal.editing) {
|
||||||
await updateProvider(providerModal.editing.id, payload);
|
await updateProvider(providerModal.editing.id, payload);
|
||||||
@@ -1080,8 +1082,28 @@ export default function AiSettingsTab() {
|
|||||||
<Form.Item name="base_url" label={t('Base URL')} rules={[{ required: true, message: t('Enter base url') }]}>
|
<Form.Item name="base_url" label={t('Base URL')} rules={[{ required: true, message: t('Enter base url') }]}>
|
||||||
<Input placeholder="https://" />
|
<Input placeholder="https://" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="api_key" label={t('API Key')}>
|
<Form.Item
|
||||||
<Input placeholder={t('Optional, can also be provided per request')} />
|
name="api_key"
|
||||||
|
label={(
|
||||||
|
<Space size={8}>
|
||||||
|
{t('API Key')}
|
||||||
|
{providerModal.editing ? (
|
||||||
|
<Tag color={providerModal.editing.has_api_key ? 'green' : 'default'}>
|
||||||
|
{providerModal.editing.has_api_key ? '已设置' : '未设置'}
|
||||||
|
</Tag>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Input.Password
|
||||||
|
placeholder={
|
||||||
|
providerModal.editing
|
||||||
|
? '留空不更新,填写将覆盖'
|
||||||
|
: t('Optional, can also be provided per request')
|
||||||
|
}
|
||||||
|
autoComplete="new-password"
|
||||||
|
visibilityToggle={false}
|
||||||
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="logo_url" label={t('Logo URL')}>
|
<Form.Item name="logo_url" label={t('Logo URL')}>
|
||||||
<Input placeholder="https://" />
|
<Input placeholder="https://" />
|
||||||
|
|||||||
Reference in New Issue
Block a user