Skip to content

Commit

Permalink
feat: add Novita AI as model provider (songquanpeng#1609)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonhp authored and jinjianming committed Jul 17, 2024
1 parent 457abc0 commit 3c147e1
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ _✨ 通过标准的 OpenAI API 格式访问所有的大模型,开箱即用
+ [x] [Cloudflare Workers AI](https://developers.cloudflare.com/workers-ai/)
+ [x] [DeepL](https://www.deepl.com/)
+ [x] [together.ai](https://www.together.ai/)
+ [x] [novita.ai](https://www.novita.ai/)
2. 支持配置镜像以及众多[第三方代理服务](https://iamazing.cn/page/openai-api-third-party-services)
3. 支持通过**负载均衡**的方式访问多个渠道。
4. 支持 **stream 模式**,可以通过流式传输实现打字机效果。
Expand Down
19 changes: 19 additions & 0 deletions relay/adaptor/novita/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package novita

// https://novita.ai/llm-api

var ModelList = []string{
"meta-llama/llama-3-8b-instruct",
"meta-llama/llama-3-70b-instruct",
"nousresearch/hermes-2-pro-llama-3-8b",
"nousresearch/nous-hermes-llama2-13b",
"mistralai/mistral-7b-instruct",
"cognitivecomputations/dolphin-mixtral-8x22b",
"sao10k/l3-70b-euryale-v2.1",
"sophosympatheia/midnight-rose-70b",
"gryphe/mythomax-l2-13b",
"Nous-Hermes-2-Mixtral-8x7B-DPO",
"lzlv_70b",
"teknium/openhermes-2.5-mistral-7b",
"microsoft/wizardlm-2-8x22b",
}
15 changes: 15 additions & 0 deletions relay/adaptor/novita/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package novita

import (
"fmt"

"github.com/songquanpeng/one-api/relay/meta"
"github.com/songquanpeng/one-api/relay/relaymode"
)

func GetRequestURL(meta *meta.Meta) (string, error) {
if meta.Mode == relaymode.ChatCompletions {
return fmt.Sprintf("%s/chat/completions", meta.BaseURL), nil
}
return "", fmt.Errorf("unsupported relay mode %d for novita", meta.Mode)
}
10 changes: 7 additions & 3 deletions relay/adaptor/openai/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ package openai
import (
"errors"
"fmt"
"io"
"net/http"
"strings"

"github.com/gin-gonic/gin"
"github.com/songquanpeng/one-api/relay/adaptor"
"github.com/songquanpeng/one-api/relay/adaptor/doubao"
"github.com/songquanpeng/one-api/relay/adaptor/minimax"
"github.com/songquanpeng/one-api/relay/adaptor/novita"
"github.com/songquanpeng/one-api/relay/channeltype"
"github.com/songquanpeng/one-api/relay/meta"
"github.com/songquanpeng/one-api/relay/model"
"github.com/songquanpeng/one-api/relay/relaymode"
"io"
"net/http"
"strings"
)

type Adaptor struct {
Expand Down Expand Up @@ -48,6 +50,8 @@ func (a *Adaptor) GetRequestURL(meta *meta.Meta) (string, error) {
return minimax.GetRequestURL(meta)
case channeltype.Doubao:
return doubao.GetRequestURL(meta)
case channeltype.Novita:
return novita.GetRequestURL(meta)
default:
return GetFullRequestURL(meta.BaseURL, meta.RequestURLPath, meta.ChannelType), nil
}
Expand Down
4 changes: 4 additions & 0 deletions relay/adaptor/openai/compatible.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/songquanpeng/one-api/relay/adaptor/minimax"
"github.com/songquanpeng/one-api/relay/adaptor/mistral"
"github.com/songquanpeng/one-api/relay/adaptor/moonshot"
"github.com/songquanpeng/one-api/relay/adaptor/novita"
"github.com/songquanpeng/one-api/relay/adaptor/stepfun"
"github.com/songquanpeng/one-api/relay/adaptor/togetherai"
"github.com/songquanpeng/one-api/relay/channeltype"
Expand All @@ -28,6 +29,7 @@ var CompatibleChannels = []int{
channeltype.StepFun,
channeltype.DeepSeek,
channeltype.TogetherAI,
channeltype.Novita,
}

func GetCompatibleChannelMeta(channelType int) (string, []string) {
Expand Down Expand Up @@ -56,6 +58,8 @@ func GetCompatibleChannelMeta(channelType int) (string, []string) {
return "together.ai", togetherai.ModelList
case channeltype.Doubao:
return "doubao", doubao.ModelList
case channeltype.Novita:
return "novita", novita.ModelList
default:
return "openai", ModelList
}
Expand Down
1 change: 1 addition & 0 deletions relay/channeltype/define.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ const (
DeepL
TogetherAI
Doubao
Novita
Dummy
)
1 change: 1 addition & 0 deletions relay/channeltype/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var ChannelBaseURLs = []string{
"https://api-free.deepl.com", // 38
"https://api.together.xyz", // 39
"https://ark.cn-beijing.volces.com", // 40
"https://api.novita.ai/v3/openai", // 41
}

func init() {
Expand Down
6 changes: 6 additions & 0 deletions web/berry/src/constants/ChannelConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ export const CHANNEL_OPTIONS = {
value: 39,
color: 'primary'
},
41: {
key: 41,
text: 'Novita',
value: 41,
color: 'purple'
},
8: {
key: 8,
text: '自定义渠道',
Expand Down
1 change: 1 addition & 0 deletions web/default/src/constants/channel.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const CHANNEL_OPTIONS = [
{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: '字节跳动豆包', value: 40, color: 'blue'},
{key: 15, text: '百度文心千帆', value: 15, color: 'blue'},
{key: 17, text: '阿里通义千问', value: 17, color: 'orange'},
Expand Down

0 comments on commit 3c147e1

Please sign in to comment.