break response if error in loop
This commit is contained in:
parent
a7c588549d
commit
cba0bbe5cc
15
handlers.go
15
handlers.go
@ -107,9 +107,6 @@ func nightmare(c *gin.Context) {
|
|||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
c.JSON(500, gin.H{
|
|
||||||
"error": "error reading response",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(line) < 6 {
|
if len(line) < 6 {
|
||||||
@ -124,9 +121,6 @@ func nightmare(c *gin.Context) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if chat_response.Error != nil {
|
if chat_response.Error != nil {
|
||||||
c.JSON(500, gin.H{
|
|
||||||
"error": chat_response.Error,
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if chat_response.Message.Content.Parts[0] == "" || chat_response.Message.Author.Role != "assistant" {
|
if chat_response.Message.Content.Parts[0] == "" || chat_response.Message.Author.Role != "assistant" {
|
||||||
@ -165,17 +159,11 @@ func nightmare(c *gin.Context) {
|
|||||||
// Stream the response to the client
|
// Stream the response to the client
|
||||||
response_string, err := json.Marshal(completions_response)
|
response_string, err := json.Marshal(completions_response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(500, gin.H{
|
|
||||||
"error": "error parsing response",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if chat_request.Stream {
|
if chat_request.Stream {
|
||||||
_, err = c.Writer.WriteString("data: " + string(response_string) + "\n\n")
|
_, err = c.Writer.WriteString("data: " + string(response_string) + "\n\n")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(500, gin.H{
|
|
||||||
"error": "error writing response",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,9 +190,6 @@ func nightmare(c *gin.Context) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(500, gin.H{
|
|
||||||
"error": "error parsing response",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(200, full_response)
|
c.JSON(200, full_response)
|
||||||
|
Reference in New Issue
Block a user