openai-go
openai-go copied to clipboard
When unmarshaling ChatCompletionChunk, the sdk doesn't check if the input is valid
Using the snippet below:
chunk = openai.ChatCompletionChunk{}
err := json.Unmarshal([]byte(`[]`), &chunk)
fmt.Printf("%+v\n", err)
The err is nil and the chunk is successfully unmarshalled, though it will have empty value except that the raw field is [].
Sometimes, errors are ignored during decoding: https://github.com/openai/openai-go/blob/c0414f15a9f4065adee2ed96a4dcd4d4cb9708aa/internal/apijson/decoder.go#L408-L411
https://github.com/openai/openai-go/blob/c0414f15a9f4065adee2ed96a4dcd4d4cb9708aa/internal/apijson/decoder.go#L430-L435
https://github.com/openai/openai-go/blob/c0414f15a9f4065adee2ed96a4dcd4d4cb9708aa/internal/apijson/decoder.go#L482-L486
What is the reason behind them?