- 
                Notifications
    
You must be signed in to change notification settings  - Fork 5.5k
 
[Components] microsoft_azure_ai_translator #14490 #14694
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -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; | ||
| }, | ||
                
      
                  jcortes marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -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; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
         
      Comment on lines
    
      +19
     to 
      +30
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Add error handling and fix summary message. The run method has several issues that need to be addressed: 
 Apply these improvements:    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;
+    try {
+      const response = await this.app.detectLanguage({
+        $,
+        data: [
+          {
+            text: this.text,
+          },
+        ],
+      });
+      
+      if (!response?.language) {
+        throw new Error("Invalid response: Missing language detection result");
+      }
+      
+      $.export("$summary", `Successfully detected language of the provided text: '${response.language}'`);
+      return response;
+    } catch (error) {
+      throw new Error(`Language detection failed: ${error.message}`);
+    }
   },📝 Committable suggestion
 
        Suggested change
       
    
 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first point seems to be a fair one, can you check that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jcortes, you're right—the first point about the typo in the success message is valid. The extra   | 
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -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; | ||
| }, | ||
                
      
                  jcortes marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| }; | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export default { | ||
| PROFANITY_ACTIONS: [ | ||
| "NoAction", | ||
| "Marked", | ||
| "Deleted", | ||
| ], | ||
| }; | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -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", | ||
| }, | ||
| }); | ||
| }, | ||
                
      
                  jcortes marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| 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, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.