feat: Add support for different Dify bot types and request URLs
This commit is contained in:
@@ -9,9 +9,18 @@ import (
|
|||||||
"one-api/dto"
|
"one-api/dto"
|
||||||
"one-api/relay/channel"
|
"one-api/relay/channel"
|
||||||
relaycommon "one-api/relay/common"
|
relaycommon "one-api/relay/common"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
BotTypeChatFlow = 1 // chatflow default
|
||||||
|
BotTypeAgent = 2
|
||||||
|
BotTypeWorkFlow = 3
|
||||||
|
BotTypeCompletion = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
type Adaptor struct {
|
type Adaptor struct {
|
||||||
|
BotType int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Adaptor) ConvertAudioRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.AudioRequest) (io.Reader, error) {
|
func (a *Adaptor) ConvertAudioRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.AudioRequest) (io.Reader, error) {
|
||||||
@@ -25,10 +34,28 @@ func (a *Adaptor) ConvertImageRequest(c *gin.Context, info *relaycommon.RelayInf
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Adaptor) Init(info *relaycommon.RelayInfo) {
|
func (a *Adaptor) Init(info *relaycommon.RelayInfo) {
|
||||||
|
if strings.HasPrefix(info.UpstreamModelName, "agent") {
|
||||||
|
a.BotType = BotTypeAgent
|
||||||
|
} else if strings.HasPrefix(info.UpstreamModelName, "workflow") {
|
||||||
|
a.BotType = BotTypeWorkFlow
|
||||||
|
} else if strings.HasPrefix(info.UpstreamModelName, "chat") {
|
||||||
|
a.BotType = BotTypeCompletion
|
||||||
|
} else {
|
||||||
|
a.BotType = BotTypeChatFlow
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
|
func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
|
||||||
return fmt.Sprintf("%s/v1/chat-messages", info.BaseUrl), nil
|
switch a.BotType {
|
||||||
|
case BotTypeWorkFlow:
|
||||||
|
return fmt.Sprintf("%s/v1/workflows/run", info.BaseUrl), nil
|
||||||
|
case BotTypeCompletion:
|
||||||
|
return fmt.Sprintf("%s/v1/completion-messages", info.BaseUrl), nil
|
||||||
|
case BotTypeAgent:
|
||||||
|
fallthrough
|
||||||
|
default:
|
||||||
|
return fmt.Sprintf("%s/v1/chat-messages", info.BaseUrl), nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Header, info *relaycommon.RelayInfo) error {
|
func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Header, info *relaycommon.RelayInfo) error {
|
||||||
@@ -53,7 +80,6 @@ func (a *Adaptor) ConvertEmbeddingRequest(c *gin.Context, info *relaycommon.Rela
|
|||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (a *Adaptor) DoRequest(c *gin.Context, info *relaycommon.RelayInfo, requestBody io.Reader) (any, error) {
|
func (a *Adaptor) DoRequest(c *gin.Context, info *relaycommon.RelayInfo, requestBody io.Reader) (any, error) {
|
||||||
return channel.DoApiRequest(a, c, info, requestBody)
|
return channel.DoApiRequest(a, c, info, requestBody)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user