-
Notifications
You must be signed in to change notification settings - Fork 11
/
example_test.go
85 lines (66 loc) · 1.73 KB
/
example_test.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
73
74
75
76
77
78
79
80
81
82
83
84
85
package replicate_test
import (
"context"
"fmt"
"strings"
"github.com/replicate/replicate-go"
)
func ExampleClient_Run() {
ctx := context.TODO()
r8, err := replicate.NewClient(replicate.WithTokenFromEnv())
if err != nil {
panic(err)
}
model := "bytedance/sdxl-lightning-4step"
version := "5f24084160c9089501c1b3545d9be3c27883ae2239b6f412990e82d4a6210f8f"
input := replicate.PredictionInput{
"prompt": "An astronaut riding a rainbow unicorn",
}
output, err := r8.Run(ctx, fmt.Sprintf("%s:%s", model, version), input, nil)
if err != nil {
panic(err)
}
fmt.Printf("Generated %d image(s)\n", len(output.([]any)))
// Output: Generated 1 image(s)
}
func ExampleClient_CreatePrediction() {
ctx := context.TODO()
r8, err := replicate.NewClient(replicate.WithTokenFromEnv())
if err != nil {
panic(err)
}
// https://replicate.com/bytedance/sdxl-lightning-4step
version := "5f24084160c9089501c1b3545d9be3c27883ae2239b6f412990e82d4a6210f8f"
input := replicate.PredictionInput{
"prompt": "An astronaut riding a rainbow unicorn",
}
prediction, err := r8.CreatePrediction(ctx, version, input, nil, false)
if err != nil {
panic(err)
}
err = r8.Wait(ctx, prediction)
if err != nil {
panic(err)
}
fmt.Println(prediction.Status)
// Output: succeeded
}
func ExampleClient_SearchModels() {
ctx := context.TODO()
r8, err := replicate.NewClient(replicate.WithTokenFromEnv())
if err != nil {
panic(err)
}
query := "llama"
modelsPage, err := r8.SearchModels(ctx, query)
if err != nil {
panic(err)
}
for _, model := range modelsPage.Results {
if model.Owner == "meta" && strings.HasPrefix(model.Name, "meta-llama-3") {
fmt.Printf("Found Meta Llama 3 model")
break
}
}
// Output: Found Meta Llama 3 model
}