mirror of
https://github.com/openai/openai-go.git
synced 2026-04-01 00:57:11 +09:00
35 lines
564 B
Go
35 lines
564 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/openai/openai-go/v3"
|
|
)
|
|
|
|
func main() {
|
|
client := openai.NewClient()
|
|
|
|
ctx := context.Background()
|
|
|
|
question := "Write me a haiku"
|
|
|
|
print("> ")
|
|
println(question)
|
|
println()
|
|
params := openai.ChatCompletionNewParams{
|
|
Messages: []openai.ChatCompletionMessageParamUnion{
|
|
openai.UserMessage(question),
|
|
},
|
|
Seed: openai.Int(0),
|
|
Model: openai.ChatModelGPT4o,
|
|
}
|
|
|
|
completion, err := client.Chat.Completions.New(ctx, params)
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
println(completion.Choices[0].Message.Content)
|
|
}
|