fix: stream return EOF when openai return error (#184)

* fix: stream return EOF when openai return error

* perf: add error accumulator

* fix: golangci-lint

* fix: unmarshal error possibly null

* fix: error accumulator

* test: error accumulator use interface and add test code

* test: error accumulator add test code

* refactor: use stream reader to re-use stream code

* refactor: stream reader use generics
This commit is contained in:
Liu Shuang
2023-03-22 13:32:47 +08:00
committed by GitHub
parent aa149c1bf8
commit a5a945ad14
8 changed files with 372 additions and 107 deletions

15
unmarshaler.go Normal file
View File

@@ -0,0 +1,15 @@
package openai
import (
"encoding/json"
)
type unmarshaler interface {
unmarshal(data []byte, v any) error
}
type jsonUnmarshaler struct{}
func (jm *jsonUnmarshaler) unmarshal(data []byte, v any) error {
return json.Unmarshal(data, v)
}