File tree 1 file changed +0
-50
lines changed
1 file changed +0
-50
lines changed Original file line number Diff line number Diff line change @@ -134,53 +134,3 @@ func main() {
134
134
}
135
135
```
136
136
</details >
137
-
138
-
139
- <details >
140
- <summary >GPT-3 streaming completion</summary >
141
-
142
- ``` go
143
- package main
144
-
145
- import (
146
- " errors"
147
- " context"
148
- " fmt"
149
- " io"
150
- openai " github.com/sashabaranov/go-openai"
151
- )
152
-
153
- func main () {
154
- c := openai.NewClient (" your token" )
155
- ctx := context.Background ()
156
-
157
- req := openai.CompletionRequest {
158
- Model: openai.GPT3Ada ,
159
- MaxTokens: 5 ,
160
- Prompt: " Lorem ipsum" ,
161
- Stream: true ,
162
- }
163
- stream , err := c.CreateCompletionStream (ctx, req)
164
- if err != nil {
165
- return
166
- }
167
- defer stream.Close ()
168
-
169
- for {
170
- response , err := stream.Recv ()
171
- if errors.Is (err, io.EOF ) {
172
- fmt.Println (" Stream finished" )
173
- return
174
- }
175
-
176
- if err != nil {
177
- fmt.Printf (" Stream error: %v \n " , err)
178
- return
179
- }
180
-
181
-
182
- fmt.Printf (" Stream response: %v \n " , response)
183
- }
184
- }
185
- ```
186
- </details >
You can’t perform that action at this time.
0 commit comments