Skip to content

Commit

Permalink
#7832 - Eden AI new components (#7965)
Browse files Browse the repository at this point in the history
* package and pnpm lock

* pnpm lock

* AI-generated app file

* App file adjustments

* AI generated action #1

* Improvements on AI output

* pnpm

* Adding and updating props

* Adjustments to document translation action

* Prop definitions and adding optional props

* Detect AI Content + improvements

* Analyze sentiment in text + more propDefinitions

* Generate Image (AI)

* pnpm

* Description adjustments

* Generate Image finalizing

* Prop adjustments

* typos
  • Loading branch information
GTFalcao committed Sep 11, 2023
1 parent e2c90b4 commit 6b58e13
Show file tree
Hide file tree
Showing 9 changed files with 420 additions and 20 deletions.
3 changes: 0 additions & 3 deletions components/eden_ai/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import app from "../../eden_ai.app.mjs";

export default {
key: "eden_ai-analyze-sentiment-in-text",
name: "Analyze Sentiment in Text",
description: "Analyzes sentiment in the provided text. [See the documentation](https://docs.edenai.co/reference/text_sentiment_analysis_create)",
version: "0.0.1",
type: "action",
props: {
app,
text: {
propDefinition: [
app,
"text",
],
},
providers: {
propDefinition: [
app,
"providers",
],
},
fallbackProviders: {
propDefinition: [
app,
"fallbackProviders",
],
},
showOriginalResponse: {
propDefinition: [
app,
"showOriginalResponse",
],
},
language: {
propDefinition: [
app,
"language",
],
optional: true,
},
},
async run({ $ }) {
const {
text,
providers,
fallbackProviders,
showOriginalResponse,
language,
} = this;

const params = {
$,
data: {
text,
providers: providers.join(),
fallback_providers: fallbackProviders?.join(),
show_original_response: showOriginalResponse,
language,
},
};

const response = await this.app.analyzeSentimentInText(params);
$.export("$summary", "Sentiment analysis successfully performed");
return response;
},
};
68 changes: 68 additions & 0 deletions components/eden_ai/actions/detect-ai-content/detect-ai-content.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import app from "../../eden_ai.app.mjs";

export default {
key: "eden_ai-detect-ai-content",
name: "Detect AI Content",
description:
"Detects AI content in the provided text. [See the documentation](https://docs.edenai.co/reference/text_ai_detection_create)",
version: "0.0.1",
type: "action",
props: {
app,
text: {
propDefinition: [
app,
"text",
],
},
providers: {
propDefinition: [
app,
"providers",
],
},
fallbackProviders: {
propDefinition: [
app,
"fallbackProviders",
],
},
showOriginalResponse: {
propDefinition: [
app,
"showOriginalResponse",
],
},
language: {
propDefinition: [
app,
"language",
],
optional: true,
},
},
async run({ $ }) {
const {
text,
providers,
fallbackProviders,
showOriginalResponse,
language,
} = this;

const params = {
$,
data: {
text,
providers: providers.join(),
fallback_providers: fallbackProviders?.join(),
show_original_response: showOriginalResponse,
language,
},
};

const response = await this.app.detectAIContent(params);
$.export("$summary", "AI content detection completed successfully");
return response;
},
};
82 changes: 82 additions & 0 deletions components/eden_ai/actions/generate-image/generate-image.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import app from "../../eden_ai.app.mjs";

export default {
key: "eden_ai-generate-image",
name: "Generate Image",
description: "Generates an image from the provided description. [See the documentation](https://docs.edenai.co/reference/image_generation_create)",
version: "0.0.1",
type: "action",
props: {
app,
text: {
propDefinition: [
app,
"text",
],
description: "Description of the desired image(s) - the maximum length is 1000 characters.",
},
resolution: {
type: "string",
label: "Resolution",
description: "Resolution of the image.",
options: [
"256x256",
"512x512",
"1024x1024",
],
},
numImages: {
type: "integer",
label: "Number of images",
description: "The number of images to generate.",
optional: true,
default: 1,
min: 1,
max: 10,
},
providers: {
propDefinition: [
app,
"providers",
],
},
fallbackProviders: {
propDefinition: [
app,
"fallbackProviders",
],
},
showOriginalResponse: {
propDefinition: [
app,
"showOriginalResponse",
],
},
},
async run({ $ }) {
const {
text,
resolution,
numImages,
providers,
fallbackProviders,
showOriginalResponse,
} = this;

const params = {
$,
data: {
text,
resolution,
number_of_images: numImages,
providers: providers.join(),
fallback_providers: fallbackProviders?.join(),
show_original_response: showOriginalResponse,
},
};

const response = await this.app.generateImage(params);
$.export("$summary", "Image generated successfully");
return response;
},
};
108 changes: 108 additions & 0 deletions components/eden_ai/actions/translate-document/translate-document.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import app from "../../eden_ai.app.mjs";
import { ConfigurationError } from "@pipedream/platform";
import FormData from "form-data";
import fs from "fs";

export default {
key: "eden_ai-translate-document",
name: "Translate Document",
description: "Translates a document from a local file or URL. [See the documentation](https://docs.edenai.co/reference/translation_document_translation_create)",
version: "0.0.1",
type: "action",
props: {
app,
providers: {
propDefinition: [
app,
"providers",
],
},
fallbackProviders: {
propDefinition: [
app,
"fallbackProviders",
],
},
showOriginalResponse: {
propDefinition: [
app,
"showOriginalResponse",
],
},
sourceLanguage: {
propDefinition: [
app,
"language",
],
label: "Source Language",
optional: true,
},
targetLanguage: {
propDefinition: [
app,
"language",
],
label: "Target Language",
},
file: {
type: "string",
label: "File Path",
description: "The path to a file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp).",
optional: true,
},
fileUrl: {
type: "string",
label: "File URL",
description: "The URL of the file to translate",
optional: true,
},
},
async run({ $ }) {
const {
providers, fallbackProviders, showOriginalResponse, sourceLanguage, targetLanguage, file, fileUrl, // eslint-disable-line max-len
} = this;

let headers, data = {
providers: providers.join(),
fallback_providers: fallbackProviders.join(),
show_original_response: showOriginalResponse,
source_language: sourceLanguage,
target_language: targetLanguage,
};

if (file) {
const formData = new FormData();
Object.entries(data).forEach(([
key,
value,
]) => {
if (value !== undefined) {
formData.append(key, value);
}
});

formData.append("file", fs.createReadStream(file.startsWith("/tmp/")
? file
: `/tmp/${file}`));
headers = {
"Content-Type": `multipart/form-data; boundary=${formData._boundary}`,
};
data = formData;
} else if (fileUrl) {
data.file_url = fileUrl;
headers = {
"Content-Type": "application/json",
};
} else {
throw new ConfigurationError("You must provide either a file or a file URL");
}

const response = await this.app.translateText({
$,
data,
headers,
});
$.export("$summary", "Document translated successfully");
return response;
},
};
13 changes: 0 additions & 13 deletions components/eden_ai/app/eden_ai.app.ts

This file was deleted.

Loading

1 comment on commit 6b58e13

@vercel
Copy link

@vercel vercel bot commented on 6b58e13 Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.