1 Star 0 Fork 0

糍粑/funk-open-ai

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
request_builder.go 753 Bytes
一键复制 编辑 原始数据 按行查看 历史
sashabaranov 提交于 2023-03-15 13:16 . Add testable request builder (#162)
package openai
import (
"bytes"
"context"
"net/http"
)
type requestBuilder interface {
build(ctx context.Context, method, url string, request any) (*http.Request, error)
}
type httpRequestBuilder struct {
marshaller marshaller
}
func newRequestBuilder() *httpRequestBuilder {
return &httpRequestBuilder{
marshaller: &jsonMarshaller{},
}
}
func (b *httpRequestBuilder) build(ctx context.Context, method, url string, request any) (*http.Request, error) {
if request == nil {
return http.NewRequestWithContext(ctx, method, url, nil)
}
var reqBytes []byte
reqBytes, err := b.marshaller.marshal(request)
if err != nil {
return nil, err
}
return http.NewRequestWithContext(
ctx,
method,
url,
bytes.NewBuffer(reqBytes),
)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/pc_859107393/funk-open-ai.git
git@gitee.com:pc_859107393/funk-open-ai.git
pc_859107393
funk-open-ai
funk-open-ai
master

搜索帮助