mirror of
https://github.com/openai/openai-go.git
synced 2026-04-02 01:19:53 +09:00
* 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>
40 lines
722 B
Go
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
|
|
}
|