-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimages-example.go
72 lines (59 loc) · 1.46 KB
/
images-example.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"fmt"
"os"
"github.com/Kardbord/gopenai/authentication"
"github.com/Kardbord/gopenai/images"
_ "github.com/joho/godotenv/autoload"
)
const OpenAITokenEnv = "OPENAI_API_KEY"
func init() {
key := os.Getenv(OpenAITokenEnv)
authentication.SetAPIKey(key)
}
func create(model, size string) (*images.Response, error) {
const prompt = "A cute baby sea otter"
fmt.Printf("Creating from model=\"%s\", prompt=\"%s\"\n", model, prompt)
resp, _, err := images.MakeModeratedCreationRequest(&images.CreationRequest{
Prompt: prompt,
Size: size,
User: "https://github.com/Kardbord/gopenai",
Model: model,
}, nil)
if err != nil {
return nil, err
}
fmt.Printf("Generated: %s\n", resp.Data[0].URL)
return resp, nil
}
func variation(imagename, image string) error {
fmt.Printf("Generating a variation...")
resp, err := images.MakeVariationRequest(&images.VariationRequest{
Image: image,
ImageName: imagename,
Size: images.Dalle2SmallImage,
User: "https://github.com/Kardbord/gopenai",
}, nil)
if err != nil {
return err
}
fmt.Printf("Generated: %s\n", resp.Data[0].URL)
return nil
}
func main() {
resp, err := create(images.ModelDalle2, images.Dalle2SmallImage)
if err != nil {
fmt.Println(err)
return
}
err = variation("Original", resp.Data[0].URL)
if err != nil {
fmt.Println(err)
return
}
_, err = create(images.ModelDalle3, images.Dalle3SquareImage)
if err != nil {
fmt.Println(err)
return
}
}