Skip to content

Commit 285a738

Browse files
authored
Merge pull request #6 from meguminnnnnnnnn/feat/option
feat: CreateChatCompletionStream add ChatCompletionRequestOption
2 parents 5178926 + 4008612 commit 285a738

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

chat_stream.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package openai
22

33
import (
44
"context"
5+
"io"
56
"net/http"
67
)
78

@@ -78,6 +79,7 @@ type ChatCompletionStream struct {
7879
func (c *Client) CreateChatCompletionStream(
7980
ctx context.Context,
8081
request ChatCompletionRequest,
82+
opts ...ChatCompletionRequestOption,
8183
) (stream *ChatCompletionStream, err error) {
8284
urlSuffix := chatCompletionsSuffix
8385
if !checkEndpointSupportsModel(urlSuffix, request.Model) {
@@ -91,11 +93,26 @@ func (c *Client) CreateChatCompletionStream(
9193
return
9294
}
9395

96+
ccOpts := &chatCompletionRequestOptions{}
97+
for _, opt := range opts {
98+
opt(ccOpts)
99+
}
100+
101+
body := any(request)
102+
if ccOpts.RequestBodySetter != nil {
103+
var newBody io.Reader
104+
newBody, err = c.getNewRequestBody(request, ccOpts.RequestBodySetter)
105+
if err != nil {
106+
return stream, err
107+
}
108+
body = newBody
109+
}
110+
94111
req, err := c.newRequest(
95112
ctx,
96113
http.MethodPost,
97114
c.fullURL(urlSuffix, withModel(request.Model)),
98-
withBody(request),
115+
withBody(body),
99116
)
100117
if err != nil {
101118
return nil, err

0 commit comments

Comments
 (0)