Skip to content

Commit d783555

Browse files
author
shenhaofang
committed
feat: add MakeChatReqBytes to return http request body bytes
1 parent 7d79b35 commit d783555

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

client.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (c *AIClient) RetrieveFile(method string, fileID string) (*FileInfo, error)
148148
return &res.FileInfo, err
149149
}
150150

151-
func (c *AIClient) MakeChatRequest(method string, param OpenAIChatParam) (*AIRequest, error) {
151+
func (c *AIClient) MakeChatReqBytes(param OpenAIChatParam) (reqByts []byte, err error) {
152152
if param.Model == "" {
153153
param.Model = "gpt-3.5-turbo-0301" //gpt-3.5-turbo or gpt-3.5-turbo-0301
154154
}
@@ -182,11 +182,19 @@ func (c *AIClient) MakeChatRequest(method string, param OpenAIChatParam) (*AIReq
182182
if param.PresencePenalty > 2 || param.PresencePenalty < (-2) {
183183
param.PresencePenalty = 0.6
184184
}
185-
reqByts, err := json.Marshal(param)
185+
reqByts, err = json.Marshal(param)
186186
if err != nil {
187187
err = errors.Wrap(err, "[ai_client]marshal open ai request error")
188188
return nil, err
189189
}
190+
return reqByts, nil
191+
}
192+
193+
func (c *AIClient) MakeChatRequest(method string, param OpenAIChatParam) (*AIRequest, error) {
194+
reqByts, err := c.MakeChatReqBytes(param)
195+
if err != nil {
196+
return nil, err
197+
}
190198

191199
reqBuffer := bytes.NewBuffer(reqByts)
192200
if method == "" {

0 commit comments

Comments
 (0)