@rohitaryal/whisk-api 3.0.1 → 3.1.0
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/dist/Whisk.d.ts +6 -0
- package/dist/Whisk.js +63 -0
- package/dist/index.js +0 -1
- package/package.json +1 -1
package/dist/Whisk.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Media } from "./Media.js";
|
|
2
2
|
import { Project } from "./Project.js";
|
|
3
|
+
import { PromptConfig } from "./Types.js";
|
|
3
4
|
export declare class Account {
|
|
4
5
|
private cookie;
|
|
5
6
|
private authToken?;
|
|
@@ -43,4 +44,9 @@ export declare class Whisk {
|
|
|
43
44
|
* @param projectName Name of the project
|
|
44
45
|
*/
|
|
45
46
|
newProject(projectName?: string): Promise<Project>;
|
|
47
|
+
/**
|
|
48
|
+
* Uses imagefx's api to generate image.
|
|
49
|
+
* Advantage here is it can generate multiple images in single request
|
|
50
|
+
*/
|
|
51
|
+
generateImage(input: string | PromptConfig, count?: number): Promise<Media>;
|
|
46
52
|
}
|
package/dist/Whisk.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ImageGenerationModel } from "./Constants.js";
|
|
1
2
|
import { Media } from "./Media.js";
|
|
2
3
|
import { Project } from "./Project.js";
|
|
3
4
|
import { request } from "./Utils.js";
|
|
@@ -162,4 +163,66 @@ export class Whisk {
|
|
|
162
163
|
});
|
|
163
164
|
return new Project(projectInfo.workflowId, this.account);
|
|
164
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Uses imagefx's api to generate image.
|
|
168
|
+
* Advantage here is it can generate multiple images in single request
|
|
169
|
+
*/
|
|
170
|
+
async generateImage(input, count = 1) {
|
|
171
|
+
if (typeof input === "string") {
|
|
172
|
+
input = {
|
|
173
|
+
seed: 0,
|
|
174
|
+
prompt: input,
|
|
175
|
+
model: "IMAGEN_3_5",
|
|
176
|
+
aspectRatio: "IMAGE_ASPECT_RATIO_LANDSCAPE",
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
if (!input.seed)
|
|
180
|
+
input.seed = 0;
|
|
181
|
+
if (!count)
|
|
182
|
+
count = 1;
|
|
183
|
+
if (!input.model)
|
|
184
|
+
input.model = "IMAGEN_3_5";
|
|
185
|
+
if (!input.aspectRatio)
|
|
186
|
+
input.aspectRatio = "IMAGE_ASPECT_RATIO_LANDSCAPE";
|
|
187
|
+
if (!input.prompt?.trim?.())
|
|
188
|
+
throw new Error("prompt is required");
|
|
189
|
+
if (!Object.values(ImageGenerationModel).includes(input.model)) {
|
|
190
|
+
throw new Error(`'${input.model}': invalid image generation model provided for imagefx`);
|
|
191
|
+
}
|
|
192
|
+
if (count < 1 || count > 8) {
|
|
193
|
+
throw new Error(`'${count}': image generation count must be between 1 and 8 (1 <= count <= 8)`);
|
|
194
|
+
}
|
|
195
|
+
const generationResponse = await request("https://aisandbox-pa.googleapis.com/v1:runImageFx", {
|
|
196
|
+
headers: { "authorization": `Bearer ${await this.account.getToken()}` },
|
|
197
|
+
body: JSON.stringify({
|
|
198
|
+
"userInput": {
|
|
199
|
+
"candidatesCount": count,
|
|
200
|
+
"prompts": [input.prompt],
|
|
201
|
+
"seed": input.seed
|
|
202
|
+
},
|
|
203
|
+
"clientContext": {
|
|
204
|
+
"sessionId": ";1768371666629",
|
|
205
|
+
"tool": "IMAGE_FX"
|
|
206
|
+
},
|
|
207
|
+
"modelInput": {
|
|
208
|
+
"modelNameType": input.model
|
|
209
|
+
},
|
|
210
|
+
"aspectRatio": input.aspectRatio
|
|
211
|
+
}),
|
|
212
|
+
method: "POST",
|
|
213
|
+
});
|
|
214
|
+
return generationResponse.imagePanels[0].generatedImages.map((img) => {
|
|
215
|
+
return new Media({
|
|
216
|
+
seed: img.seed,
|
|
217
|
+
prompt: img.prompt,
|
|
218
|
+
workflowId: img.workflowId,
|
|
219
|
+
encodedMedia: img.encodedImage,
|
|
220
|
+
mediaGenerationId: img.mediaGenerationId,
|
|
221
|
+
aspectRatio: img.aspectRatio,
|
|
222
|
+
mediaType: "IMAGE",
|
|
223
|
+
model: img.modelNameType,
|
|
224
|
+
account: this.account
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
}
|
|
165
228
|
}
|
package/dist/index.js
CHANGED