Skip to content

Commit

Permalink
✨ feat: add Github channel (MartialBE#358)
Browse files Browse the repository at this point in the history
增加Github渠道适配
  • Loading branch information
ZeroDeng01 authored Sep 19, 2024
1 parent 99946b7 commit 8b0b529
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 49 deletions.
100 changes: 51 additions & 49 deletions common/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,58 +202,60 @@ const (
ChannelTypeFlux = 46
ChannelTypeJina = 47
ChannelTypeRerank = 48
ChannelTypeGithub = 49
)

var ChannelBaseURLs = []string{
"", // 0
"https://api.openai.com", // 1
"https://oa.api2d.net", // 2
"", // 3
"https://api.closeai-proxy.xyz", // 4
"https://api.openai-sb.com", // 5
"https://api.openaimax.com", // 6
"https://api.ohmygpt.com", // 7
"", // 8
"https://api.caipacity.com", // 9
"https://api.aiproxy.io", // 10
"", // 11
"https://api.api2gpt.com", // 12
"https://api.aigc2d.com", // 13
"https://api.anthropic.com", // 14
"https://aip.baidubce.com", // 15
"https://open.bigmodel.cn", // 16
"https://dashscope.aliyuncs.com", // 17
"", // 18
"https://ai.360.cn", // 19
"https://openrouter.ai/api", // 20
"https://api.aiproxy.io", // 21
"https://fastgpt.run/api/openapi", // 22
"https://hunyuan.cloud.tencent.com", //23
"", //24
"", //25
"https://api.baichuan-ai.com", //26
"https://api.minimax.chat/v1", //27
"https://api.deepseek.com", //28
"https://api.moonshot.cn", //29
"https://api.mistral.ai", //30
"https://api.groq.com/openai", //31
"", //32
"https://api.lingyiwanwu.com", //33
"", //34
"", //35
"https://api.cohere.ai/v1", //36
"https://api.stability.ai/v2beta", //37
"https://api.coze.com/open_api", //38
"", //39
"https://hunyuan.tencentcloudapi.com", //40
"", //41
"", //42
"", //43
"https://api.ideogram.ai", //44
"https://api.siliconflow.cn", //45
"", //46
"https://api.jina.ai", //47
"", //48
"", // 0
"https://api.openai.com", // 1
"https://oa.api2d.net", // 2
"", // 3
"https://api.closeai-proxy.xyz", // 4
"https://api.openai-sb.com", // 5
"https://api.openaimax.com", // 6
"https://api.ohmygpt.com", // 7
"", // 8
"https://api.caipacity.com", // 9
"https://api.aiproxy.io", // 10
"", // 11
"https://api.api2gpt.com", // 12
"https://api.aigc2d.com", // 13
"https://api.anthropic.com", // 14
"https://aip.baidubce.com", // 15
"https://open.bigmodel.cn", // 16
"https://dashscope.aliyuncs.com", // 17
"", // 18
"https://ai.360.cn", // 19
"https://openrouter.ai/api", // 20
"https://api.aiproxy.io", // 21
"https://fastgpt.run/api/openapi", // 22
"https://hunyuan.cloud.tencent.com", //23
"", //24
"", //25
"https://api.baichuan-ai.com", //26
"https://api.minimax.chat/v1", //27
"https://api.deepseek.com", //28
"https://api.moonshot.cn", //29
"https://api.mistral.ai", //30
"https://api.groq.com/openai", //31
"", //32
"https://api.lingyiwanwu.com", //33
"", //34
"", //35
"https://api.cohere.ai/v1", //36
"https://api.stability.ai/v2beta", //37
"https://api.coze.com/open_api", //38
"", //39
"https://hunyuan.tencentcloudapi.com", //40
"", //41
"", //42
"", //43
"https://api.ideogram.ai", //44
"https://api.siliconflow.cn", //45
"", //46
"https://api.jina.ai", //47
"", //48
"https://models.inference.ai.azure.com", //49
}

const (
Expand Down
37 changes: 37 additions & 0 deletions providers/github/base.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package github

import (
"one-api/common/requester"
"one-api/model"
"one-api/providers/base"
"one-api/providers/openai"
)

type GithubProviderFactory struct{}

// 创建 GithubProvider
func (f GithubProviderFactory) Create(channel *model.Channel) base.ProviderInterface {
config := getGithubConfig()
return &GithubProvider{
OpenAIProvider: openai.OpenAIProvider{
BaseProvider: base.BaseProvider{
Config: config,
Channel: channel,
Requester: requester.NewHTTPRequester(*channel.Proxy, openai.RequestErrorHandle),
},
BalanceAction: false,
},
}
}

func getGithubConfig() base.ProviderConfig {
return base.ProviderConfig{
BaseURL: "https://models.inference.ai.azure.com",
ChatCompletions: "/chat/completions",
Embeddings: "/embeddings",
}
}

type GithubProvider struct {
openai.OpenAIProvider
}
2 changes: 2 additions & 0 deletions providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"one-api/providers/coze"
"one-api/providers/deepseek"
"one-api/providers/gemini"
"one-api/providers/github"
"one-api/providers/groq"
"one-api/providers/hunyuan"
"one-api/providers/jina"
Expand Down Expand Up @@ -79,6 +80,7 @@ func init() {
config.ChannelTypeVertexAI: vertexai.VertexAIProviderFactory{},
config.ChannelTypeSiliconflow: siliconflow.SiliconflowProviderFactory{},
config.ChannelTypeJina: jina.JinaProviderFactory{},
config.ChannelTypeGithub: github.GithubProviderFactory{},
}
}

Expand Down
1 change: 1 addition & 0 deletions relay/relay_util/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ func init() {
config.ChannelTypeSiliconflow: "Siliconflow",
config.ChannelTypeJina: "Jina",
config.ChannelTypeRerank: "Rerank",
config.ChannelTypeGithub: "Github",
}
}
7 changes: 7 additions & 0 deletions web/src/constants/ChannelConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ export const CHANNEL_OPTIONS = {
color: 'orange',
url: 'https://portal.azure.com/'
},
49: {
key: 49,
text: 'Github',
value: 49,
color: 'default',
url: 'https://github.com/marketplace/models'
},
8: {
key: 8,
text: '自定义渠道',
Expand Down
11 changes: 11 additions & 0 deletions web/src/views/Channel/type/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,17 @@ const typeConfig = {
test_model: ''
},
modelGroup: 'Jina'
},
49: {
input: {
models: ['gpt-4o', 'gpt-4o-mini', 'text-embedding-3-large', 'text-embedding-3-small', 'Cohere-command-r-plus', 'Cohere-command-r'],
test_model: 'gpt-4o-mini'
},
prompt: {
key: '密钥信息请参考https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens',
base_url: 'https://models.inference.ai.azure.com'
},
modelGroup: 'Github'
}
};

Expand Down

0 comments on commit 8b0b529

Please sign in to comment.