go-openai
go-openai copied to clipboard
the chat stream api should check return error message.
https://github.com/sashabaranov/go-gpt3/blob/575c4e4adbf3e12dea780c735fa9c19062440e11/chat_stream.go#L40
In the recv method is that it does not check the response status code, and it returns an empty message instead of an error message when the status is not 200.
To fix this issue, the recv method should check the status code of the response and return an error message if the status code is not 200. The error message should be of type ErrorResponse with an APIError field containing the appropriate error information.
type APIError struct {
Code *string `json:"code,omitempty"`
Message string `json:"message"`
Param *string `json:"param,omitempty"`
Type string `json:"type"`
StatusCode int `json:"-"`
}
type ErrorResponse struct {
Error *APIError `json:"error,omitempty"`
}
@NICEXAI
Good advice, I have the same problem, I will solve it.
When will this problem be solved, thanks @NICEXAI
Happy to jump in if you need.
Good advice, I also have trouble with it.
Btw, this part of the library has been upgraded quite a bit, see https://github.com/sashabaranov/go-openai/blob/master/stream_reader.go
@sashabaranov thanks,this issue will be closed.