go-openai icon indicating copy to clipboard operation
go-openai copied to clipboard

the chat stream api should check return error message.

Open wwsheng009 opened this issue 2 years ago • 4 comments

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"`
}

wwsheng009 avatar Mar 03 '23 14:03 wwsheng009

@NICEXAI

sashabaranov avatar Mar 03 '23 14:03 sashabaranov

Good advice, I have the same problem, I will solve it.

NICEXAI avatar Mar 06 '23 03:03 NICEXAI

When will this problem be solved, thanks @NICEXAI

smile-magic avatar Mar 15 '23 09:03 smile-magic

Happy to jump in if you need.

abdulrabbani00 avatar Mar 16 '23 00:03 abdulrabbani00

Good advice, I also have trouble with it.

helios741 avatar Apr 10 '23 12:04 helios741

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 avatar Apr 10 '23 13:04 sashabaranov

@sashabaranov thanks,this issue will be closed.

wwsheng009 avatar Apr 12 '23 01:04 wwsheng009