File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package openai
2
2
3
3
import (
4
4
"context"
5
+ "io"
5
6
"net/http"
6
7
)
7
8
@@ -78,6 +79,7 @@ type ChatCompletionStream struct {
78
79
func (c * Client ) CreateChatCompletionStream (
79
80
ctx context.Context ,
80
81
request ChatCompletionRequest ,
82
+ opts ... ChatCompletionRequestOption ,
81
83
) (stream * ChatCompletionStream , err error ) {
82
84
urlSuffix := chatCompletionsSuffix
83
85
if ! checkEndpointSupportsModel (urlSuffix , request .Model ) {
@@ -91,11 +93,26 @@ func (c *Client) CreateChatCompletionStream(
91
93
return
92
94
}
93
95
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
+
94
111
req , err := c .newRequest (
95
112
ctx ,
96
113
http .MethodPost ,
97
114
c .fullURL (urlSuffix , withModel (request .Model )),
98
- withBody (request ),
115
+ withBody (body ),
99
116
)
100
117
if err != nil {
101
118
return nil , err
You can’t perform that action at this time.
0 commit comments