wavespeed 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -73,6 +73,54 @@ async function generateImage(): Promise<void> {
|
|
|
73
73
|
generateImage().catch(console.error);
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
+
### Manual Status Polling Example
|
|
77
|
+
|
|
78
|
+
If you need more control over the polling process, you can use the `create` method and manually poll for status updates:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import WaveSpeed from 'wavespeed';
|
|
82
|
+
|
|
83
|
+
// Initialize the client with your API key
|
|
84
|
+
const client = new WaveSpeed('YOUR_API_KEY');
|
|
85
|
+
|
|
86
|
+
async function generateWithManualPolling(): Promise<void> {
|
|
87
|
+
// Create a prediction without waiting
|
|
88
|
+
const prediction = await client.create('wavespeed-ai/flux-dev', {
|
|
89
|
+
prompt: 'A beautiful mountain landscape at sunset',
|
|
90
|
+
size: '1024*1024',
|
|
91
|
+
num_inference_steps: 28,
|
|
92
|
+
guidance_scale: 5.0,
|
|
93
|
+
num_images: 1
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
console.log(`Prediction created with ID: ${prediction.id}`);
|
|
97
|
+
console.log(`Initial status: ${prediction.status}`);
|
|
98
|
+
|
|
99
|
+
// Manually poll for status updates
|
|
100
|
+
let currentPrediction = prediction;
|
|
101
|
+
|
|
102
|
+
while (currentPrediction.status !== 'completed' && currentPrediction.status !== 'failed') {
|
|
103
|
+
console.log('Prediction still processing, checking again in 2 seconds...');
|
|
104
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
105
|
+
|
|
106
|
+
// Reload the prediction to get the latest status
|
|
107
|
+
currentPrediction = await currentPrediction.reload();
|
|
108
|
+
console.log(`Updated status: ${currentPrediction.status}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (currentPrediction.status === 'completed') {
|
|
112
|
+
console.log('Prediction completed successfully!');
|
|
113
|
+
currentPrediction.outputs.forEach((imgUrl, i) => {
|
|
114
|
+
console.log(`Image ${i+1}: ${imgUrl}`);
|
|
115
|
+
});
|
|
116
|
+
} else {
|
|
117
|
+
console.error(`Prediction failed: ${currentPrediction.error}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
generateWithManualPolling().catch(console.error);
|
|
122
|
+
```
|
|
123
|
+
|
|
76
124
|
## API Reference
|
|
77
125
|
|
|
78
126
|
### WaveSpeed Client
|
package/package.json
CHANGED