PullRequestInc / go-gpt3

An OpenAI GPT-3 API client enabling Go/Golang programs to interact with the gpt3 APIs.
MIT License
393 stars 65 forks source link

context deadline exceeded (Client.Timeout or context cancellation while reading body) #24

Open qimo2020 opened 1 year ago

qimo2020 commented 1 year ago

hello The code reported an error: “context deadline exceeded (Client.Timeout or context cancellation while reading body)”

qimo2020 commented 1 year ago

hello

Still return “context deadline exceeded (Client.Timeout or context cancellation while reading body)” codes: httpClient := &http.Client{ Timeout: time.Duration(600 * time.Second), } client := gpt3.NewClient(apiKey, gpt3.WithHTTPClient(httpClient)) I used streaming call(client.CompletionStreamWithEngine), but the problem was not solved

letschers commented 1 year ago

Recently I started having this problem too, even if on curl request the request is working properly (ie is not an outage from openAI). Do you guys have any clue?

letschers commented 1 year ago

@qimo2020 to fix this you just need to set a timeout to their client when instantiating it, like in the example below:

client := gpt3.NewClient(apiKey, gpt3.WithTimeout(time.Second*300))

If you dont set a custom timeout, will be used their standard timeout time which is 30 seconds (you can read the snippet here)