You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe this could be a duplicate of #452, but the discussion there diverged from the actual point.
Problem
When using the CreateChatCompletionStream, and hitting rate limits errors (Code: 429), the returned error nor the stream doesn't contain the http headers. I need to retrieve 'Retry-After' headers to pause the job for the specified time.
Those headers are standard and provide the amount of time (seconds/time-stamp on 'Retry-After', milliseconds on 'Retry-After-Ms').
If a 429 is obtained, what I do with CreateChatCompletion is to parse those headers and pause to go routine for the specified amount of time.
resp, err:=client.client.CreateChatCompletion(ctx, *openaiReq)
iferr!=nil {
...checkstatuscode ...
parseAndPause(resp.Header()) // even with error, we still get `resp`
}
But for CreateChatCompletionStream the above code could not work as:
stream, err:=client.client.CreateChatCompletionStream(ctx, *openaiReq)
iferr!=nil {
...checkstatuscode ...
parseAndPause(stream.Header()) // stream.header could be nil, thus this panics
}
I believe this could be a duplicate of #452, but the discussion there diverged from the actual point.
Problem
When using the
CreateChatCompletionStream
, and hitting rate limits errors (Code: 429), the returned error nor the stream doesn't contain the http headers. I need to retrieve 'Retry-After' headers to pause the job for the specified time.If a 429 is obtained, what I do with
CreateChatCompletion
is to parse those headers and pause to go routine for the specified amount of time.But for
CreateChatCompletionStream
the above code could not work as:Proposed solution
I believe here:
https://github.com/sashabaranov/go-openai/blob/7c145ebb4be68610bc3bb5377b754944307d44fd/client.go#L166C1-L172C3
Those returns should add the response into the
streamReader
struct.The text was updated successfully, but these errors were encountered: