Update README.md

This commit is contained in:
sashabaranov
2023-03-04 15:23:39 +04:00
committed by GitHub
parent 114a7d14b2
commit d59ab48c58

View File

@@ -134,53 +134,3 @@ func main() {
} }
``` ```
</details> </details>
<details>
<summary>GPT-3 streaming completion</summary>
```go
package main
import (
"errors"
"context"
"fmt"
"io"
openai "github.com/sashabaranov/go-openai"
)
func main() {
c := openai.NewClient("your token")
ctx := context.Background()
req := openai.CompletionRequest{
Model: openai.GPT3Ada,
MaxTokens: 5,
Prompt: "Lorem ipsum",
Stream: true,
}
stream, err := c.CreateCompletionStream(ctx, req)
if err != nil {
return
}
defer stream.Close()
for {
response, err := stream.Recv()
if errors.Is(err, io.EOF) {
fmt.Println("Stream finished")
return
}
if err != nil {
fmt.Printf("Stream error: %v\n", err)
return
}
fmt.Printf("Stream response: %v\n", response)
}
}
```
</details>