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
9e2433e2
authored
Feb 14, 2025
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: Improve OpenAI stream data parsing and handling
parent
025b6d12
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
relay/channel/openai/relay-openai.go
+6
-6
No files found.
relay/channel/openai/relay-openai.go
View file @
9e2433e2
...
@@ -5,6 +5,9 @@ import (
...
@@ -5,6 +5,9 @@ import (
"bytes"
"bytes"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"github.com/bytedance/gopkg/util/gopool"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
"github.com/pkg/errors"
"github.com/pkg/errors"
"io"
"io"
"math"
"math"
...
@@ -20,10 +23,6 @@ import (
...
@@ -20,10 +23,6 @@ import (
"strings"
"strings"
"sync"
"sync"
"time"
"time"
"github.com/bytedance/gopkg/util/gopool"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
)
)
func
sendStreamData
(
c
*
gin
.
Context
,
data
string
,
forceFormat
bool
)
error
{
func
sendStreamData
(
c
*
gin
.
Context
,
data
string
,
forceFormat
bool
)
error
{
...
@@ -91,11 +90,12 @@ func OaiStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.Rel
...
@@ -91,11 +90,12 @@ func OaiStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.Rel
if
len
(
data
)
<
6
{
// ignore blank line or wrong format
if
len
(
data
)
<
6
{
// ignore blank line or wrong format
continue
continue
}
}
if
data
[
:
6
]
!=
"data: "
&&
data
[
:
6
]
!=
"[DONE]"
{
if
data
[
:
5
]
!=
"data: "
&&
data
[
:
6
]
!=
"[DONE]"
{
continue
continue
}
}
mu
.
Lock
()
mu
.
Lock
()
data
=
data
[
6
:
]
data
=
data
[
5
:
]
data
=
strings
.
TrimSpace
(
data
)
if
!
strings
.
HasPrefix
(
data
,
"[DONE]"
)
{
if
!
strings
.
HasPrefix
(
data
,
"[DONE]"
)
{
if
lastStreamData
!=
""
{
if
lastStreamData
!=
""
{
err
:=
sendStreamData
(
c
,
lastStreamData
,
forceFormat
)
err
:=
sendStreamData
(
c
,
lastStreamData
,
forceFormat
)
...
...
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