feat: support custom base url for channels

This commit is contained in:
JustSong 2023-06-20 22:32:56 +08:00
parent 634099e592
commit e398f470a1
3 changed files with 16 additions and 8 deletions

View File

@ -25,9 +25,7 @@ func testChannel(channel *model.Channel, request ChatRequest) error {
if channel.Type == common.ChannelTypeAzure {
requestURL = fmt.Sprintf("%s/openai/deployments/%s/chat/completions?api-version=2023-03-15-preview", channel.BaseURL, request.Model)
} else {
if channel.Type == common.ChannelTypeCustom {
requestURL = channel.BaseURL
} else if channel.Type == common.ChannelTypeOpenAI && channel.BaseURL != "" {
if channel.BaseURL != "" {
requestURL = channel.BaseURL
}
requestURL += "/v1/chat/completions"

View File

@ -30,13 +30,9 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
}
baseURL := common.ChannelBaseURLs[channelType]
requestURL := c.Request.URL.String()
if channelType == common.ChannelTypeCustom {
baseURL = c.GetString("base_url")
} else if channelType == common.ChannelTypeOpenAI {
if c.GetString("base_url") != "" {
baseURL = c.GetString("base_url")
}
}
fullRequestURL := fmt.Sprintf("%s%s", baseURL, requestURL)
if channelType == common.ChannelTypeAzure {
// https://learn.microsoft.com/en-us/azure/cognitive-services/openai/chatgpt-quickstart?pivots=rest-api&tabs=command-line#rest-api

View File

@ -177,6 +177,20 @@ const EditChannel = () => {
</Form.Field>
)
}
{
inputs.type !== 3 && inputs.type !== 8 && (
<Form.Field>
<Form.Input
label='Base URL'
name='base_url'
placeholder={'请输入自定义 Base URL格式为https://domain.com可不填不填使用渠道默认值'}
onChange={handleInputChange}
value={inputs.base_url}
autoComplete='new-password'
/>
</Form.Field>
)
}
<Form.Field>
<Form.Input
label='名称'