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
22
33import (
44 "context"
5+ "io"
56 "net/http"
67)
78
@@ -78,6 +79,7 @@ type ChatCompletionStream struct {
7879func (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
You can’t perform that action at this time.
0 commit comments