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
24200df4
authored
May 04, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: remove unnecessary call to helper.Done and adjust data rendering in ClaudeChunkData
parent
4cc1f2b4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
3 additions
and
5 deletions
+3
-5
relay/channel/openai/relay-openai.go
+0
-2
relay/helper/common.go
+1
-1
relay/helper/stream_scanner.go
+2
-2
No files found.
relay/channel/openai/relay-openai.go
View file @
24200df4
...
@@ -724,8 +724,6 @@ func OaiResponsesStreamHandler(c *gin.Context, resp *http.Response, info *relayc
...
@@ -724,8 +724,6 @@ func OaiResponsesStreamHandler(c *gin.Context, resp *http.Response, info *relayc
return
true
return
true
})
})
helper
.
Done
(
c
)
if
usage
.
CompletionTokens
==
0
{
if
usage
.
CompletionTokens
==
0
{
// 计算输出文本的 token 数量
// 计算输出文本的 token 数量
tempStr
:=
responseTextBuilder
.
String
()
tempStr
:=
responseTextBuilder
.
String
()
...
...
relay/helper/common.go
View file @
24200df4
...
@@ -37,7 +37,7 @@ func ClaudeData(c *gin.Context, resp dto.ClaudeResponse) error {
...
@@ -37,7 +37,7 @@ func ClaudeData(c *gin.Context, resp dto.ClaudeResponse) error {
func
ClaudeChunkData
(
c
*
gin
.
Context
,
resp
dto
.
ClaudeResponse
,
data
string
)
{
func
ClaudeChunkData
(
c
*
gin
.
Context
,
resp
dto
.
ClaudeResponse
,
data
string
)
{
c
.
Render
(
-
1
,
common
.
CustomEvent
{
Data
:
fmt
.
Sprintf
(
"event: %s
\n
"
,
resp
.
Type
)})
c
.
Render
(
-
1
,
common
.
CustomEvent
{
Data
:
fmt
.
Sprintf
(
"event: %s
\n
"
,
resp
.
Type
)})
c
.
Render
(
-
1
,
common
.
CustomEvent
{
Data
:
fmt
.
Sprintf
(
"data: %s
\n
"
,
data
)})
c
.
Render
(
-
1
,
common
.
CustomEvent
{
Data
:
fmt
.
Sprintf
(
"data: %s"
,
data
)})
if
flusher
,
ok
:=
c
.
Writer
.
(
http
.
Flusher
);
ok
{
if
flusher
,
ok
:=
c
.
Writer
.
(
http
.
Flusher
);
ok
{
flusher
.
Flush
()
flusher
.
Flush
()
}
}
...
...
relay/helper/stream_scanner.go
View file @
24200df4
...
@@ -32,7 +32,7 @@ func StreamScannerHandler(c *gin.Context, resp *http.Response, info *relaycommon
...
@@ -32,7 +32,7 @@ func StreamScannerHandler(c *gin.Context, resp *http.Response, info *relaycommon
defer
resp
.
Body
.
Close
()
defer
resp
.
Body
.
Close
()
streamingTimeout
:=
time
.
Duration
(
constant
.
StreamingTimeout
)
*
time
.
Second
streamingTimeout
:=
time
.
Duration
(
constant
.
StreamingTimeout
)
*
time
.
Second
if
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"o
1"
)
||
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"o3
"
)
{
if
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"o"
)
{
// twice timeout for thinking model
// twice timeout for thinking model
streamingTimeout
*=
2
streamingTimeout
*=
2
}
}
...
@@ -115,7 +115,7 @@ func StreamScannerHandler(c *gin.Context, resp *http.Response, info *relaycommon
...
@@ -115,7 +115,7 @@ func StreamScannerHandler(c *gin.Context, resp *http.Response, info *relaycommon
}
}
data
=
data
[
5
:
]
data
=
data
[
5
:
]
data
=
strings
.
TrimLeft
(
data
,
" "
)
data
=
strings
.
TrimLeft
(
data
,
" "
)
data
=
strings
.
TrimSuffix
(
data
,
"
\
"
"
)
data
=
strings
.
TrimSuffix
(
data
,
"
\
r
"
)
if
!
strings
.
HasPrefix
(
data
,
"[DONE]"
)
{
if
!
strings
.
HasPrefix
(
data
,
"[DONE]"
)
{
info
.
SetFirstResponseTime
()
info
.
SetFirstResponseTime
()
writeMutex
.
Lock
()
// Lock before writing
writeMutex
.
Lock
()
// Lock before writing
...
...
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