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
2e45163f
authored
Jul 07, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add env DIFY_DEBUG
parent
ba43598f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
2 deletions
+17
-2
README.md
+1
-0
common/env.go
+12
-0
constant/env.go
+1
-0
relay/channel/dify/relay-dify.go
+3
-2
No files found.
README.md
View file @
2e45163f
...
...
@@ -72,6 +72,7 @@
## 比原版One API多出的配置
-
`STREAMING_TIMEOUT`
:设置流式一次回复的超时时间,默认为 30 秒
-
`DIFY_DEBUG`
:设置 Dify 渠道是否输出工作流和节点信息到客户端,默认为
`true`
, 可选值为
`true`
和
`false`
## 部署
### 部署要求
...
...
common/env.go
View file @
2e45163f
...
...
@@ -24,3 +24,15 @@ func GetEnvOrDefaultString(env string, defaultValue string) string {
}
return
os
.
Getenv
(
env
)
}
func
GetEnvOrDefaultBool
(
env
string
,
defaultValue
bool
)
bool
{
if
env
==
""
||
os
.
Getenv
(
env
)
==
""
{
return
defaultValue
}
b
,
err
:=
strconv
.
ParseBool
(
os
.
Getenv
(
env
))
if
err
!=
nil
{
SysError
(
fmt
.
Sprintf
(
"failed to parse %s: %s, using default value: %t"
,
env
,
err
.
Error
(),
defaultValue
))
return
defaultValue
}
return
b
}
constant/env.go
View file @
2e45163f
...
...
@@ -5,3 +5,4 @@ import (
)
var
StreamingTimeout
=
common
.
GetEnvOrDefault
(
"STREAMING_TIMEOUT"
,
30
)
var
DifyDebug
=
common
.
GetEnvOrDefaultBool
(
"DIFY_DEBUG"
,
true
)
relay/channel/dify/relay-dify.go
View file @
2e45163f
...
...
@@ -7,6 +7,7 @@ import (
"io"
"net/http"
"one-api/common"
"one-api/constant"
"one-api/dto"
relaycommon
"one-api/relay/common"
"one-api/service"
...
...
@@ -48,9 +49,9 @@ func streamResponseDify2OpenAI(difyResponse DifyChunkChatCompletionResponse) *dt
Model
:
"dify"
,
}
var
choice
dto
.
ChatCompletionsStreamResponseChoice
if
difyResponse
.
Event
==
"workflow_started"
{
if
constant
.
DifyDebug
&&
difyResponse
.
Event
==
"workflow_started"
{
choice
.
Delta
.
SetContentString
(
"Workflow: "
+
difyResponse
.
Data
.
WorkflowId
+
"
\n
"
)
}
else
if
difyResponse
.
Event
==
"node_started"
{
}
else
if
constant
.
DifyDebug
&&
difyResponse
.
Event
==
"node_started"
{
choice
.
Delta
.
SetContentString
(
"Node: "
+
difyResponse
.
Data
.
NodeId
+
"
\n
"
)
}
else
if
difyResponse
.
Event
==
"message"
{
choice
.
Delta
.
SetContentString
(
difyResponse
.
Answer
)
...
...
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