refactor: use http.NewRequestWithContext instead of http.NewRequest (#97)

This commit is contained in:
bestgopher
2023-03-02 14:27:09 +08:00
committed by GitHub
parent de9a632138
commit 58d99eb220
11 changed files with 17 additions and 32 deletions

View File

@@ -79,7 +79,7 @@ func (c *Client) CreateCompletionStream(
}
urlSuffix := "/completions"
req, err := http.NewRequest("POST", c.fullURL(urlSuffix), bytes.NewBuffer(reqBytes))
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.fullURL(urlSuffix), bytes.NewBuffer(reqBytes))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "text/event-stream")
req.Header.Set("Cache-Control", "no-cache")
@@ -89,7 +89,6 @@ func (c *Client) CreateCompletionStream(
return
}
req = req.WithContext(ctx)
resp, err := c.config.HTTPClient.Do(req) //nolint:bodyclose // body is closed in stream.Close()
if err != nil {
return