mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-12 19:33:41 +08:00
feat: add OpenAI compatible channel (close #2091)
This commit is contained in:
@@ -17,6 +17,9 @@ func ResponseText2Usage(responseText string, modelName string, promptTokens int)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetFullRequestURL(baseURL string, requestURL string, channelType int) string {
|
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)
|
fullRequestURL := fmt.Sprintf("%s%s", baseURL, requestURL)
|
||||||
|
|
||||||
if strings.HasPrefix(baseURL, "https://gateway.ai.cloudflare.com") {
|
if strings.HasPrefix(baseURL, "https://gateway.ai.cloudflare.com") {
|
||||||
|
|||||||
@@ -51,5 +51,6 @@ const (
|
|||||||
BaiduV2
|
BaiduV2
|
||||||
XunfeiV2
|
XunfeiV2
|
||||||
AliBailian
|
AliBailian
|
||||||
|
OpenAICompatible
|
||||||
Dummy
|
Dummy
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ var ChannelBaseURLs = []string{
|
|||||||
"https://qianfan.baidubce.com", // 47
|
"https://qianfan.baidubce.com", // 47
|
||||||
"https://spark-api-open.xf-yun.com", // 48
|
"https://spark-api-open.xf-yun.com", // 48
|
||||||
"https://dashscope.aliyuncs.com", // 49
|
"https://dashscope.aliyuncs.com", // 49
|
||||||
|
"", // 50
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
export const CHANNEL_OPTIONS = [
|
export const CHANNEL_OPTIONS = [
|
||||||
{key: 1, text: 'OpenAI', value: 1, color: 'green'},
|
{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: 14, text: 'Anthropic Claude', value: 14, color: 'black'},
|
||||||
{key: 33, text: 'AWS', value: 33, color: 'black'},
|
{key: 33, text: 'AWS', value: 33, color: 'black'},
|
||||||
{key: 3, text: 'Azure OpenAI', value: 3, color: 'olive'},
|
{key: 3, text: 'Azure OpenAI', value: 3, color: 'olive'},
|
||||||
@@ -71,7 +78,13 @@ export const CHANNEL_OPTIONS = [
|
|||||||
{key: 44, text: 'SiliconFlow', value: 44, color: 'blue'},
|
{key: 44, text: 'SiliconFlow', value: 44, color: 'blue'},
|
||||||
{key: 45, text: 'xAI', value: 45, color: 'blue'},
|
{key: 45, text: 'xAI', value: 45, color: 'blue'},
|
||||||
{key: 46, text: 'Replicate', value: 46, color: 'blue'},
|
{key: 46, text: 'Replicate', value: 46, color: 'blue'},
|
||||||
{key: 8, text: '自定义渠道', value: 8, color: 'pink'},
|
{
|
||||||
|
key: 8,
|
||||||
|
text: '自定义渠道',
|
||||||
|
value: 8,
|
||||||
|
color: 'pink',
|
||||||
|
tip: '注意,这里所需要填入的代理地址仅会在实际请求时替换域名部分,如果你想填入 OpenAI SDK 中所要求的 Base URL,请使用 OpenAI 兼容渠道类型',
|
||||||
|
},
|
||||||
{key: 22, text: '知识库:FastGPT', value: 22, color: 'blue'},
|
{key: 22, text: '知识库:FastGPT', value: 22, color: 'blue'},
|
||||||
{key: 21, text: '知识库:AI Proxy', value: 21, color: 'purple'},
|
{key: 21, text: '知识库:AI Proxy', value: 21, color: 'purple'},
|
||||||
{key: 20, text: 'OpenRouter', value: 20, color: 'black'},
|
{key: 20, text: 'OpenRouter', value: 20, color: 'black'},
|
||||||
|
|||||||
@@ -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",
|
"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": "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",
|
"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",
|
"proxy_url": "Proxy",
|
||||||
"base_url_placeholder": "Optional, used for API calls through proxy. Enter proxy address in format: https://domain.com",
|
"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": "Key",
|
||||||
"key_placeholder": "Please enter key",
|
"key_placeholder": "Please enter key",
|
||||||
"batch": "Batch Create",
|
"batch": "Batch Create",
|
||||||
|
|||||||
@@ -104,8 +104,10 @@
|
|||||||
"model_mapping_placeholder": "此项可选,用于修改请求体中的模型名称,为一个 JSON 字符串,键为请求中模型名称,值为要替换的模型名称",
|
"model_mapping_placeholder": "此项可选,用于修改请求体中的模型名称,为一个 JSON 字符串,键为请求中模型名称,值为要替换的模型名称",
|
||||||
"system_prompt": "系统提示词",
|
"system_prompt": "系统提示词",
|
||||||
"system_prompt_placeholder": "此项可选,用于强制设置给定的系统提示词,请配合自定义模型 & 模型重定向使用,首先创建一个唯一的自定义模型名称并在上面填入,之后将该自定义模型重定向映射到该渠道一个原生支持的模型",
|
"system_prompt_placeholder": "此项可选,用于强制设置给定的系统提示词,请配合自定义模型 & 模型重定向使用,首先创建一个唯一的自定义模型名称并在上面填入,之后将该自定义模型重定向映射到该渠道一个原生支持的模型",
|
||||||
"base_url": "代理",
|
"proxy_url": "代理",
|
||||||
"base_url_placeholder": "此项可选,用于通过代理站来进行 API 调用,请输入代理站地址,格式为:https://domain.com",
|
"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": "密钥",
|
||||||
"key_placeholder": "请输入密钥",
|
"key_placeholder": "请输入密钥",
|
||||||
"batch": "批量创建",
|
"batch": "批量创建",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, {useEffect, useState} from 'react';
|
import React, {useEffect, useState} from 'react';
|
||||||
import {useTranslation} from 'react-i18next';
|
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 {useNavigate, useParams} from 'react-router-dom';
|
||||||
import {API, copy, getChannelModels, showError, showInfo, showSuccess, verifyJSON,} from '../../helpers';
|
import {API, copy, getChannelModels, showError, showInfo, showSuccess, verifyJSON,} from '../../helpers';
|
||||||
import {CHANNEL_OPTIONS} from '../../constants';
|
import {CHANNEL_OPTIONS} from '../../constants';
|
||||||
@@ -339,6 +339,20 @@ const EditChannel = () => {
|
|||||||
{inputs.type === 8 && (
|
{inputs.type === 8 && (
|
||||||
<Form.Field>
|
<Form.Field>
|
||||||
<Form.Input
|
<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')}
|
label={t('channel.edit.base_url')}
|
||||||
name='base_url'
|
name='base_url'
|
||||||
placeholder={t('channel.edit.base_url_placeholder')}
|
placeholder={t('channel.edit.base_url_placeholder')}
|
||||||
@@ -637,12 +651,13 @@ const EditChannel = () => {
|
|||||||
{inputs.type !== 3 &&
|
{inputs.type !== 3 &&
|
||||||
inputs.type !== 33 &&
|
inputs.type !== 33 &&
|
||||||
inputs.type !== 8 &&
|
inputs.type !== 8 &&
|
||||||
|
inputs.type !== 50 &&
|
||||||
inputs.type !== 22 && (
|
inputs.type !== 22 && (
|
||||||
<Form.Field>
|
<Form.Field>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
label={t('channel.edit.base_url')}
|
label={t('channel.edit.proxy_url')}
|
||||||
name='base_url'
|
name='base_url'
|
||||||
placeholder={t('channel.edit.base_url_placeholder')}
|
placeholder={t('channel.edit.proxy_url_placeholder')}
|
||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
value={inputs.base_url}
|
value={inputs.base_url}
|
||||||
autoComplete='new-password'
|
autoComplete='new-password'
|
||||||
|
|||||||
Reference in New Issue
Block a user