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
fce31dd1
authored
Jun 27, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 支持设置流模式超时时间(gemini, claude)
parent
f83a1626
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
7 deletions
+17
-7
relay/channel/claude/relay-claude.go
+8
-3
relay/channel/gemini/relay-gemini.go
+8
-3
relay/channel/openai/relay-openai.go
+1
-1
No files found.
relay/channel/claude/relay-claude.go
View file @
fce31dd1
...
...
@@ -8,6 +8,7 @@ import (
"io"
"net/http"
"one-api/common"
"one-api/constant"
"one-api/dto"
relaycommon
"one-api/relay/common"
"one-api/service"
...
...
@@ -267,8 +268,8 @@ func claudeStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.
}
return
0
,
nil
,
nil
})
dataChan
:=
make
(
chan
string
)
stopChan
:=
make
(
chan
bool
)
dataChan
:=
make
(
chan
string
,
5
)
stopChan
:=
make
(
chan
bool
,
2
)
go
func
()
{
for
scanner
.
Scan
()
{
data
:=
scanner
.
Text
()
...
...
@@ -276,7 +277,11 @@ func claudeStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.
continue
}
data
=
strings
.
TrimPrefix
(
data
,
"data: "
)
dataChan
<-
data
if
!
common
.
SafeSendStringTimeout
(
dataChan
,
data
,
constant
.
StreamingTimeout
)
{
// send data timeout, stop the stream
common
.
LogError
(
c
,
"send data timeout, stop the stream"
)
break
}
}
stopChan
<-
true
}()
...
...
relay/channel/gemini/relay-gemini.go
View file @
fce31dd1
...
...
@@ -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"
...
...
@@ -163,8 +164,8 @@ func streamResponseGeminiChat2OpenAI(geminiResponse *GeminiChatResponse) *dto.Ch
func
geminiChatStreamHandler
(
c
*
gin
.
Context
,
resp
*
http
.
Response
,
info
*
relaycommon
.
RelayInfo
)
(
*
dto
.
OpenAIErrorWithStatusCode
,
string
)
{
responseText
:=
""
dataChan
:=
make
(
chan
string
)
stopChan
:=
make
(
chan
bool
)
dataChan
:=
make
(
chan
string
,
5
)
stopChan
:=
make
(
chan
bool
,
2
)
scanner
:=
bufio
.
NewScanner
(
resp
.
Body
)
scanner
.
Split
(
func
(
data
[]
byte
,
atEOF
bool
)
(
advance
int
,
token
[]
byte
,
err
error
)
{
if
atEOF
&&
len
(
data
)
==
0
{
...
...
@@ -187,7 +188,11 @@ func geminiChatStreamHandler(c *gin.Context, resp *http.Response, info *relaycom
}
data
=
strings
.
TrimPrefix
(
data
,
"
\"
text
\"
:
\"
"
)
data
=
strings
.
TrimSuffix
(
data
,
"
\"
"
)
dataChan
<-
data
if
!
common
.
SafeSendStringTimeout
(
dataChan
,
data
,
constant
.
StreamingTimeout
)
{
// send data timeout, stop the stream
common
.
LogError
(
c
,
"send data timeout, stop the stream"
)
break
}
}
stopChan
<-
true
}()
...
...
relay/channel/openai/relay-openai.go
View file @
fce31dd1
...
...
@@ -54,7 +54,7 @@ func OpenaiStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.
}
if
!
common
.
SafeSendStringTimeout
(
dataChan
,
data
,
constant
.
StreamingTimeout
)
{
// send data timeout, stop the stream
common
.
Log
Info
(
c
,
"send data timeout, stop the stream"
)
common
.
Log
Error
(
c
,
"send data timeout, stop the stream"
)
break
}
data
=
data
[
6
:
]
...
...
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