- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
[Components] fal_ai - New action components #14545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            124 changes: 124 additions & 0 deletions
          
          124 
        
  components/fal_ai/actions/add-request-to-queue/add-request-to-queue.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | 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, | ||
| }); | ||
|         
                  jcortes marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| $.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, | ||
| }); | ||
|         
                  jcortes marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| $.export("$summary", "Successfully retrieved the request response."); | ||
| return response; | ||
| }, | ||
| }; | ||
        
          
          
            50 changes: 50 additions & 0 deletions
          
          50 
        
  components/fal_ai/actions/cancel-request/cancel-request.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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, | ||
| }); | ||
| }, | ||
| }, | ||
|         
                  jcortes marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| async run({ $ }) { | ||
| const { | ||
| cancelRequest, | ||
| appId, | ||
| requestId, | ||
| } = this; | ||
|  | ||
| const response = await cancelRequest({ | ||
| $, | ||
| appId, | ||
| requestId, | ||
| }); | ||
|  | ||
| $.export("$summary", "Successfully canceled request."); | ||
| return response; | ||
| }, | ||
| }; | ||
|         
                  jcortes marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
        
          
          
            40 changes: 40 additions & 0 deletions
          
          40 
        
  components/fal_ai/actions/get-request-response/get-request-response.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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", | ||
| ], | ||
| }, | ||
| }, | ||
|         
                  jcortes marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| async run({ $ }) { | ||
| const { | ||
| app, | ||
| appId, | ||
| requestId, | ||
| } = this; | ||
|  | ||
| const response = await app.getRequestResponse({ | ||
| $, | ||
| appId, | ||
| requestId, | ||
| }); | ||
|  | ||
| $.export("$summary", "Successfully retrieved the request response."); | ||
| return response; | ||
| }, | ||
| }; | ||
        
          
          
            53 changes: 53 additions & 0 deletions
          
          53 
        
  components/fal_ai/actions/get-request-status/get-request-status.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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; | ||
| }, | ||
| }; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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), | ||
| }); | ||
| }, | ||
|         
                  jcortes marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| post(args = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| ...args, | ||
| }); | ||
| }, | ||
| put(args = {}) { | ||
| return this._makeRequest({ | ||
| method: "PUT", | ||
| ...args, | ||
| }); | ||
|         
                  jcortes marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| }, | ||
| 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, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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": [ | ||
|  | @@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "3.0.3" | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
      
      Oops, something went wrong.
      
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.