-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmain.go
More file actions
46 lines (38 loc) · 800 Bytes
/
main.go
File metadata and controls
46 lines (38 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"context"
"log"
"github.com/k0kubun/pp/v3"
"go.jetify.com/ai"
"go.jetify.com/ai/api"
"go.jetify.com/ai/provider/openai"
)
func example() error {
// Create a model
model := openai.NewLanguageModel("gpt-4o-mini")
// Generate text
response, err := ai.GenerateTextStr(
context.Background(),
"Explain what artificial intelligence is in simple terms",
ai.WithModel(model),
ai.WithMaxOutputTokens(100),
)
if err != nil {
return err
}
// Print the response:
printResponse(response)
return nil
}
func printResponse(response *api.Response) {
response.ProviderMetadata = nil
response.Warnings = nil
printer := pp.New()
printer.SetOmitEmpty(true)
_, _ = printer.Print(response)
}
func main() {
if err := example(); err != nil {
log.Fatal(err)
}
}