record all json request body

This commit is contained in:
2024-02-16 22:42:48 +08:00
parent 46ee30ced7
commit e8b89fc41a

View File

@@ -224,6 +224,13 @@ func processRequest(c *gin.Context, upstream *OPENAI_UPSTREAM, record *Record, s
log.Println(record.Response) log.Println(record.Response)
} else { } else {
// record request body
if strings.HasPrefix(c.Request.Header.Get("Content-Type"), "application/json") {
record.Body = string(inBody)
} else {
record.Body = "binary data"
}
// record response // record response
// stream mode // stream mode
if strings.HasPrefix(contentType, "text/event-stream") { if strings.HasPrefix(contentType, "text/event-stream") {
@@ -246,10 +253,8 @@ func processRequest(c *gin.Context, upstream *OPENAI_UPSTREAM, record *Record, s
} }
record.Response += chunk.Choices[0].Delta.Content record.Response += chunk.Choices[0].Delta.Content
} }
} else if strings.HasPrefix(contentType, "text") && strings.HasPrefix(record.Model, "whisper") { } else if strings.HasPrefix(contentType, "text") {
// whisper model response
record.Response = string(resp) record.Response = string(resp)
record.Body = ""
} else if strings.HasPrefix(contentType, "application/json") { } else if strings.HasPrefix(contentType, "application/json") {
var fetchResp FetchModeResponse var fetchResp FetchModeResponse
err := json.Unmarshal(resp, &fetchResp) err := json.Unmarshal(resp, &fetchResp)