mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-18 17:46:37 +08:00
fix: Improve OpenAI stream data parsing
This commit is contained in:
parent
8df4a2670b
commit
1ac79a8126
@ -34,7 +34,7 @@ func StreamHandler(c *gin.Context, resp *http.Response, relayMode int) (*model.E
|
||||
|
||||
doneRendered := false
|
||||
for scanner.Scan() {
|
||||
data := scanner.Text()
|
||||
data := NormalizeDataLine(scanner.Text())
|
||||
if len(data) < dataPrefixLength { // ignore blank line or wrong format
|
||||
continue
|
||||
}
|
||||
|
@ -21,3 +21,11 @@ func ErrorWrapper(err error, code string, statusCode int) *model.ErrorWithStatus
|
||||
StatusCode: statusCode,
|
||||
}
|
||||
}
|
||||
|
||||
func NormalizeDataLine(data string) string {
|
||||
if strings.HasPrefix(data, "data:") {
|
||||
content := strings.TrimLeft(data[len("data:"):], " ")
|
||||
return "data: " + content
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user