Skip to content

Commit 8bbe2bd

Browse files
authored
Added actions (#14694)
1 parent 94a542c commit 8bbe2bd

File tree

7 files changed

+295
-58
lines changed

7 files changed

+295
-58
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import app from "../../microsoft_azure_ai_translator.app.mjs";
2+
3+
export default {
4+
key: "microsoft_azure_ai_translator-break-sentence",
5+
name: "Break Sentence",
6+
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)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
text: {
12+
propDefinition: [
13+
app,
14+
"text",
15+
],
16+
},
17+
},
18+
19+
async run({ $ }) {
20+
const response = await this.app.breakSentence({
21+
$,
22+
data: [
23+
{
24+
text: this.text,
25+
},
26+
],
27+
});
28+
$.export("$summary", "Successfully identified the number and length of the provided sentences ");
29+
return response;
30+
},
31+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import app from "../../microsoft_azure_ai_translator.app.mjs";
2+
3+
export default {
4+
key: "microsoft_azure_ai_translator-detect-language",
5+
name: "Detect Language",
6+
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)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
text: {
12+
propDefinition: [
13+
app,
14+
"text",
15+
],
16+
},
17+
},
18+
19+
async run({ $ }) {
20+
const response = await this.app.detectLanguage({
21+
$,
22+
data: [
23+
{
24+
text: this.text,
25+
},
26+
],
27+
});
28+
$.export("$summary", `Successfully detected language of the provided text: '${response.language}'s`);
29+
return response;
30+
},
31+
};
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import app from "../../microsoft_azure_ai_translator.app.mjs";
2+
3+
export default {
4+
key: "microsoft_azure_ai_translator-translate-text",
5+
name: "Translate Text",
6+
description: "Translate text into the specified language. [See the documentation](https://learn.microsoft.com/en-us/azure/ai-services/translator/reference/v3-0-translate)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
text: {
12+
propDefinition: [
13+
app,
14+
"text",
15+
],
16+
},
17+
to: {
18+
propDefinition: [
19+
app,
20+
"to",
21+
],
22+
},
23+
from: {
24+
propDefinition: [
25+
app,
26+
"from",
27+
],
28+
},
29+
profanityAction: {
30+
propDefinition: [
31+
app,
32+
"profanityAction",
33+
],
34+
},
35+
includeAlignment: {
36+
propDefinition: [
37+
app,
38+
"includeAlignment",
39+
],
40+
},
41+
},
42+
43+
async run({ $ }) {
44+
const response = await this.app.translateText({
45+
$,
46+
data: [
47+
{
48+
text: this.text,
49+
},
50+
],
51+
params: {
52+
from: this.from,
53+
to: this.to,
54+
profanityAction: this.profanityAction,
55+
includeAlignment: this.includeAlignment,
56+
},
57+
});
58+
$.export("$summary", "Successfully translated the provided text");
59+
return response;
60+
},
61+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default {
2+
PROFANITY_ACTIONS: [
3+
"NoAction",
4+
"Marked",
5+
"Deleted",
6+
],
7+
};
Lines changed: 105 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,112 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "microsoft_azure_ai_translator",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
text: {
9+
type: "string",
10+
label: "Text",
11+
description: "String that will be sent to the API",
12+
},
13+
to: {
14+
type: "string",
15+
label: "Output Language",
16+
description: "Language of the output text",
17+
async options() {
18+
const response = await this.getLanguages();
19+
return Object.entries(response.translation).map(([
20+
key,
21+
{ name },
22+
]) => ({
23+
label: name,
24+
value: key,
25+
}));
26+
},
27+
},
28+
from: {
29+
type: "string",
30+
label: "Input Language",
31+
description: "Language of the input text",
32+
optional: true,
33+
async options() {
34+
const response = await this.getLanguages();
35+
return Object.entries(response.translation).map(([
36+
key,
37+
{ name },
38+
]) => ({
39+
label: name,
40+
value: key,
41+
}));
42+
},
43+
},
44+
profanityAction: {
45+
type: "string",
46+
label: "Profanity Action",
47+
description: "Specifies how profanities should be treated",
48+
options: constants.PROFANITY_ACTIONS,
49+
},
50+
includeAlignment: {
51+
type: "boolean",
52+
label: "Include Alignment",
53+
description: "Specifies whether to include alignment projection from source text to translated text",
54+
optional: true,
55+
},
56+
},
557
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
58+
_baseUrl() {
59+
return `${this.$auth.endpoint}`;
60+
},
61+
async _makeRequest(opts = {}) {
62+
const {
63+
$ = this,
64+
path,
65+
headers,
66+
params,
67+
...otherOpts
68+
} = opts;
69+
return axios($, {
70+
...otherOpts,
71+
url: this._baseUrl() + path,
72+
headers: {
73+
...headers,
74+
"Ocp-Apim-Subscription-Key": `${this.$auth.api_key}`,
75+
"Ocp-Apim-Subscription-Region": `${this.$auth.location}`,
76+
"Content-Type": "application/json",
77+
},
78+
params: {
79+
...params,
80+
"api-version": "3.0",
81+
},
82+
});
83+
},
84+
async translateText(args = {}) {
85+
return this._makeRequest({
86+
path: "/translate",
87+
method: "post",
88+
...args,
89+
});
90+
},
91+
async breakSentence(args = {}) {
92+
return this._makeRequest({
93+
path: "/breaksentence",
94+
method: "post",
95+
...args,
96+
});
97+
},
98+
async detectLanguage(args = {}) {
99+
return this._makeRequest({
100+
path: "/detect",
101+
method: "post",
102+
...args,
103+
});
104+
},
105+
async getLanguages(args = {}) {
106+
return this._makeRequest({
107+
path: "/languages",
108+
...args,
109+
});
9110
},
10111
},
11112
};

components/microsoft_azure_ai_translator/package.json

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

0 commit comments

Comments
 (0)