Repository navigation
Expand file tree
/
Copy pathwavespeed.go
More file actions
132 lines (119 loc) · 4.26 KB
/
Copy pathwavespeed.go
File metadata and controls
132 lines (119 loc) · 4.26 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package wavespeed
import (
"github.com/WaveSpeedAI/wavespeed-go/api"
)
// Client is the WaveSpeed API client.
type Client = api.Client
// ClientOption configures a Client created with NewClient.
type ClientOption = api.ClientOption
// SubmissionError indicates that a prediction submission POST failed without
// a definitive response. The task may or may not have been created, so the
// SDK never retries the submission POST automatically.
type SubmissionError = api.SubmissionError
// RunDetail contains detailed information about a task execution.
type RunDetail = api.RunDetail
// RunNoThrowResult is the result of the Client.RunNoThrow method.
type RunNoThrowResult = api.RunNoThrowResult
// RunOption configures optional parameters for Run.
type RunOption = api.RunOption
// UploadOption configures optional parameters for Upload.
type UploadOption = api.UploadOption
// NewClient creates a new WaveSpeed API client with optional configuration.
// It is re-exported from the api subpackage so users never need to import it:
//
// client := wavespeed.NewClient(wavespeed.WithAPIKey("your-api-key"))
var NewClient = api.NewClient
// Client option constructors
var (
// WithAPIKey sets the API key for the client.
WithAPIKey = api.WithAPIKey
// WithBaseURL sets the base URL for the client.
WithBaseURL = api.WithBaseURL
// WithClientName sets the client name reported in the X-Client-Name header.
WithClientName = api.WithClientName
// WithConnectionTimeout sets the connection timeout in seconds.
WithConnectionTimeout = api.WithConnectionTimeout
// WithReadTimeout overrides the per-request timeout in seconds (defaults: 30
// result/GET, 60 async submit, 120 upload; not sync submit); it never limits
// the overall wait.
WithReadTimeout = api.WithReadTimeout
// WithClientMaxRetries sets the maximum number of task-level retries.
WithClientMaxRetries = api.WithClientMaxRetries
// WithMaxConnectionRetries sets the maximum number of HTTP connection retries.
WithMaxConnectionRetries = api.WithMaxConnectionRetries
// WithRetryInterval sets the base interval between retries in seconds.
WithRetryInterval = api.WithRetryInterval
)
// Run option constructors
var (
// WithTimeout sets the maximum time in seconds to wait for completion.
// By default there is no limit; 0 or a negative value also means no limit.
WithTimeout = api.WithTimeout
// WithPollInterval sets the interval between status checks.
WithPollInterval = api.WithPollInterval
// WithSyncMode enables or disables synchronous mode.
WithSyncMode = api.WithSyncMode
// WithMaxRetries sets the maximum number of task-level retries.
WithMaxRetries = api.WithMaxRetries
// WithUploadTimeout sets the timeout for file upload.
WithUploadTimeout = api.WithUploadTimeout
)
// Run executes a model and waits for the output.
//
// Args:
// - model: Model identifier (e.g., "wavespeed-ai/z-image/turbo").
// - input: Input parameters for the model.
// - opts: Optional parameters (WithTimeout, WithSyncMode, etc.)
//
// Returns:
// - map[string]any containing "outputs" array with model outputs.
//
// Example:
//
// import "github.com/WaveSpeedAI/wavespeed-go"
//
// // Simple usage
// output, err := wavespeed.Run(
// "wavespeed-ai/z-image/turbo",
// map[string]any{"prompt": "Cat"},
// )
// if err != nil {
// log.Fatal(err)
// }
// fmt.Println(output["outputs"].([]any)[0])
//
// // With options
// output, err := wavespeed.Run(
// "wavespeed-ai/z-image/turbo",
// map[string]any{"prompt": "Cat"},
// wavespeed.WithSyncMode(true),
// wavespeed.WithTimeout(60),
// )
func Run(model string, input map[string]any, opts ...RunOption) (map[string]any, error) {
return api.Run(model, input, opts...)
}
// Upload uploads a file to WaveSpeed.
//
// Args:
// - file: File path string to upload.
// - opts: Optional upload options (WithUploadTimeout, etc.)
//
// Returns:
// - URL of the uploaded file.
//
// Example:
//
// import "github.com/WaveSpeedAI/wavespeed-go"
//
// // Simple usage
// url, err := wavespeed.Upload("/path/to/image.png")
// if err != nil {
// log.Fatal(err)
// }
// fmt.Println(url)
//
// // With timeout
// url, err := wavespeed.Upload("/path/to/image.png", wavespeed.WithUploadTimeout(30))
func Upload(file string, opts ...UploadOption) (string, error) {
return api.Upload(file, opts...)
}