feat: added new translations and api url handling features
- Added new translation strings for API URL actions and hints. - Updated Chinese translations and added new provider API URL descriptions. - Added new translations for API URL preview and reset tip. - Added support for Open AI API settings preview and hint. - Added a new isOpenAIProvider function to handle specific provider type checks. - Added a new function to validate if a given URL has a valid non-root path.
This commit is contained in:
parent
14808649f8
commit
624230411a
@ -235,6 +235,8 @@
|
||||
"provider.docs_more_details": "for more details",
|
||||
"provider.search_placeholder": "Search model id or name",
|
||||
"provider.api.url.reset": "Reset",
|
||||
"provider.api.url.preview": "Preview: {{url}}",
|
||||
"provider.api.url.tip": "Add / at the end to force using the input address",
|
||||
"models.default_assistant_model": "Default Assistant Model",
|
||||
"models.topic_naming_model": "Topic Naming Model",
|
||||
"models.translate_model": "Translate Model",
|
||||
|
||||
@ -235,6 +235,8 @@
|
||||
"provider.docs_more_details": "获取更多详情",
|
||||
"provider.search_placeholder": "搜索模型 ID 或名称",
|
||||
"provider.api.url.reset": "重置",
|
||||
"provider.api.url.preview": "预览: {{url}}",
|
||||
"provider.api.url.tip": "结尾添加 / 强制使用输入地址",
|
||||
"models.default_assistant_model": "默认助手模型",
|
||||
"models.topic_naming_model": "话题命名模型",
|
||||
"models.translate_model": "翻译模型",
|
||||
|
||||
@ -235,6 +235,8 @@
|
||||
"provider.docs_more_details": "查看更多細節",
|
||||
"provider.search_placeholder": "搜尋模型 ID 或名稱",
|
||||
"provider.api.url.reset": "重置",
|
||||
"provider.api.url.preview": "預覽: {{url}}",
|
||||
"provider.api.url.tip": "結尾新增 / 強制使用輸入地址",
|
||||
"models.default_assistant_model": "預設助手模型",
|
||||
"models.topic_naming_model": "話題命名模型",
|
||||
"models.translate_model": "翻譯模型",
|
||||
|
||||
@ -11,6 +11,7 @@ import { getModelLogo, isVisionModel } from '@renderer/config/models'
|
||||
import { PROVIDER_CONFIG } from '@renderer/config/providers'
|
||||
import { useTheme } from '@renderer/context/ThemeProvider'
|
||||
import { useProvider } from '@renderer/hooks/useProvider'
|
||||
import { isOpenAIProvider } from '@renderer/providers/ProviderFactory'
|
||||
import { checkApi } from '@renderer/services/api'
|
||||
import { Provider } from '@renderer/types'
|
||||
import { Avatar, Button, Card, Divider, Flex, Input, Space, Switch } from 'antd'
|
||||
@ -81,6 +82,8 @@ const ProviderSetting: FC<Props> = ({ provider: _provider }) => {
|
||||
updateProvider({ ...provider, apiHost: configedApiHost })
|
||||
}
|
||||
|
||||
const hostPreview = (apiHost.endsWith('/') ? apiHost : `${apiHost}/v1/`) + 'chat/completions'
|
||||
|
||||
return (
|
||||
<SettingContainer
|
||||
style={
|
||||
@ -138,6 +141,12 @@ const ProviderSetting: FC<Props> = ({ provider: _provider }) => {
|
||||
<Button onClick={onReset}>{t('settings.provider.api.url.reset')}</Button>
|
||||
)}
|
||||
</Space.Compact>
|
||||
{isOpenAIProvider(provider) && (
|
||||
<SettingHelpTextRow style={{ justifyContent: 'space-between' }}>
|
||||
<SettingHelpText style={{ marginLeft: 6 }}>{hostPreview}</SettingHelpText>
|
||||
<SettingHelpText>{t('settings.provider.api.url.tip')}</SettingHelpText>
|
||||
</SettingHelpTextRow>
|
||||
)}
|
||||
{provider.id === 'azure-openai' && (
|
||||
<>
|
||||
<SettingSubtitle>{t('settings.provider.api_version')}</SettingSubtitle>
|
||||
|
||||
@ -17,3 +17,7 @@ export default class ProviderFactory {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function isOpenAIProvider(provider: Provider) {
|
||||
return !['anthropic', 'gemini'].includes(provider.id)
|
||||
}
|
||||
|
||||
@ -305,3 +305,13 @@ export const captureScrollableDiv = async (divRef: React.RefObject<HTMLDivElemen
|
||||
|
||||
return Promise.resolve(undefined)
|
||||
}
|
||||
|
||||
export function hasPath(url: string): boolean {
|
||||
try {
|
||||
const parsedUrl = new URL(url)
|
||||
return parsedUrl.pathname !== '/' && parsedUrl.pathname !== ''
|
||||
} catch (error) {
|
||||
console.error('Invalid URL:', error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user