1 Star 0 Fork 0

ledao/go-openai

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
error_accumulator.go 693 Bytes
一键复制 编辑 原始数据 按行查看 历史
package openai
import (
"bytes"
"fmt"
"io"
)
type ErrorAccumulator interface {
Write(p []byte) error
Bytes() []byte
}
type errorBuffer interface {
io.Writer
Len() int
Bytes() []byte
}
type DefaultErrorAccumulator struct {
Buffer errorBuffer
}
func NewErrorAccumulator() ErrorAccumulator {
return &DefaultErrorAccumulator{
Buffer: &bytes.Buffer{},
}
}
func (e *DefaultErrorAccumulator) Write(p []byte) error {
_, err := e.Buffer.Write(p)
if err != nil {
return fmt.Errorf("error accumulator write error, %w", err)
}
return nil
}
func (e *DefaultErrorAccumulator) Bytes() (errBytes []byte) {
if e.Buffer.Len() == 0 {
return
}
errBytes = e.Buffer.Bytes()
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/ledao/go-openai.git
git@gitee.com:ledao/go-openai.git
ledao
go-openai
go-openai
v1.0.7

搜索帮助