feat: Add API host formatting utility function
This commit is contained in:
parent
f062c56de4
commit
69bb661b5a
@ -22,6 +22,7 @@ import { isProviderSupportAuth, isProviderSupportCharge } from '@renderer/servic
|
|||||||
import { useAppDispatch } from '@renderer/store'
|
import { useAppDispatch } from '@renderer/store'
|
||||||
import { setModel } from '@renderer/store/assistants'
|
import { setModel } from '@renderer/store/assistants'
|
||||||
import { Model, ModelType, Provider } from '@renderer/types'
|
import { Model, ModelType, Provider } from '@renderer/types'
|
||||||
|
import { formatApiHost } from '@renderer/utils/api'
|
||||||
import { providerCharge } from '@renderer/utils/oauth'
|
import { providerCharge } from '@renderer/utils/oauth'
|
||||||
import { Avatar, Button, Card, Checkbox, Divider, Flex, Input, Popover, Space, Switch } from 'antd'
|
import { Avatar, Button, Card, Checkbox, Divider, Flex, Input, Popover, Space, Switch } from 'antd'
|
||||||
import Link from 'antd/es/typography/Link'
|
import Link from 'antd/es/typography/Link'
|
||||||
@ -160,7 +161,7 @@ const ProviderSetting: FC<Props> = ({ provider: _provider }) => {
|
|||||||
return apiHost.replace('#', '')
|
return apiHost.replace('#', '')
|
||||||
}
|
}
|
||||||
|
|
||||||
return (apiHost.endsWith('/') ? apiHost : `${apiHost}/v1/`) + 'chat/completions'
|
return formatApiHost(apiHost) + 'chat/completions'
|
||||||
}
|
}
|
||||||
|
|
||||||
const onUpdateModelTypes = (model: Model, types: ModelType[]) => {
|
const onUpdateModelTypes = (model: Model, types: ModelType[]) => {
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import store from '@renderer/store'
|
|||||||
import type { Assistant, GenerateImageParams, Message, Model, Provider, Suggestion } from '@renderer/types'
|
import type { Assistant, GenerateImageParams, Message, Model, Provider, Suggestion } from '@renderer/types'
|
||||||
import { delay, isJSON, parseJSON } from '@renderer/utils'
|
import { delay, isJSON, parseJSON } from '@renderer/utils'
|
||||||
import { addAbortController, removeAbortController } from '@renderer/utils/abortController'
|
import { addAbortController, removeAbortController } from '@renderer/utils/abortController'
|
||||||
|
import { formatApiHost } from '@renderer/utils/api'
|
||||||
import { t } from 'i18next'
|
import { t } from 'i18next'
|
||||||
import type OpenAI from 'openai'
|
import type OpenAI from 'openai'
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ export default abstract class BaseProvider {
|
|||||||
|
|
||||||
public getBaseURL(): string {
|
public getBaseURL(): string {
|
||||||
const host = this.provider.apiHost
|
const host = this.provider.apiHost
|
||||||
return host.endsWith('/') ? host : `${host}/v1/`
|
return formatApiHost(host)
|
||||||
}
|
}
|
||||||
|
|
||||||
public getApiKey() {
|
public getApiKey() {
|
||||||
|
|||||||
15
src/renderer/src/utils/api.ts
Normal file
15
src/renderer/src/utils/api.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
export function formatApiHost(host: string) {
|
||||||
|
const forceUseOriginalHost = () => {
|
||||||
|
if (host.endsWith('/')) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (host.endsWith('volces.com/api/v3')) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return forceUseOriginalHost() ? host : `${host}/v1/`
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user