Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import app from "../../fal_ai.app.mjs";

export default {
key: "fal_ai-add-request-to-queue",
name: "Add Request to Queue",
description: "Adds a request to the queue for asynchronous processing, including specifying a webhook URL for receiving updates. [See the documentation](https://fal.ai/docs/model-endpoints/queue#queue-endpoints).",
version: "0.0.1",
type: "action",
props: {
app,
appId: {
propDefinition: [
app,
"appId",
],
},
data: {
type: "object",
label: "Data",
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.",
default: {
model_name: "stabilityai/stable-diffusion-xl-base-1.0",
prompt: "Photo of a european medieval 40 year old queen, silver hair, highly detailed face, detailed eyes, head shot, intricate crown, age spots, wrinkles",
},
},
reRunEnabled: {
type: "boolean",
label: "Rerun Enabled",
description: "Enable the step to rerun to retrieve the request response. [See the documentation](https://pipedream.com/docs/code/nodejs/rerun/#flowrerun).",
optional: true,
reloadProps: true,
default: false,
},
},
additionalProps() {
if (this.reRunEnabled) {
return {
reRunTimeoutInSecs: {
type: "integer",
label: "Rerun Timeout",
description: "The time in seconds to wait before rerunning the step to retrieve the request response. Eg. `30`. [See the documentation](https://pipedream.com/docs/code/nodejs/rerun/#flowrerun).",
optional: true,
min: 10,
},
};
}

return {
falWebhook: {
type: "string",
label: "Webhook URL",
description: "The URL to receive updates via webhook.",
optional: true,
},
};
},
methods: {
addToQueue({
appId, ...args
} = {}) {
return this.app.post({
path: `/${appId}`,
...args,
});
},
},
async run({ $ }) {
const {
context: {
run: {
runs,
callback_request: callbackRequest,
},
},
} = $;

const {
app,
addToQueue,
appId,
data,
falWebhook,
reRunEnabled,
reRunTimeoutInSecs,
} = this;

if (!reRunEnabled) {
const response = await addToQueue({
$,
appId,
params: {
fal_webhook: falWebhook,
},
data,
});

$.export("$summary", `Successfully added the request to the queue with ID \`${response.request_id}\`.`);
return response;
}

if (runs === 1) {
const timeout = 1000 * (reRunTimeoutInSecs || 10);
const { resume_url: resumeUrl } = $.flow.rerun(timeout, null, 1);

return addToQueue({
$,
appId,
params: {
fal_webhook: resumeUrl,
},
data,
});
}

const response = await app.getRequestResponse({
$,
appId,
requestId: callbackRequest.body?.request_id,
});

$.export("$summary", "Successfully retrieved the request response.");
return response;
},
};
50 changes: 50 additions & 0 deletions components/fal_ai/actions/cancel-request/cancel-request.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import app from "../../fal_ai.app.mjs";

export default {
key: "fal_ai-cancel-request",
name: "Cancel Request",
description: "Cancels a request in the queue. This allows you to stop a long-running task if it's no longer needed. [See the documentation](https://fal.ai/docs/model-endpoints/queue#queue-endpoints).",
version: "0.0.1",
type: "action",
props: {
app,
appId: {
propDefinition: [
app,
"appId",
],
},
requestId: {
propDefinition: [
app,
"requestId",
],
},
},
methods: {
cancelRequest({
appId, requestId, ...args
} = {}) {
return this.app.put({
path: `/${appId}/requests/${requestId}/cancel`,
...args,
});
},
},
async run({ $ }) {
const {
cancelRequest,
appId,
requestId,
} = this;

const response = await cancelRequest({
$,
appId,
requestId,
});

$.export("$summary", "Successfully canceled request.");
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import app from "../../fal_ai.app.mjs";

export default {
key: "fal_ai-get-request-response",
name: "Get Request Response",
description: "Gets the response of a completed request in the queue. This retrieves the results of your asynchronous task. [See the documentation](https://fal.ai/docs/model-endpoints/queue#queue-endpoints).",
version: "0.0.1",
type: "action",
props: {
app,
appId: {
propDefinition: [
app,
"appId",
],
},
requestId: {
propDefinition: [
app,
"requestId",
],
},
},
async run({ $ }) {
const {
app,
appId,
requestId,
} = this;

const response = await app.getRequestResponse({
$,
appId,
requestId,
});

$.export("$summary", "Successfully retrieved the request response.");
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import app from "../../fal_ai.app.mjs";

export default {
key: "fal_ai-get-request-status",
name: "Get Request Status",
description: "Gets the status of a request in the queue. This allows you to monitor the progress of your asynchronous tasks. [See the documentation](https://fal.ai/docs/model-endpoints/queue#queue-endpoints).",
version: "0.0.1",
type: "action",
props: {
app,
appId: {
propDefinition: [
app,
"appId",
],
},
requestId: {
propDefinition: [
app,
"requestId",
],
},
logs: {
propDefinition: [
app,
"logs",
],
},
},
async run({ $ }) {
const {
app,
appId,
requestId,
logs,
} = this;

const response = await app.getRequestStatus({
$,
appId,
requestId,
params: {
logs: logs
? 1
: undefined,
},
});

$.export("$summary", `Successfully retrieved status as \`${response.status}\`.`);

return response;
},
};
70 changes: 66 additions & 4 deletions components/fal_ai/fal_ai.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,73 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "fal_ai",
propDefinitions: {},
propDefinitions: {
appId: {
type: "string",
label: "App ID",
description: "The unique identifier for the app. Eg. `lora`.",
},
requestId: {
type: "string",
label: "Request ID",
description: "The unique identifier for the request.",
},
logs: {
type: "boolean",
label: "Enable Logs",
description: "Specify if logs should be enabled for the request status.",
optional: true,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
getUrl(path) {
return `https://queue.fal.run/fal-ai${path}`;
},
getHeaders(headers) {
return {
...headers,
"Authorization": `Key ${this.$auth.api_key}`,
"Content-Type": "application/json",
};
},
_makeRequest({
$ = this, path, headers, ...args
} = {}) {
return axios($, {
...args,
url: this.getUrl(path),
headers: this.getHeaders(headers),
});
},
post(args = {}) {
return this._makeRequest({
method: "POST",
...args,
});
},
put(args = {}) {
return this._makeRequest({
method: "PUT",
...args,
});
},
getRequestStatus({
appId, requestId, ...args
} = {}) {
return this._makeRequest({
path: `/${appId}/requests/${requestId}/status`,
...args,
});
},
getRequestResponse({
appId, requestId, ...args
} = {}) {
return this._makeRequest({
path: `/${appId}/requests/${requestId}`,
...args,
});
},
},
};
7 changes: 5 additions & 2 deletions components/fal_ai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/fal_ai",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream fal.ai Components",
"main": "fal_ai.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "3.0.3"
}
}
}
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading