Skip to content

Commit addc6eb

Browse files
committed
[Components] letzai #16541
Sources - New Image - New Image Edit Actions - Create New Image - Get Image Information - Create Image Edit
1 parent 539790b commit addc6eb

File tree

13 files changed

+950
-283
lines changed

13 files changed

+950
-283
lines changed

components/letzai/actions/create-image-edit/create-image-edit.mjs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { parseObject } from "../../common/utils.mjs";
12
import letzai from "../../letzai.app.mjs";
2-
import { axios } from "@pipedream/platform";
33

44
export default {
55
key: "letzai-create-image-edit",
66
name: "Create Image Edit",
7-
description: "Creates an image edit task that modifies an existing image using inpainting or outpainting in LetzAI. [See the documentation](https://letz.ai/docs/api)",
8-
version: "0.0.{{ts}}",
7+
description: "Creates an image edit task that modifies an existing image using inpainting or outpainting in LetzAI. [See the documentation](https://api.letz.ai/doc#/image-edit/image_edit_create)",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
1111
letzai,
@@ -14,6 +14,7 @@ export default {
1414
letzai,
1515
"mode",
1616
],
17+
reloadProps: true,
1718
},
1819
originalImageCompletionId: {
1920
propDefinition: [
@@ -79,22 +80,27 @@ export default {
7980
optional: true,
8081
},
8182
},
83+
async additionalProps(props) {
84+
if (this.mode === "in") {
85+
props.mask.optional = false;
86+
}
87+
return {};
88+
},
8289
async run({ $ }) {
83-
const data = {
84-
mode: this.mode,
85-
original_image_completion_id: this.originalImageCompletionId,
86-
image_url: this.imageUrl,
87-
prompt: this.prompt,
88-
mask: this.mask,
89-
width: this.width,
90-
height: this.height,
91-
image_completions_count: this.imageCompletionsCount,
92-
settings: this.settings,
93-
webhook_url: this.webhookUrl,
94-
};
90+
const {
91+
letzai,
92+
settings,
93+
...data
94+
} = this;
9595

96-
const response = await this.letzai.createImageEditTask(data);
97-
$.export("$summary", `Image edit task created successfully with ID: ${response.id}`);
96+
const response = await letzai.createImageEditTask({
97+
$,
98+
data: {
99+
...data,
100+
settings: settings && parseObject(settings),
101+
},
102+
});
103+
$.export("$summary", `Image edit task created successfully with request ID: ${response.id}`);
98104
return response;
99105
},
100106
};

components/letzai/actions/create-new-image/create-new-image.mjs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import letzai from "../../letzai.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "letzai-create-new-image",
65
name: "Create New Image",
7-
description: "Creates a new image generation task from a text prompt in LetzAI. [See the documentation](https://letz.ai/docs/api#createImages)",
8-
version: "0.0.{{ts}}",
6+
description: "Creates a new image generation task from a text prompt in LetzAI. [See the documentation](https://api.letz.ai/doc#/images/images_create)",
7+
version: "0.0.1",
98
type: "action",
109
props: {
1110
letzai,
11+
info: {
12+
type: "alert",
13+
alertType: "info",
14+
content: "**Note:** You can monitor the generation status using the Action \"Get Image Information\".",
15+
},
1216
prompt: {
1317
propDefinition: [
1418
letzai,
@@ -20,57 +24,61 @@ export default {
2024
letzai,
2125
"width",
2226
],
27+
optional: true,
2328
},
2429
height: {
2530
propDefinition: [
2631
letzai,
2732
"height",
2833
],
34+
optional: true,
2935
},
3036
quality: {
3137
propDefinition: [
3238
letzai,
3339
"quality",
3440
],
41+
optional: true,
3542
},
3643
creativity: {
3744
propDefinition: [
3845
letzai,
3946
"creativity",
4047
],
48+
optional: true,
4149
},
4250
hasWatermark: {
4351
propDefinition: [
4452
letzai,
4553
"hasWatermark",
4654
],
55+
optional: true,
4756
},
4857
systemVersion: {
4958
propDefinition: [
5059
letzai,
5160
"systemVersion",
5261
],
62+
optional: true,
5363
},
5464
mode: {
5565
propDefinition: [
5666
letzai,
5767
"generationMode",
5868
],
69+
optional: true,
5970
},
6071
},
6172
async run({ $ }) {
62-
const data = {
63-
prompt: this.prompt,
64-
width: this.width,
65-
height: this.height,
66-
quality: this.quality,
67-
creativity: this.creativity,
68-
hasWatermark: this.hasWatermark,
69-
systemVersion: this.systemVersion,
70-
mode: this.mode,
71-
};
73+
const {
74+
letzai,
75+
...data
76+
} = this;
7277

73-
const response = await this.letzai.createImageGenerationTask(data);
78+
const response = await letzai.createImage({
79+
$,
80+
data,
81+
});
7482
$.export("$summary", `Created image with ID: ${response.id}`);
7583
return response;
7684
},

components/letzai/actions/get-image-information/get-image-information.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import letzai from "../../letzai.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "letzai-get-image-information",
65
name: "Get Image Information",
7-
description: "Retrieves information about a specific image by ID. [See the documentation](https://api.letz.ai/docs/api)",
8-
version: "0.0.{{ts}}",
6+
description: "Retrieves information about a specific image by ID. [See the documentation](https://api.letz.ai/doc#/images/images_get)",
7+
version: "0.0.1",
98
type: "action",
109
props: {
1110
letzai,
@@ -17,7 +16,10 @@ export default {
1716
},
1817
},
1918
async run({ $ }) {
20-
const response = await this.letzai.retrieveImageInfo(this.imageId);
19+
const response = await this.letzai.retrieveImageInfo({
20+
$,
21+
imageId: this.imageId,
22+
});
2123
$.export("$summary", `Successfully retrieved information for image ID: ${this.imageId}`);
2224
return response;
2325
},
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export const LIMIT = 50;
2+
3+
export const GENERATION_MODE_OPTIONS = [
4+
{
5+
label: "Default",
6+
value: "default",
7+
},
8+
{
9+
label: "Sigma",
10+
value: "sigma",
11+
},
12+
];
13+
14+
export const SYSTEM_VERSION_OPTIONS = [
15+
{
16+
label: "Version 2",
17+
value: 2,
18+
},
19+
{
20+
label: "Version 3",
21+
value: 3,
22+
},
23+
];
24+
25+
export const MODE_OPTIONS = [
26+
{
27+
label: "Inpainting",
28+
value: "in",
29+
},
30+
{
31+
label: "Outpainting",
32+
value: "out",
33+
},
34+
];

components/letzai/common/utils.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

0 commit comments

Comments
 (0)