feat: get header from sendRequestRaw (#694)
* feat: get header from sendRequestRaw * Fix ci lint
This commit is contained in:
15
client.go
15
client.go
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user