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
5f137378
authored
Jul 17, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: try to fix panic #369
parent
7638a92d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
9 deletions
+16
-9
relay/channel/openai/relay-openai.go
+4
-1
service/relay.go
+12
-8
No files found.
relay/channel/openai/relay-openai.go
View file @
5f137378
...
...
@@ -53,7 +53,10 @@ func OpenaiStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.
}
data
=
data
[
6
:
]
if
!
strings
.
HasPrefix
(
data
,
"[DONE]"
)
{
service
.
StringData
(
c
,
data
)
err
:=
service
.
StringData
(
c
,
data
)
if
err
!=
nil
{
common
.
LogError
(
c
,
"streaming error: "
+
err
.
Error
())
}
streamItems
=
append
(
streamItems
,
data
)
}
}
...
...
service/relay.go
View file @
5f137378
...
...
@@ -2,10 +2,10 @@ package service
import
(
"encoding/json"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"one-api/common"
"strings"
)
func
SetEventStreamHeaders
(
c
*
gin
.
Context
)
{
...
...
@@ -16,11 +16,16 @@ func SetEventStreamHeaders(c *gin.Context) {
c
.
Writer
.
Header
()
.
Set
(
"X-Accel-Buffering"
,
"no"
)
}
func
StringData
(
c
*
gin
.
Context
,
str
string
)
{
str
=
strings
.
TrimPrefix
(
str
,
"data: "
)
str
=
strings
.
TrimSuffix
(
str
,
"
\r
"
)
func
StringData
(
c
*
gin
.
Context
,
str
string
)
error
{
//
str = strings.TrimPrefix(str, "data: ")
//
str = strings.TrimSuffix(str, "\r")
c
.
Render
(
-
1
,
common
.
CustomEvent
{
Data
:
"data: "
+
str
})
c
.
Writer
.
Flush
()
if
c
.
Writer
!=
nil
{
c
.
Writer
.
Flush
()
}
else
{
return
errors
.
New
(
"writer is nil"
)
}
return
nil
}
func
ObjectData
(
c
*
gin
.
Context
,
object
interface
{})
error
{
...
...
@@ -28,12 +33,11 @@ func ObjectData(c *gin.Context, object interface{}) error {
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error marshalling object: %w"
,
err
)
}
StringData
(
c
,
string
(
jsonData
))
return
nil
return
StringData
(
c
,
string
(
jsonData
))
}
func
Done
(
c
*
gin
.
Context
)
{
StringData
(
c
,
"[DONE]"
)
_
=
StringData
(
c
,
"[DONE]"
)
}
func
GetResponseID
(
c
*
gin
.
Context
)
string
{
...
...
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