Files
openai.openai-go/examples/responses-streaming/main.go
Jacob Zimmerman 1c8754ff90 chore(examples): migrate to latest version (#444)
* chore(docs): typo fix (#400)

* fix(accumulator)!: update casing (#401)

* fix(client): use scanner for streaming

* feat(api)!: improve naming and remove assistants

* fix(client): increase max stream buffer size

* fix(client): correctly set stream key for multipart

* fix(client)!: rename file array param variant

* chore(examples): migrate to latest

* migrate vector stores

---------

Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
2025-05-19 12:56:12 -04:00

40 lines
722 B
Go

package main
import (
"context"
"github.com/openai/openai-go"
"github.com/openai/openai-go/responses"
)
func main() {
client := openai.NewClient()
ctx := context.Background()
question := "Tell me about briefly about Doug Engelbart"
stream := client.Responses.NewStreaming(ctx, responses.ResponseNewParams{
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String(question)},
Model: openai.ChatModelGPT4,
})
var completeText string
for stream.Next() {
data := stream.Current()
print(data.Delta)
if data.JSON.Text.Valid() {
println()
println("Finished Content")
completeText = data.Text
break
}
}
if stream.Err() != nil {
panic(stream.Err())
}
_ = completeText
}