Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
66831a1b
authored
Feb 24, 2025
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Add support for different Dify bot types and request URLs
parent
fd44ac7c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
2 deletions
+28
-2
relay/channel/dify/adaptor.go
+28
-2
No files found.
relay/channel/dify/adaptor.go
View file @
66831a1b
...
@@ -9,9 +9,18 @@ import (
...
@@ -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
...
@@ -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
...
@@ -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
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment