mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-17 01:06:37 +08:00
feat: add OpenAI compatible channel (close #2091)
This commit is contained in:
parent
8b8cd03e85
commit
cafd0a0327
@ -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") {
|
||||
|
@ -51,5 +51,6 @@ const (
|
||||
BaiduV2
|
||||
XunfeiV2
|
||||
AliBailian
|
||||
OpenAICompatible
|
||||
Dummy
|
||||
)
|
||||
|
@ -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() {
|
||||
|
@ -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: '请前往<a href="https://console.bce.baidu.com/iam/#/iam/apikey/list" target="_blank">此处</a>获取 API Key,注意本渠道仅支持<a target="_blank" href="https://cloud.baidu.com/doc/WENXINWORKSHOP/s/em4tsqo3v">推理服务 V2</a>相关模型',
|
||||
},
|
||||
{
|
||||
key: 17,
|
||||
text: '阿里通义千问',
|
||||
value: 17,
|
||||
color: 'orange',
|
||||
tip: '如需使用阿里云百炼,请使用<strong>阿里云百炼</strong>渠道',
|
||||
},
|
||||
{key: 49, text: '阿里云百炼', value: 49, color: 'orange'},
|
||||
{
|
||||
key: 17,
|
||||
text: '阿里通义千问',
|
||||
value: 17,
|
||||
color: 'orange',
|
||||
tip: '如需使用阿里云百炼,请使用<strong>阿里云百炼</strong>渠道',
|
||||
},
|
||||
{key: 49, text: '阿里云百炼', value: 49, color: 'orange'},
|
||||
{
|
||||
key: 18,
|
||||
text: '讯飞星火认知',
|
||||
@ -50,38 +57,44 @@ export const CHANNEL_OPTIONS = [
|
||||
color: 'blue',
|
||||
tip: 'HTTP 版本的讯飞接口,前往<a href="https://console.xfyun.cn/services/cbm" target="_blank">此处</a>获取 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'},
|
||||
];
|
||||
|
@ -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",
|
||||
|
@ -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": "批量创建",
|
||||
|
@ -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 && (
|
||||
<Form.Field>
|
||||
<Form.Input
|
||||
required
|
||||
label={t('channel.edit.proxy_url')}
|
||||
name='base_url'
|
||||
placeholder={t('channel.edit.proxy_url_placeholder')}
|
||||
onChange={handleInputChange}
|
||||
value={inputs.base_url}
|
||||
autoComplete='new-password'
|
||||
/>
|
||||
</Form.Field>
|
||||
)}
|
||||
{inputs.type === 50 && (
|
||||
<Form.Field>
|
||||
<Form.Input
|
||||
required
|
||||
label={t('channel.edit.base_url')}
|
||||
name='base_url'
|
||||
placeholder={t('channel.edit.base_url_placeholder')}
|
||||
@ -637,12 +651,13 @@ const EditChannel = () => {
|
||||
{inputs.type !== 3 &&
|
||||
inputs.type !== 33 &&
|
||||
inputs.type !== 8 &&
|
||||
inputs.type !== 50 &&
|
||||
inputs.type !== 22 && (
|
||||
<Form.Field>
|
||||
<Form.Input
|
||||
label={t('channel.edit.base_url')}
|
||||
label={t('channel.edit.proxy_url')}
|
||||
name='base_url'
|
||||
placeholder={t('channel.edit.base_url_placeholder')}
|
||||
placeholder={t('channel.edit.proxy_url_placeholder')}
|
||||
onChange={handleInputChange}
|
||||
value={inputs.base_url}
|
||||
autoComplete='new-password'
|
||||
|
Loading…
Reference in New Issue
Block a user