Update README.md
This commit is contained in:
50
README.md
50
README.md
@@ -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>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user