Skip to content

Commit

Permalink
:art copilot non-streaming output
Browse files Browse the repository at this point in the history
  • Loading branch information
v_frgfeng committed Feb 19, 2024
1 parent b7fb291 commit 2e0e078
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions api/copilot/copilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func CompletionsRequest(c *gin.Context, req map[string]interface{}, copilotToken
}

w := c.Writer

global.SugarLog.Infow("CompletionsRequest start of processor", "respContentType", respContentType, "statusCode", resp.StatusCode())
if strings.Contains(respContentType, "text/plain") { // 有错误信息
body, err := io.ReadAll(reader)
if err != nil {
Expand All @@ -226,7 +226,8 @@ func CompletionsRequest(c *gin.Context, req map[string]interface{}, copilotToken
global.SugarLog.Infow("CompletionsHandler response error", "body", bodyStr, "copilotToken", copilotToken)
response.FailWithOpenAIError(resp.StatusCode(), bodyStr, c)
return nil
} else if strings.Contains(respContentType, "application/json") { // json 格式 非流式
}
if b, ok := req["stream"]; ok && b.(bool) == false { // json 格式 非流式
utils.SetJsonHeaders(c)
flusher, _ := w.(http.Flusher)
body, readErr := io.ReadAll(reader)
Expand All @@ -236,7 +237,7 @@ func CompletionsRequest(c *gin.Context, req map[string]interface{}, copilotToken
}
w.Write(body)
flusher.Flush()
global.SugarLog.Infow("CompletionsRequest execute success, content type is json")
global.SugarLog.Infow("CompletionsRequest end of processor, stream is true")
return
}

Expand All @@ -253,7 +254,7 @@ func CompletionsRequest(c *gin.Context, req map[string]interface{}, copilotToken
w.Write(line)
flusher.Flush()
}
global.SugarLog.Infow("CompletionsRequest execute success")
global.SugarLog.Infow("CompletionsRequest end of processor")
return
}

Expand Down

0 comments on commit 2e0e078

Please sign in to comment.