Last active
August 25, 2020 11:08
-
-
Save olafwrieden/a3486bf145c6b082897578eef8f630db to your computer and use it in GitHub Desktop.
Sentiment Analysis Snippets for Azure, AWS, GCP.
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
const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics"); | |
const client = new TextAnalyticsClient(process.env["TEXT_ANALYSIS_ENDPOINT"], new AzureKeyCredential(process.env["TEXT_ANALYSIS_KEY"])); | |
module.exports = async function (context, req) { | |
// Extract submitted text from request body | |
const text = req.body && req.body.text; | |
if (!text) { | |
// Error if no text was found | |
return context.res = { | |
status: 422, | |
body: "A text key value pair is required." | |
}; | |
} else { | |
// Await sentiment analysis for the text | |
const sentiment = await client.analyzeSentiment([text]); | |
// Return sentiment details | |
return context.res = { | |
status: 200, | |
body: sentiment[0] | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment