Skip to content

Commit bf69ca1

Browse files
committed
[Components] fal_ai - New action components
1 parent 515c48c commit bf69ca1

File tree

7 files changed

+291
-7
lines changed

7 files changed

+291
-7
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import app from "../../fal_ai.app.mjs";
2+
3+
export default {
4+
key: "fal_ai-add-request-to-queue",
5+
name: "Add Request to Queue",
6+
description: "Adds a request to the queue for asynchronous processing, including specifying a webhook URL for receiving updates.",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
appId: {
12+
propDefinition: [
13+
app,
14+
"appId",
15+
],
16+
},
17+
data: {
18+
type: "object",
19+
label: "Data",
20+
description: "Additional data to include with the request. [See the documentation](https://fal.ai/models/fal-ai/lora/api#schema-input) for more input fields.",
21+
default: {
22+
model_name: "stabilityai/stable-diffusion-xl-base-1.0",
23+
prompt: "Photo of a european medieval 40 year old queen, silver hair, highly detailed face, detailed eyes, head shot, intricate crown, age spots, wrinkles",
24+
},
25+
},
26+
falWebhook: {
27+
propDefinition: [
28+
app,
29+
"falWebhook",
30+
],
31+
},
32+
},
33+
methods: {
34+
addToQueue({
35+
appId, ...args
36+
} = {}) {
37+
return this.app.post({
38+
path: `/${appId}`,
39+
...args,
40+
});
41+
},
42+
},
43+
async run({ $ }) {
44+
const {
45+
addToQueue,
46+
appId,
47+
data,
48+
falWebhook,
49+
} = this;
50+
51+
const response = await addToQueue({
52+
$,
53+
appId,
54+
params: {
55+
fal_webhook: falWebhook,
56+
},
57+
data,
58+
});
59+
60+
$.export("$summary", `Successfully added request to the queue with ID \`${response.request_id}\`.`);
61+
return response;
62+
},
63+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import app from "../../fal_ai.app.mjs";
2+
3+
export default {
4+
key: "fal_ai-cancel-request",
5+
name: "Cancel Request",
6+
description: "Cancels a request in the queue. This allows you to stop a long-running task if it's no longer needed.",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
appId: {
12+
propDefinition: [
13+
app,
14+
"appId",
15+
],
16+
},
17+
requestId: {
18+
propDefinition: [
19+
app,
20+
"requestId",
21+
],
22+
},
23+
},
24+
methods: {
25+
cancelRequest({
26+
appId, requestId, ...args
27+
} = {}) {
28+
return this.app.put({
29+
path: `/${appId}/requests/${requestId}/cancel`,
30+
...args,
31+
});
32+
},
33+
},
34+
async run({ $ }) {
35+
const {
36+
cancelRequest,
37+
appId,
38+
requestId,
39+
} = this;
40+
41+
const response = await cancelRequest({
42+
$,
43+
appId,
44+
requestId,
45+
});
46+
47+
$.export("$summary", "Successfully canceled request.");
48+
return response;
49+
},
50+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import app from "../../fal_ai.app.mjs";
2+
3+
export default {
4+
key: "fal_ai-get-request-response",
5+
name: "Get Request Response",
6+
description: "Gets the response of a completed request in the queue. This retrieves the results of your asynchronous task.",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
appId: {
12+
propDefinition: [
13+
app,
14+
"appId",
15+
],
16+
},
17+
requestId: {
18+
propDefinition: [
19+
app,
20+
"requestId",
21+
],
22+
},
23+
},
24+
methods: {
25+
getRequestResponse({
26+
appId, requestId, ...args
27+
} = {}) {
28+
return this.app._makeRequest({
29+
path: `/${appId}/requests/${requestId}`,
30+
...args,
31+
});
32+
},
33+
},
34+
async run({ $ }) {
35+
const {
36+
getRequestResponse,
37+
appId,
38+
requestId,
39+
} = this;
40+
41+
const response = await getRequestResponse({
42+
$,
43+
appId,
44+
requestId,
45+
});
46+
47+
$.export("$summary", "Successfully retrieved the request response.");
48+
return response;
49+
},
50+
};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import app from "../../fal_ai.app.mjs";
2+
3+
export default {
4+
key: "fal_ai-get-request-status",
5+
name: "Get Request Status",
6+
description: "Gets the status of a request in the queue. This allows you to monitor the progress of your asynchronous tasks.",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
appId: {
12+
propDefinition: [
13+
app,
14+
"appId",
15+
],
16+
},
17+
requestId: {
18+
propDefinition: [
19+
app,
20+
"requestId",
21+
],
22+
},
23+
logs: {
24+
propDefinition: [
25+
app,
26+
"logs",
27+
],
28+
},
29+
},
30+
methods: {
31+
getRequestStatus({
32+
appId, requestId, ...args
33+
} = {}) {
34+
return this.app._makeRequest({
35+
path: `/${appId}/requests/${requestId}/status`,
36+
...args,
37+
});
38+
},
39+
},
40+
async run({ $ }) {
41+
const {
42+
getRequestStatus,
43+
appId,
44+
requestId,
45+
logs,
46+
} = this;
47+
48+
const response = await getRequestStatus({
49+
$,
50+
appId,
51+
requestId,
52+
params: {
53+
logs: logs
54+
? 1
55+
: undefined,
56+
},
57+
});
58+
59+
$.export("$summary", `Successfully retrieved status for request ID \`${response.request_id}\`.`);
60+
61+
return response;
62+
},
63+
};

components/fal_ai/fal_ai.app.mjs

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,63 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "fal_ai",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
appId: {
8+
type: "string",
9+
label: "App ID",
10+
description: "The unique identifier for the app. Eg. `lora`.",
11+
},
12+
falWebhook: {
13+
type: "string",
14+
label: "Webhook URL",
15+
description: "The URL to receive updates via webhook.",
16+
optional: true,
17+
},
18+
requestId: {
19+
type: "string",
20+
label: "Request ID",
21+
description: "The unique identifier for the request.",
22+
},
23+
logs: {
24+
type: "boolean",
25+
label: "Enable Logs",
26+
description: "Specify if logs should be enabled for the request status.",
27+
optional: true,
28+
},
29+
},
530
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
31+
getUrl(path) {
32+
return `https://queue.fal.run/fal-ai${path}`;
33+
},
34+
getHeaders(headers) {
35+
return {
36+
...headers,
37+
"Authorization": `Key ${this.$auth.api_key}`,
38+
"Content-Type": "application/json",
39+
};
40+
},
41+
_makeRequest({
42+
$ = this, path, headers, ...args
43+
} = {}) {
44+
return axios($, {
45+
...args,
46+
url: this.getUrl(path),
47+
headers: this.getHeaders(headers),
48+
});
49+
},
50+
post(args = {}) {
51+
return this._makeRequest({
52+
method: "POST",
53+
...args,
54+
});
55+
},
56+
put(args = {}) {
57+
return this._makeRequest({
58+
method: "PUT",
59+
...args,
60+
});
961
},
1062
},
1163
};

components/fal_ai/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/fal_ai",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream fal.ai Components",
55
"main": "fal_ai.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "3.0.3"
1417
}
15-
}
18+
}

pnpm-lock.yaml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)