diff --git a/relay/adaptor/openai/helper.go b/relay/adaptor/openai/helper.go index 47c2a882..c6d5bd7f 100644 --- a/relay/adaptor/openai/helper.go +++ b/relay/adaptor/openai/helper.go @@ -17,6 +17,9 @@ func ResponseText2Usage(responseText string, modelName string, promptTokens int) } func GetFullRequestURL(baseURL string, requestURL string, channelType int) string { + if channelType == channeltype.OpenAICompatible { + return fmt.Sprintf("%s%s", strings.TrimSuffix(baseURL, "/"), strings.TrimPrefix(requestURL, "/v1")) + } fullRequestURL := fmt.Sprintf("%s%s", baseURL, requestURL) if strings.HasPrefix(baseURL, "https://gateway.ai.cloudflare.com") { diff --git a/relay/channeltype/define.go b/relay/channeltype/define.go index 76b549e1..87a3cbb8 100644 --- a/relay/channeltype/define.go +++ b/relay/channeltype/define.go @@ -51,5 +51,6 @@ const ( BaiduV2 XunfeiV2 AliBailian + OpenAICompatible Dummy ) diff --git a/relay/channeltype/url.go b/relay/channeltype/url.go index a8acd967..f2e41602 100644 --- a/relay/channeltype/url.go +++ b/relay/channeltype/url.go @@ -51,6 +51,7 @@ var ChannelBaseURLs = []string{ "https://qianfan.baidubce.com", // 47 "https://spark-api-open.xf-yun.com", // 48 "https://dashscope.aliyuncs.com", // 49 + "", // 50 } func init() { diff --git a/web/default/src/constants/channel.constants.js b/web/default/src/constants/channel.constants.js index 26ffd0c4..d40273ed 100644 --- a/web/default/src/constants/channel.constants.js +++ b/web/default/src/constants/channel.constants.js @@ -1,12 +1,19 @@ export const CHANNEL_OPTIONS = [ - {key: 1, text: 'OpenAI', value: 1, color: 'green'}, - {key: 14, text: 'Anthropic Claude', value: 14, color: 'black'}, - {key: 33, text: 'AWS', value: 33, color: 'black'}, - {key: 3, text: 'Azure OpenAI', value: 3, color: 'olive'}, - {key: 11, text: 'Google PaLM2', value: 11, color: 'orange'}, - {key: 24, text: 'Google Gemini', value: 24, color: 'orange'}, - {key: 28, text: 'Mistral AI', value: 28, color: 'orange'}, - {key: 41, text: 'Novita', value: 41, color: 'purple'}, + {key: 1, text: 'OpenAI', value: 1, color: 'green'}, + { + key: 50, + text: 'OpenAI 兼容', + value: 50, + color: 'olive', + description: 'OpenAI 兼容渠道,支持设置 Base URL', + }, + {key: 14, text: 'Anthropic Claude', value: 14, color: 'black'}, + {key: 33, text: 'AWS', value: 33, color: 'black'}, + {key: 3, text: 'Azure OpenAI', value: 3, color: 'olive'}, + {key: 11, text: 'Google PaLM2', value: 11, color: 'orange'}, + {key: 24, text: 'Google Gemini', value: 24, color: 'orange'}, + {key: 28, text: 'Mistral AI', value: 28, color: 'orange'}, + {key: 41, text: 'Novita', value: 41, color: 'purple'}, { key: 40, text: '字节火山引擎', @@ -28,14 +35,14 @@ export const CHANNEL_OPTIONS = [ color: 'blue', tip: '请前往此处获取 API Key,注意本渠道仅支持推理服务 V2相关模型', }, - { - key: 17, - text: '阿里通义千问', - value: 17, - color: 'orange', - tip: '如需使用阿里云百炼,请使用阿里云百炼渠道', - }, - {key: 49, text: '阿里云百炼', value: 49, color: 'orange'}, + { + key: 17, + text: '阿里通义千问', + value: 17, + color: 'orange', + tip: '如需使用阿里云百炼,请使用阿里云百炼渠道', + }, + {key: 49, text: '阿里云百炼', value: 49, color: 'orange'}, { key: 18, text: '讯飞星火认知', @@ -50,38 +57,44 @@ export const CHANNEL_OPTIONS = [ color: 'blue', tip: 'HTTP 版本的讯飞接口,前往此处获取 HTTP 服务接口认证密钥', }, - {key: 16, text: '智谱 ChatGLM', value: 16, color: 'violet'}, - {key: 19, text: '360 智脑', value: 19, color: 'blue'}, - {key: 25, text: 'Moonshot AI', value: 25, color: 'black'}, - {key: 23, text: '腾讯混元', value: 23, color: 'teal'}, - {key: 26, text: '百川大模型', value: 26, color: 'orange'}, - {key: 27, text: 'MiniMax', value: 27, color: 'red'}, - {key: 29, text: 'Groq', value: 29, color: 'orange'}, - {key: 30, text: 'Ollama', value: 30, color: 'black'}, - {key: 31, text: '零一万物', value: 31, color: 'green'}, - {key: 32, text: '阶跃星辰', value: 32, color: 'blue'}, - {key: 34, text: 'Coze', value: 34, color: 'blue'}, - {key: 35, text: 'Cohere', value: 35, color: 'blue'}, - {key: 36, text: 'DeepSeek', value: 36, color: 'black'}, - {key: 37, text: 'Cloudflare', value: 37, color: 'orange'}, - {key: 38, text: 'DeepL', value: 38, color: 'black'}, - {key: 39, text: 'together.ai', value: 39, color: 'blue'}, - {key: 42, text: 'VertexAI', value: 42, color: 'blue'}, - {key: 43, text: 'Proxy', value: 43, color: 'blue'}, - {key: 44, text: 'SiliconFlow', value: 44, color: 'blue'}, - {key: 45, text: 'xAI', value: 45, color: 'blue'}, - {key: 46, text: 'Replicate', value: 46, color: 'blue'}, - {key: 8, text: '自定义渠道', value: 8, color: 'pink'}, - {key: 22, text: '知识库:FastGPT', value: 22, color: 'blue'}, - {key: 21, text: '知识库:AI Proxy', value: 21, color: 'purple'}, - {key: 20, text: 'OpenRouter', value: 20, color: 'black'}, - {key: 2, text: '代理:API2D', value: 2, color: 'blue'}, - {key: 5, text: '代理:OpenAI-SB', value: 5, color: 'brown'}, - {key: 7, text: '代理:OhMyGPT', value: 7, color: 'purple'}, - {key: 10, text: '代理:AI Proxy', value: 10, color: 'purple'}, - {key: 4, text: '代理:CloseAI', value: 4, color: 'teal'}, - {key: 6, text: '代理:OpenAI Max', value: 6, color: 'violet'}, - {key: 9, text: '代理:AI.LS', value: 9, color: 'yellow'}, - {key: 12, text: '代理:API2GPT', value: 12, color: 'blue'}, - {key: 13, text: '代理:AIGC2D', value: 13, color: 'purple'}, + {key: 16, text: '智谱 ChatGLM', value: 16, color: 'violet'}, + {key: 19, text: '360 智脑', value: 19, color: 'blue'}, + {key: 25, text: 'Moonshot AI', value: 25, color: 'black'}, + {key: 23, text: '腾讯混元', value: 23, color: 'teal'}, + {key: 26, text: '百川大模型', value: 26, color: 'orange'}, + {key: 27, text: 'MiniMax', value: 27, color: 'red'}, + {key: 29, text: 'Groq', value: 29, color: 'orange'}, + {key: 30, text: 'Ollama', value: 30, color: 'black'}, + {key: 31, text: '零一万物', value: 31, color: 'green'}, + {key: 32, text: '阶跃星辰', value: 32, color: 'blue'}, + {key: 34, text: 'Coze', value: 34, color: 'blue'}, + {key: 35, text: 'Cohere', value: 35, color: 'blue'}, + {key: 36, text: 'DeepSeek', value: 36, color: 'black'}, + {key: 37, text: 'Cloudflare', value: 37, color: 'orange'}, + {key: 38, text: 'DeepL', value: 38, color: 'black'}, + {key: 39, text: 'together.ai', value: 39, color: 'blue'}, + {key: 42, text: 'VertexAI', value: 42, color: 'blue'}, + {key: 43, text: 'Proxy', value: 43, color: 'blue'}, + {key: 44, text: 'SiliconFlow', value: 44, color: 'blue'}, + {key: 45, text: 'xAI', value: 45, color: 'blue'}, + {key: 46, text: 'Replicate', value: 46, color: 'blue'}, + { + key: 8, + text: '自定义渠道', + value: 8, + color: 'pink', + tip: '注意,这里所需要填入的代理地址仅会在实际请求时替换域名部分,如果你想填入 OpenAI SDK 中所要求的 Base URL,请使用 OpenAI 兼容渠道类型', + }, + {key: 22, text: '知识库:FastGPT', value: 22, color: 'blue'}, + {key: 21, text: '知识库:AI Proxy', value: 21, color: 'purple'}, + {key: 20, text: 'OpenRouter', value: 20, color: 'black'}, + {key: 2, text: '代理:API2D', value: 2, color: 'blue'}, + {key: 5, text: '代理:OpenAI-SB', value: 5, color: 'brown'}, + {key: 7, text: '代理:OhMyGPT', value: 7, color: 'purple'}, + {key: 10, text: '代理:AI Proxy', value: 10, color: 'purple'}, + {key: 4, text: '代理:CloseAI', value: 4, color: 'teal'}, + {key: 6, text: '代理:OpenAI Max', value: 6, color: 'violet'}, + {key: 9, text: '代理:AI.LS', value: 9, color: 'yellow'}, + {key: 12, text: '代理:API2GPT', value: 12, color: 'blue'}, + {key: 13, text: '代理:AIGC2D', value: 13, color: 'purple'}, ]; diff --git a/web/default/src/locales/en/translation.json b/web/default/src/locales/en/translation.json index 76d51f80..47f3400f 100644 --- a/web/default/src/locales/en/translation.json +++ b/web/default/src/locales/en/translation.json @@ -104,8 +104,10 @@ "model_mapping_placeholder": "Optional, used to modify model names in request body. A JSON string where keys are request model names and values are target model names", "system_prompt": "System Prompt", "system_prompt_placeholder": "Optional, used to force set system prompt. Use with custom model & model mapping. First create a unique custom model name above, then map it to a natively supported model", - "base_url": "Proxy", - "base_url_placeholder": "Optional, used for API calls through proxy. Enter proxy address in format: https://domain.com", + "proxy_url": "Proxy", + "proxy_url_placeholder": "This is optional and used for API calls via a proxy. Please enter the proxy URL, formatted as: https://domain.com", + "base_url": "Base URL", + "base_url_placeholder": "The Base URL required by the OpenAPI SDK", "key": "Key", "key_placeholder": "Please enter key", "batch": "Batch Create", diff --git a/web/default/src/locales/zh/translation.json b/web/default/src/locales/zh/translation.json index 40e4ee5f..7cbf686d 100644 --- a/web/default/src/locales/zh/translation.json +++ b/web/default/src/locales/zh/translation.json @@ -104,8 +104,10 @@ "model_mapping_placeholder": "此项可选,用于修改请求体中的模型名称,为一个 JSON 字符串,键为请求中模型名称,值为要替换的模型名称", "system_prompt": "系统提示词", "system_prompt_placeholder": "此项可选,用于强制设置给定的系统提示词,请配合自定义模型 & 模型重定向使用,首先创建一个唯一的自定义模型名称并在上面填入,之后将该自定义模型重定向映射到该渠道一个原生支持的模型", - "base_url": "代理", - "base_url_placeholder": "此项可选,用于通过代理站来进行 API 调用,请输入代理站地址,格式为:https://domain.com", + "proxy_url": "代理", + "proxy_url_placeholder": "此项可选,用于通过代理站来进行 API 调用,请输入代理站地址,格式为:https://domain.com。注意,这里所需要填入的代理地址仅会在实际请求时替换域名部分,如果你想填入 OpenAI SDK 中所要求的 Base URL,请使用 OpenAI 兼容渠道类型", + "base_url": "Base URL", + "base_url_placeholder": "OpenAPI SDK 中所要求的 Base URL", "key": "密钥", "key_placeholder": "请输入密钥", "batch": "批量创建", diff --git a/web/default/src/pages/Channel/EditChannel.js b/web/default/src/pages/Channel/EditChannel.js index 799e1d16..243db3d3 100644 --- a/web/default/src/pages/Channel/EditChannel.js +++ b/web/default/src/pages/Channel/EditChannel.js @@ -1,6 +1,6 @@ import React, {useEffect, useState} from 'react'; import {useTranslation} from 'react-i18next'; -import {Button, Card, Form, Input, Message,} from 'semantic-ui-react'; +import {Button, Card, Form, Input, Message} from 'semantic-ui-react'; import {useNavigate, useParams} from 'react-router-dom'; import {API, copy, getChannelModels, showError, showInfo, showSuccess, verifyJSON,} from '../../helpers'; import {CHANNEL_OPTIONS} from '../../constants'; @@ -339,6 +339,20 @@ const EditChannel = () => { {inputs.type === 8 && ( + + )} + {inputs.type === 50 && ( + + { {inputs.type !== 3 && inputs.type !== 33 && inputs.type !== 8 && + inputs.type !== 50 && inputs.type !== 22 && (