Sfoglia il codice sorgente

feat: 自定义渠道功能变更 (#262)

CaIon 1 anno fa
parent
commit
84da88506f
2 ha cambiato i file con 15 aggiunte e 11 eliminazioni
  1. 4 4
      relay/channel/openai/adaptor.go
  2. 11 7
      web/src/pages/Channel/EditChannel.js

+ 4 - 4
relay/channel/openai/adaptor.go

@@ -41,10 +41,10 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
 		return relaycommon.GetFullRequestURL(info.BaseUrl, requestURL, info.ChannelType), nil
 	case common.ChannelTypeMiniMax:
 		return minimax.GetRequestURL(info)
-	//case common.ChannelTypeCustom:
-	//	url := info.BaseUrl
-	//	url = strings.Replace(url, "{model}", info.UpstreamModelName, -1)
-	//	return url, nil
+	case common.ChannelTypeCustom:
+		url := info.BaseUrl
+		url = strings.Replace(url, "{model}", info.UpstreamModelName, -1)
+		return url, nil
 	default:
 		return relaycommon.GetFullRequestURL(info.BaseUrl, info.RequestURLPath, info.ChannelType), nil
 	}

+ 11 - 7
web/src/pages/Channel/EditChannel.js

@@ -301,17 +301,18 @@ const EditChannel = (props) => {
   const addCustomModels = () => {
     if (customModel.trim() === '') return;
     // 使用逗号分隔字符串,然后去除每个模型名称前后的空格
-    const modelArray = customModel.split(',').map(model => model.trim());
-    
+    const modelArray = customModel.split(',').map((model) => model.trim());
+
     let localModels = [...inputs.models];
     let localModelOptions = [...modelOptions];
     let hasError = false;
 
-    modelArray.forEach(model => {
+    modelArray.forEach((model) => {
       // 检查模型是否已存在,且模型名称非空
       if (model && !localModels.includes(model)) {
         localModels.push(model); // 添加到模型列表
-        localModelOptions.push({ // 添加到下拉选项
+        localModelOptions.push({
+          // 添加到下拉选项
           key: model,
           text: model,
           value: model,
@@ -330,7 +331,6 @@ const EditChannel = (props) => {
     handleInputChange('models', localModels);
   };
 
-
   return (
     <>
       <SideSheet
@@ -433,11 +433,15 @@ const EditChannel = (props) => {
           {inputs.type === 8 && (
             <>
               <div style={{ marginTop: 10 }}>
-                <Typography.Text strong>Base URL:</Typography.Text>
+                <Typography.Text strong>
+                  完整的 Base URL,支持变量{'{model}'}:
+                </Typography.Text>
               </div>
               <Input
                 name='base_url'
-                placeholder={'请输入自定义渠道的 Base URL'}
+                placeholder={
+                  '请输入完整的URL,例如:https://api.openai.com/v1/chat/completions'
+                }
                 onChange={(value) => {
                   handleInputChange('base_url', value);
                 }}