Просмотр исходного кода

feat: support custom base url for channels

JustSong 2 лет назад
Родитель
Сommit
e398f470a1
3 измененных файлов с 16 добавлено и 8 удалено
  1. 1 3
      controller/channel-test.go
  2. 1 5
      controller/relay-text.go
  3. 14 0
      web/src/pages/Channel/EditChannel.js

+ 1 - 3
controller/channel-test.go

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

+ 1 - 5
controller/relay-text.go

@@ -30,12 +30,8 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
 	}
 	}
 	baseURL := common.ChannelBaseURLs[channelType]
 	baseURL := common.ChannelBaseURLs[channelType]
 	requestURL := c.Request.URL.String()
 	requestURL := c.Request.URL.String()
-	if channelType == common.ChannelTypeCustom {
+	if c.GetString("base_url") != "" {
 		baseURL = 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)
 	fullRequestURL := fmt.Sprintf("%s%s", baseURL, requestURL)
 	if channelType == common.ChannelTypeAzure {
 	if channelType == common.ChannelTypeAzure {

+ 14 - 0
web/src/pages/Channel/EditChannel.js

@@ -177,6 +177,20 @@ const EditChannel = () => {
               </Form.Field>
               </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.Field>
             <Form.Input
             <Form.Input
               label='名称'
               label='名称'