mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-05-06 18:22:44 +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,
|
||||
"api_format": provider.api_format,
|
||||
"base_url": provider.base_url,
|
||||
"api_key": provider.api_key,
|
||||
"has_api_key": bool(provider.api_key),
|
||||
"logo_url": provider.logo_url,
|
||||
"extra_config": provider.extra_config or {},
|
||||
"created_at": provider.created_at,
|
||||
|
||||
@@ -13,8 +13,9 @@ export interface AIProviderPayload {
|
||||
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;
|
||||
has_api_key: boolean;
|
||||
extra_config: Record<string, unknown>;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
|
||||
@@ -295,7 +295,7 @@ export default function AiSettingsTab() {
|
||||
identifier: existing.identifier,
|
||||
api_format: existing.api_format,
|
||||
base_url: existing.base_url ?? undefined,
|
||||
api_key: existing.api_key ?? undefined,
|
||||
api_key: '',
|
||||
logo_url: existing.logo_url ?? undefined,
|
||||
provider_type: existing.provider_type ?? undefined,
|
||||
});
|
||||
@@ -345,10 +345,12 @@ export default function AiSettingsTab() {
|
||||
identifier: (values.identifier || '').trim(),
|
||||
api_format: values.api_format,
|
||||
base_url: trimmedBaseUrl ? trimmedBaseUrl : null,
|
||||
api_key: trimmedApiKey ? trimmedApiKey : null,
|
||||
logo_url: trimmedLogoUrl ? trimmedLogoUrl : null,
|
||||
provider_type: trimmedProviderType ? trimmedProviderType : null,
|
||||
};
|
||||
if (trimmedApiKey) {
|
||||
payload.api_key = trimmedApiKey;
|
||||
}
|
||||
try {
|
||||
if (providerModal.editing) {
|
||||
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') }]}>
|
||||
<Input placeholder="https://" />
|
||||
</Form.Item>
|
||||
<Form.Item name="api_key" label={t('API Key')}>
|
||||
<Input placeholder={t('Optional, can also be provided per request')} />
|
||||
<Form.Item
|
||||
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 name="logo_url" label={t('Logo URL')}>
|
||||
<Input placeholder="https://" />
|
||||
|
||||
Reference in New Issue
Block a user