Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
sashabaranov authored Mar 4, 2023
1 parent 114a7d1 commit d59ab48
Showing 1 changed file with 0 additions and 50 deletions.
50 changes: 0 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,53 +134,3 @@ func main() {
}
```
</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>

0 comments on commit d59ab48

Please sign in to comment.