Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
优化模拟api的返回 (#257)
Browse files Browse the repository at this point in the history
* imitate api

* bug fix: imitate api mod deletion

* bug fix: imitate api mod deletion v2

* simulate api return result optimization

* 修复 issues #247 ,imitate报错返回不是合法json的问题

* 优化模拟api的返回,使其更加接近官方api返回
  • Loading branch information
CoolProgramme authored Sep 14, 2023
1 parent 116219c commit 0027c91
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/imitate/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ func Handler(c *gin.Context, response *http.Response, stream bool, id string, mo
if originalResponse.Message.Metadata.MessageType != "next" && originalResponse.Message.Metadata.MessageType != "continue" || originalResponse.Message.EndTurn != nil {
continue
}
if (len(originalResponse.Message.Content.Parts) == 0 || originalResponse.Message.Content.Parts[0] == "") && !isRole {
continue
}
responseString := ConvertToString(&originalResponse, &previousText, isRole, id, model)
isRole = false
if stream {
Expand All @@ -313,6 +316,9 @@ func Handler(c *gin.Context, response *http.Response, stream bool, id string, mo

} else {
if stream {
if finishReason == "" {
finishReason = "stop"
}
finalLine := StopChunk(finishReason, id, model)
_, err := c.Writer.WriteString("data: " + finalLine.String() + "\n\n")
if err != nil {
Expand Down

0 comments on commit 0027c91

Please sign in to comment.