From e398f470a19bc13a5167cce6951ca79a6c1779fc Mon Sep 17 00:00:00 2001 From: JustSong Date: Tue, 20 Jun 2023 22:32:56 +0800 Subject: [PATCH] feat: support custom base url for channels --- controller/channel-test.go | 4 +--- controller/relay-text.go | 6 +----- web/src/pages/Channel/EditChannel.js | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/controller/channel-test.go b/controller/channel-test.go index 5e44aa75..0cfc8ac9 100644 --- a/controller/channel-test.go +++ b/controller/channel-test.go @@ -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" diff --git a/controller/relay-text.go b/controller/relay-text.go index e47c517b..b7b0ed63 100644 --- a/controller/relay-text.go +++ b/controller/relay-text.go @@ -30,12 +30,8 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode { } baseURL := common.ChannelBaseURLs[channelType] requestURL := c.Request.URL.String() - if channelType == common.ChannelTypeCustom { + if c.GetString("base_url") != "" { 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 { diff --git a/web/src/pages/Channel/EditChannel.js b/web/src/pages/Channel/EditChannel.js index e25ab2de..0e544d47 100644 --- a/web/src/pages/Channel/EditChannel.js +++ b/web/src/pages/Channel/EditChannel.js @@ -177,6 +177,20 @@ const EditChannel = () => { ) } + { + inputs.type !== 3 && inputs.type !== 8 && ( + + + + ) + }