feat: get header from sendRequestRaw (#694)

* feat: get header from sendRequestRaw

* Fix ci lint
This commit is contained in:
Qiying Wang
2024-04-06 03:15:54 +08:00
committed by GitHub
parent 0925563e86
commit 2646bce71c
3 changed files with 16 additions and 12 deletions

View File

@@ -38,6 +38,12 @@ func (h *httpHeader) GetRateLimitHeaders() RateLimitHeaders {
return newRateLimitHeaders(h.Header())
}
type RawResponse struct {
io.ReadCloser
httpHeader
}
// NewClient creates new OpenAI API client.
func NewClient(authToken string) *Client {
config := DefaultConfig(authToken)
@@ -134,8 +140,8 @@ func (c *Client) sendRequest(req *http.Request, v Response) error {
return decodeResponse(res.Body, v)
}
func (c *Client) sendRequestRaw(req *http.Request) (body io.ReadCloser, err error) {
resp, err := c.config.HTTPClient.Do(req)
func (c *Client) sendRequestRaw(req *http.Request) (response RawResponse, err error) {
resp, err := c.config.HTTPClient.Do(req) //nolint:bodyclose // body should be closed by outer function
if err != nil {
return
}
@@ -144,7 +150,10 @@ func (c *Client) sendRequestRaw(req *http.Request) (body io.ReadCloser, err erro
err = c.handleErrorResp(resp)
return
}
return resp.Body, nil
response.SetHeader(resp.Header)
response.ReadCloser = resp.Body
return
}
func sendRequestStream[T streamable](client *Client, req *http.Request) (*streamReader[T], error) {