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
|
package flux
import (
"fmt"
"io/ioutil"
"time"
)
func Example() {
client := NewClient("http://xe-flux.flycast")
if _, err := client.HealthCheck(); err != nil {
fmt.Println("Error health checking:", err)
panic(err)
}
// Example of using the Predict method
predictionReq := PredictionRequest{
Input: Input{
Prompt: "A beautiful sunrise over the mountains",
NumOutputs: 1,
GuidanceScale: 7.5,
MaxSequenceLength: 256,
NumInferenceSteps: 50,
PromptStrength: 0.8,
OutputFormat: "png",
OutputQuality: 90,
},
ID: "example-prediction-id",
CreatedAt: time.Now().Format(time.RFC3339),
OutputFilePrefix: "output",
Webhook: "http://example.com/webhook",
WebhookEventsFilter: []string{"start", "completed"},
}
predictionResp, err := client.Predict(predictionReq)
if err != nil {
fmt.Println("Error predicting:", err)
} else {
fmt.Println("PredictionResponse:", predictionResp)
}
// Example of using the PredictIdempotent method
predictionResp, err = client.PredictIdempotent("example-prediction-id", predictionReq)
if err != nil {
fmt.Println("Error predicting idempotent:", err)
} else {
fmt.Println("PredictIdempotentResponse:", predictionResp)
}
// Example of using the CancelPrediction method
resp, err := client.CancelPrediction("example-prediction-id")
if err != nil {
fmt.Println("Error cancelling prediction:", err)
} else {
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("CancelPrediction response:", string(body))
resp.Body.Close()
}
}
|