From 595f344783e19734584ab7a1ed32d5ffbe745276 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Wed, 20 Nov 2024 15:33:29 -0300 Subject: [PATCH] Added actions --- .../actions/break-sentence/break-sentence.mjs | 31 +++++ .../detect-language/detect-language.mjs | 31 +++++ .../actions/translate-text/translate-text.mjs | 61 ++++++++++ .../common/constants.mjs | 7 ++ .../microsoft_azure_ai_translator.app.mjs | 109 +++++++++++++++++- .../package.json | 7 +- pnpm-lock.yaml | 107 ++++++++--------- 7 files changed, 295 insertions(+), 58 deletions(-) create mode 100644 components/microsoft_azure_ai_translator/actions/break-sentence/break-sentence.mjs create mode 100644 components/microsoft_azure_ai_translator/actions/detect-language/detect-language.mjs create mode 100644 components/microsoft_azure_ai_translator/actions/translate-text/translate-text.mjs create mode 100644 components/microsoft_azure_ai_translator/common/constants.mjs diff --git a/components/microsoft_azure_ai_translator/actions/break-sentence/break-sentence.mjs b/components/microsoft_azure_ai_translator/actions/break-sentence/break-sentence.mjs new file mode 100644 index 0000000000000..e46abc8a76081 --- /dev/null +++ b/components/microsoft_azure_ai_translator/actions/break-sentence/break-sentence.mjs @@ -0,0 +1,31 @@ +import app from "../../microsoft_azure_ai_translator.app.mjs"; + +export default { + key: "microsoft_azure_ai_translator-break-sentence", + name: "Break Sentence", + description: "Identifies the positioning of sentence boundaries in a piece of text. [See the documentation](https://learn.microsoft.com/en-us/azure/ai-services/translator/reference/v3-0-break-sentence)", + version: "0.0.1", + type: "action", + props: { + app, + text: { + propDefinition: [ + app, + "text", + ], + }, + }, + + async run({ $ }) { + const response = await this.app.breakSentence({ + $, + data: [ + { + text: this.text, + }, + ], + }); + $.export("$summary", "Successfully identified the number and length of the provided sentences "); + return response; + }, +}; diff --git a/components/microsoft_azure_ai_translator/actions/detect-language/detect-language.mjs b/components/microsoft_azure_ai_translator/actions/detect-language/detect-language.mjs new file mode 100644 index 0000000000000..6a1b9c478b656 --- /dev/null +++ b/components/microsoft_azure_ai_translator/actions/detect-language/detect-language.mjs @@ -0,0 +1,31 @@ +import app from "../../microsoft_azure_ai_translator.app.mjs"; + +export default { + key: "microsoft_azure_ai_translator-detect-language", + name: "Detect Language", + description: "Identifies the language of a piece of text. [See the documentation](https://learn.microsoft.com/en-us/azure/ai-services/translator/reference/v3-0-detect)", + version: "0.0.1", + type: "action", + props: { + app, + text: { + propDefinition: [ + app, + "text", + ], + }, + }, + + async run({ $ }) { + const response = await this.app.detectLanguage({ + $, + data: [ + { + text: this.text, + }, + ], + }); + $.export("$summary", `Successfully detected language of the provided text: '${response.language}'s`); + return response; + }, +}; diff --git a/components/microsoft_azure_ai_translator/actions/translate-text/translate-text.mjs b/components/microsoft_azure_ai_translator/actions/translate-text/translate-text.mjs new file mode 100644 index 0000000000000..80c3710f79d6c --- /dev/null +++ b/components/microsoft_azure_ai_translator/actions/translate-text/translate-text.mjs @@ -0,0 +1,61 @@ +import app from "../../microsoft_azure_ai_translator.app.mjs"; + +export default { + key: "microsoft_azure_ai_translator-translate-text", + name: "Translate Text", + description: "Translate text into the specified language. [See the documentation](https://learn.microsoft.com/en-us/azure/ai-services/translator/reference/v3-0-translate)", + version: "0.0.1", + type: "action", + props: { + app, + text: { + propDefinition: [ + app, + "text", + ], + }, + to: { + propDefinition: [ + app, + "to", + ], + }, + from: { + propDefinition: [ + app, + "from", + ], + }, + profanityAction: { + propDefinition: [ + app, + "profanityAction", + ], + }, + includeAlignment: { + propDefinition: [ + app, + "includeAlignment", + ], + }, + }, + + async run({ $ }) { + const response = await this.app.translateText({ + $, + data: [ + { + text: this.text, + }, + ], + params: { + from: this.from, + to: this.to, + profanityAction: this.profanityAction, + includeAlignment: this.includeAlignment, + }, + }); + $.export("$summary", "Successfully translated the provided text"); + return response; + }, +}; diff --git a/components/microsoft_azure_ai_translator/common/constants.mjs b/components/microsoft_azure_ai_translator/common/constants.mjs new file mode 100644 index 0000000000000..0a74997f28a9b --- /dev/null +++ b/components/microsoft_azure_ai_translator/common/constants.mjs @@ -0,0 +1,7 @@ +export default { + PROFANITY_ACTIONS: [ + "NoAction", + "Marked", + "Deleted", + ], +}; diff --git a/components/microsoft_azure_ai_translator/microsoft_azure_ai_translator.app.mjs b/components/microsoft_azure_ai_translator/microsoft_azure_ai_translator.app.mjs index c0c4cf190a5a0..c118a2529da70 100644 --- a/components/microsoft_azure_ai_translator/microsoft_azure_ai_translator.app.mjs +++ b/components/microsoft_azure_ai_translator/microsoft_azure_ai_translator.app.mjs @@ -1,11 +1,112 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + export default { type: "app", app: "microsoft_azure_ai_translator", - propDefinitions: {}, + propDefinitions: { + text: { + type: "string", + label: "Text", + description: "String that will be sent to the API", + }, + to: { + type: "string", + label: "Output Language", + description: "Language of the output text", + async options() { + const response = await this.getLanguages(); + return Object.entries(response.translation).map(([ + key, + { name }, + ]) => ({ + label: name, + value: key, + })); + }, + }, + from: { + type: "string", + label: "Input Language", + description: "Language of the input text", + optional: true, + async options() { + const response = await this.getLanguages(); + return Object.entries(response.translation).map(([ + key, + { name }, + ]) => ({ + label: name, + value: key, + })); + }, + }, + profanityAction: { + type: "string", + label: "Profanity Action", + description: "Specifies how profanities should be treated", + options: constants.PROFANITY_ACTIONS, + }, + includeAlignment: { + type: "boolean", + label: "Include Alignment", + description: "Specifies whether to include alignment projection from source text to translated text", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return `${this.$auth.endpoint}`; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + params, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + "Ocp-Apim-Subscription-Key": `${this.$auth.api_key}`, + "Ocp-Apim-Subscription-Region": `${this.$auth.location}`, + "Content-Type": "application/json", + }, + params: { + ...params, + "api-version": "3.0", + }, + }); + }, + async translateText(args = {}) { + return this._makeRequest({ + path: "/translate", + method: "post", + ...args, + }); + }, + async breakSentence(args = {}) { + return this._makeRequest({ + path: "/breaksentence", + method: "post", + ...args, + }); + }, + async detectLanguage(args = {}) { + return this._makeRequest({ + path: "/detect", + method: "post", + ...args, + }); + }, + async getLanguages(args = {}) { + return this._makeRequest({ + path: "/languages", + ...args, + }); }, }, }; diff --git a/components/microsoft_azure_ai_translator/package.json b/components/microsoft_azure_ai_translator/package.json index 2c61ece4ea585..f0f23b7864329 100644 --- a/components/microsoft_azure_ai_translator/package.json +++ b/components/microsoft_azure_ai_translator/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/microsoft_azure_ai_translator", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Microsoft Azure AI Translator Components", "main": "microsoft_azure_ai_translator.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 62601dada8f5d..a87de68677dc1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6289,7 +6289,10 @@ importers: specifiers: {} components/microsoft_azure_ai_translator: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/microsoft_entra_id: specifiers: @@ -13450,6 +13453,55 @@ packages: - aws-crt dev: false + /@aws-sdk/client-sso-oidc/3.600.0_tdq3komn4zwyd65w7klbptsu34: + resolution: {integrity: sha512-7+I8RWURGfzvChyNQSyj5/tKrqRbzRl7H+BnTOf/4Vsw1nFOi5ROhlhD4X/Y0QCTacxnaoNcIrqnY7uGGvVRzw==} + engines: {node: '>=16.0.0'} + dependencies: + '@aws-crypto/sha256-browser': 5.2.0 + '@aws-crypto/sha256-js': 5.2.0 + '@aws-sdk/client-sts': 3.600.0 + '@aws-sdk/core': 3.598.0 + '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 + '@aws-sdk/middleware-host-header': 3.598.0 + '@aws-sdk/middleware-logger': 3.598.0 + '@aws-sdk/middleware-recursion-detection': 3.598.0 + '@aws-sdk/middleware-user-agent': 3.598.0 + '@aws-sdk/region-config-resolver': 3.598.0 + '@aws-sdk/types': 3.598.0 + '@aws-sdk/util-endpoints': 3.598.0 + '@aws-sdk/util-user-agent-browser': 3.598.0 + '@aws-sdk/util-user-agent-node': 3.598.0 + '@smithy/config-resolver': 3.0.3 + '@smithy/core': 2.2.3 + '@smithy/fetch-http-handler': 3.2.1 + '@smithy/hash-node': 3.0.2 + '@smithy/invalid-dependency': 3.0.2 + '@smithy/middleware-content-length': 3.0.2 + '@smithy/middleware-endpoint': 3.0.4 + '@smithy/middleware-retry': 3.0.6 + '@smithy/middleware-serde': 3.0.3 + '@smithy/middleware-stack': 3.0.3 + '@smithy/node-config-provider': 3.1.3 + '@smithy/node-http-handler': 3.1.2 + '@smithy/protocol-http': 4.0.3 + '@smithy/smithy-client': 3.1.6 + '@smithy/types': 3.3.0 + '@smithy/url-parser': 3.0.3 + '@smithy/util-base64': 3.0.0 + '@smithy/util-body-length-browser': 3.0.0 + '@smithy/util-body-length-node': 3.0.0 + '@smithy/util-defaults-mode-browser': 3.0.6 + '@smithy/util-defaults-mode-node': 3.0.6 + '@smithy/util-endpoints': 2.0.3 + '@smithy/util-middleware': 3.0.3 + '@smithy/util-retry': 3.0.2 + '@smithy/util-utf8': 3.0.0 + tslib: 2.6.3 + transitivePeerDependencies: + - '@aws-sdk/client-sts' + - aws-crt + dev: false + /@aws-sdk/client-sso/3.423.0: resolution: {integrity: sha512-znIufHkwhCIePgaYciIs3x/+BpzR57CZzbCKHR9+oOvGyufEPPpUT5bFLvbwTgfiVkTjuk6sG/ES3U5Bc+xtrA==} engines: {node: '>=14.0.0'} @@ -13685,7 +13737,7 @@ packages: dependencies: '@aws-crypto/sha256-browser': 5.2.0 '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0 + '@aws-sdk/client-sso-oidc': 3.600.0_tdq3komn4zwyd65w7klbptsu34 '@aws-sdk/core': 3.598.0 '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 '@aws-sdk/middleware-host-header': 3.598.0 @@ -13727,55 +13779,6 @@ packages: - aws-crt dev: false - /@aws-sdk/client-sts/3.600.0_dseaa2p5u2yk67qiepewcq3hkq: - resolution: {integrity: sha512-KQG97B7LvTtTiGmjlrG1LRAY8wUvCQzrmZVV5bjrJ/1oXAU7DITYwVbSJeX9NWg6hDuSk0VE3MFwIXS2SvfLIA==} - engines: {node: '>=16.0.0'} - dependencies: - '@aws-crypto/sha256-browser': 5.2.0 - '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0 - '@aws-sdk/core': 3.598.0 - '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 - '@aws-sdk/middleware-host-header': 3.598.0 - '@aws-sdk/middleware-logger': 3.598.0 - '@aws-sdk/middleware-recursion-detection': 3.598.0 - '@aws-sdk/middleware-user-agent': 3.598.0 - '@aws-sdk/region-config-resolver': 3.598.0 - '@aws-sdk/types': 3.598.0 - '@aws-sdk/util-endpoints': 3.598.0 - '@aws-sdk/util-user-agent-browser': 3.598.0 - '@aws-sdk/util-user-agent-node': 3.598.0 - '@smithy/config-resolver': 3.0.3 - '@smithy/core': 2.2.3 - '@smithy/fetch-http-handler': 3.2.1 - '@smithy/hash-node': 3.0.2 - '@smithy/invalid-dependency': 3.0.2 - '@smithy/middleware-content-length': 3.0.2 - '@smithy/middleware-endpoint': 3.0.4 - '@smithy/middleware-retry': 3.0.6 - '@smithy/middleware-serde': 3.0.3 - '@smithy/middleware-stack': 3.0.3 - '@smithy/node-config-provider': 3.1.3 - '@smithy/node-http-handler': 3.1.2 - '@smithy/protocol-http': 4.0.3 - '@smithy/smithy-client': 3.1.6 - '@smithy/types': 3.3.0 - '@smithy/url-parser': 3.0.3 - '@smithy/util-base64': 3.0.0 - '@smithy/util-body-length-browser': 3.0.0 - '@smithy/util-body-length-node': 3.0.0 - '@smithy/util-defaults-mode-browser': 3.0.6 - '@smithy/util-defaults-mode-node': 3.0.6 - '@smithy/util-endpoints': 2.0.3 - '@smithy/util-middleware': 3.0.3 - '@smithy/util-retry': 3.0.2 - '@smithy/util-utf8': 3.0.0 - tslib: 2.6.3 - transitivePeerDependencies: - - '@aws-sdk/client-sso-oidc' - - aws-crt - dev: false - /@aws-sdk/core/3.556.0: resolution: {integrity: sha512-vJaSaHw2kPQlo11j/Rzuz0gk1tEaKdz+2ser0f0qZ5vwFlANjt08m/frU17ctnVKC1s58bxpctO/1P894fHLrA==} engines: {node: '>=14.0.0'} @@ -18158,7 +18161,7 @@ packages: '@aws-sdk/client-sns': 3.423.0 '@aws-sdk/client-sqs': 3.423.0 '@aws-sdk/client-ssm': 3.423.0 - '@aws-sdk/client-sts': 3.600.0_dseaa2p5u2yk67qiepewcq3hkq + '@aws-sdk/client-sts': 3.600.0 '@aws-sdk/s3-request-presigner': 3.609.0 '@pipedream/helper_functions': 0.3.12 '@pipedream/platform': 1.6.6