mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 04:50:14 +09:00
60 lines
2.3 KiB
Go
60 lines
2.3 KiB
Go
package adapter
|
|
|
|
import (
|
|
"chat/adapter/azure"
|
|
"chat/adapter/baichuan"
|
|
"chat/adapter/bing"
|
|
"chat/adapter/claude"
|
|
adaptercommon "chat/adapter/common"
|
|
"chat/adapter/coze"
|
|
"chat/adapter/dashscope"
|
|
"chat/adapter/deepseek"
|
|
"chat/adapter/dify"
|
|
"chat/adapter/hunyuan"
|
|
"chat/adapter/midjourney"
|
|
"chat/adapter/openai"
|
|
"chat/adapter/palm2"
|
|
"chat/adapter/skylark"
|
|
"chat/adapter/slack"
|
|
"chat/adapter/sparkdesk"
|
|
"chat/adapter/zhinao"
|
|
"chat/adapter/zhipuai"
|
|
"chat/globals"
|
|
"fmt"
|
|
)
|
|
|
|
var channelFactories = map[string]adaptercommon.FactoryCreator{
|
|
globals.OpenAIChannelType: openai.NewChatInstanceFromConfig,
|
|
globals.AzureOpenAIChannelType: azure.NewChatInstanceFromConfig,
|
|
globals.ClaudeChannelType: claude.NewChatInstanceFromConfig,
|
|
globals.SlackChannelType: slack.NewChatInstanceFromConfig,
|
|
globals.BingChannelType: bing.NewChatInstanceFromConfig,
|
|
globals.PalmChannelType: palm2.NewChatInstanceFromConfig,
|
|
globals.SparkdeskChannelType: sparkdesk.NewChatInstanceFromConfig,
|
|
globals.ChatGLMChannelType: zhipuai.NewChatInstanceFromConfig,
|
|
globals.QwenChannelType: dashscope.NewChatInstanceFromConfig,
|
|
globals.HunyuanChannelType: hunyuan.NewChatInstanceFromConfig,
|
|
globals.BaichuanChannelType: baichuan.NewChatInstanceFromConfig,
|
|
globals.SkylarkChannelType: skylark.NewChatInstanceFromConfig,
|
|
globals.ZhinaoChannelType: zhinao.NewChatInstanceFromConfig,
|
|
globals.MidjourneyChannelType: midjourney.NewChatInstanceFromConfig,
|
|
globals.DeepseekChannelType: deepseek.NewChatInstanceFromConfig,
|
|
globals.DifyChannelType: dify.NewChatInstanceFromConfig,
|
|
globals.CozeChannelType: coze.NewChatInstanceFromConfig,
|
|
|
|
globals.MoonshotChannelType: openai.NewChatInstanceFromConfig, // openai format
|
|
globals.GroqChannelType: openai.NewChatInstanceFromConfig, // openai format
|
|
}
|
|
|
|
func createChatRequest(conf globals.ChannelConfig, props *adaptercommon.ChatProps, hook globals.Hook) error {
|
|
props.Model = conf.GetModelReflect(props.OriginalModel)
|
|
props.Proxy = conf.GetProxy()
|
|
|
|
factoryType := conf.GetType()
|
|
if factory, ok := channelFactories[factoryType]; ok {
|
|
return factory(conf).CreateStreamChatRequest(props, hook)
|
|
}
|
|
|
|
return fmt.Errorf("unknown channel type %s (channel #%d)", conf.GetType(), conf.GetId())
|
|
}
|