diff --git a/constant/channel.go b/constant/channel.go index 6d3a5d92827d..5c248e3cb98a 100644 --- a/constant/channel.go +++ b/constant/channel.go @@ -54,6 +54,7 @@ const ( ChannelTypeDoubaoVideo = 54 ChannelTypeSora = 55 ChannelTypeReplicate = 56 + ChannelTypeStreamLake = 57 ChannelTypeDummy // this one is only for count, do not add any channel after this ) @@ -116,6 +117,7 @@ var ChannelBaseURLs = []string{ "https://ark.cn-beijing.volces.com", //54 "https://api.openai.com", //55 "https://api.replicate.com", //56 + "https://wanqing.streamlakeapi.com/api/gateway/v1/endpoints", //57 } var ChannelTypeNames = map[int]string{ diff --git a/relay/channel/streamlake/adaptor.go b/relay/channel/streamlake/adaptor.go new file mode 100644 index 000000000000..adecb51f0d8e --- /dev/null +++ b/relay/channel/streamlake/adaptor.go @@ -0,0 +1,100 @@ +package streamlake + +import ( + "errors" + "fmt" + "io" + "net/http" + "strings" + + "github.com/QuantumNous/new-api/constant" + "github.com/QuantumNous/new-api/dto" + "github.com/QuantumNous/new-api/relay/channel" + "github.com/QuantumNous/new-api/relay/channel/openai" + relaycommon "github.com/QuantumNous/new-api/relay/common" + "github.com/QuantumNous/new-api/types" + + "github.com/gin-gonic/gin" +) + +type Adaptor struct { +} + +func (a *Adaptor) ConvertGeminiRequest(*gin.Context, *relaycommon.RelayInfo, *dto.GeminiChatRequest) (any, error) { + //TODO implement me + return nil, errors.New("not implemented") +} + +func (a *Adaptor) ConvertClaudeRequest(c *gin.Context, info *relaycommon.RelayInfo, req *dto.ClaudeRequest) (any, error) { + //TODO implement me + return nil, errors.New("not implemented") +} + +func (a *Adaptor) ConvertAudioRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.AudioRequest) (io.Reader, error) { + //TODO implement me + return nil, errors.New("not supported") +} + +func (a *Adaptor) ConvertImageRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.ImageRequest) (any, error) { + //TODO implement me + return nil, errors.New("not implemented") +} + +func (a *Adaptor) Init(info *relaycommon.RelayInfo) { +} + +func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) { + if info == nil { + return "", errors.New("streamlake adaptor: relay info is nil") + } + if info.ChannelBaseUrl == "" { + info.ChannelBaseUrl = constant.ChannelBaseURLs[constant.ChannelTypeStreamLake] + } + requestPath := info.RequestURLPath + if requestPath == "" { + return info.ChannelBaseUrl, nil + } + requestPath = strings.TrimPrefix(requestPath, "/v1") + return relaycommon.GetFullRequestURL(info.ChannelBaseUrl, requestPath, info.ChannelType), nil +} + +func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Header, info *relaycommon.RelayInfo) error { + channel.SetupApiRequestHeader(info, c, req) + req.Set("Authorization", fmt.Sprintf("Bearer %s", info.ApiKey)) + return nil +} + +func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayInfo, request *dto.GeneralOpenAIRequest) (any, error) { + return request, nil +} + +func (a *Adaptor) ConvertOpenAIResponsesRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.OpenAIResponsesRequest) (any, error) { + // TODO implement me + return nil, errors.New("not implemented") +} + +func (a *Adaptor) DoRequest(c *gin.Context, info *relaycommon.RelayInfo, requestBody io.Reader) (any, error) { + return channel.DoApiRequest(a, c, info, requestBody) +} + +func (a *Adaptor) ConvertRerankRequest(c *gin.Context, relayMode int, request dto.RerankRequest) (any, error) { + return request, nil +} + +func (a *Adaptor) ConvertEmbeddingRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.EmbeddingRequest) (any, error) { + return request, nil +} + +func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, info *relaycommon.RelayInfo) (usage any, err *types.NewAPIError) { + adaptor := openai.Adaptor{} + usage, err = adaptor.DoResponse(c, resp, info) + return +} + +func (a *Adaptor) GetModelList() []string { + return ModelList +} + +func (a *Adaptor) GetChannelName() string { + return ChannelName +} diff --git a/relay/channel/streamlake/constants.go b/relay/channel/streamlake/constants.go new file mode 100644 index 000000000000..64e5364893bf --- /dev/null +++ b/relay/channel/streamlake/constants.go @@ -0,0 +1,9 @@ +package streamlake + +var ModelList = []string{ + "KAT-Coder-Exp-72B-1010", + "KAT-Coder-Pro-V1", + "KAT-Coder-Air-V1", +} + +var ChannelName = "StreamLake" diff --git a/web/src/constants/channel.constants.js b/web/src/constants/channel.constants.js index 0d487958e9cf..ed809522370c 100644 --- a/web/src/constants/channel.constants.js +++ b/web/src/constants/channel.constants.js @@ -184,6 +184,11 @@ export const CHANNEL_OPTIONS = [ color: 'blue', label: 'Replicate', }, + { + value: 57, + color: 'blue', + label: 'StreamLake', + }, ]; export const MODEL_TABLE_PAGE_SIZE = 10;