Add openai response error handling

This commit is contained in:
Matt Low 2024-05-05 07:32:35 +00:00
parent 1b9a8f319c
commit bdaf6204f6

View File

@ -166,7 +166,14 @@ func (c *OpenAIClient) sendRequest(ctx context.Context, req *http.Request) (*htt
req.Header.Set("Authorization", "Bearer "+c.APIKey)
client := &http.Client{}
return client.Do(req.WithContext(ctx))
resp, err := client.Do(req.WithContext(ctx))
if resp.StatusCode != 200 {
bytes, _ := io.ReadAll(resp.Body)
return resp, fmt.Errorf("%v", string(bytes))
}
return resp, err
}
func (c *OpenAIClient) CreateChatCompletion(