feat: added api connection validation and provider configuration

This commit is contained in:
kangfenmao 2024-11-12 13:56:03 +08:00
parent 29d6c4be18
commit 12a2c8c86d
6 changed files with 19 additions and 5 deletions

View File

@ -378,7 +378,8 @@
"delete.title": "Delete Provider",
"delete.content": "Are you sure you want to delete this provider?",
"edit.name": "Provider Name",
"edit.name.placeholder": "Example: OpenAI"
"edit.name.placeholder": "Example: OpenAI",
"no_models": "Please add models first before checking the API connection"
}
},
"translate": {

View File

@ -366,7 +366,8 @@
"delete.title": "删除提供商",
"delete.content": "确定要删除此模型提供商吗?",
"edit.name": "模型提供商名称",
"edit.name.placeholder": "例如 OpenAI"
"edit.name.placeholder": "例如 OpenAI",
"no_models": "请先添加模型再检查 API 连接"
}
},
"translate": {

View File

@ -366,7 +366,8 @@
"delete.title": "刪除提供者",
".delete.content": "確定要刪除此提供者嗎?",
"edit.name": "提供者名稱",
"edit.name.placeholder": "例如OpenAI"
"edit.name.placeholder": "例如OpenAI",
"no_models": "請先添加模型再檢查 API 連接"
}
},
"translate": {

View File

@ -65,6 +65,16 @@ const ProviderSetting: FC<Props> = ({ provider: _provider }) => {
const onAddModel = () => AddModelPopup.show({ title: t('settings.models.add.add_model'), provider })
const onCheckApi = async () => {
if (isEmpty(models)) {
window.message.error({
key: 'no-models',
style: { marginTop: '3vh' },
duration: 5,
content: t('settings.provider.no_models')
})
return
}
if (apiKey.includes(',')) {
const keys = apiKey
.split(',')
@ -149,7 +159,7 @@ const ProviderSetting: FC<Props> = ({ provider: _provider }) => {
type="password"
autoFocus={provider.enabled && apiKey === ''}
/>
<Button type={apiValid ? 'primary' : 'default'} ghost={apiValid} onClick={onCheckApi}>
<Button type={apiValid ? 'primary' : 'default'} ghost={apiValid} onClick={onCheckApi} disabled={!apiHost}>
{apiChecking ? <LoadingOutlined spin /> : apiValid ? <CheckOutlined /> : t('settings.provider.check')}
</Button>
</Space.Compact>

View File

@ -46,6 +46,7 @@ const ProvidersList: FC = () => {
enabled: true,
isSystem: false
} as Provider
addProvider(provider)
setSelectedProvider(provider)
}

View File

@ -339,7 +339,7 @@ const settingsSlice = createSlice({
state.providers = action.payload
},
addProvider: (state, action: PayloadAction<Provider>) => {
state.providers.push(action.payload)
state.providers.unshift(action.payload)
},
removeProvider: (state, action: PayloadAction<Provider>) => {
state.providers = state.providers.filter((p) => p.id !== action.payload.id)