Set Up Your Azure Cognitive Services
- Navigate to the Azure Portal and sign in with your Azure account.
- Click on "Create a resource" and search for "Cognitive Services". Click on it and then select "Create".
- Fill in the required details such as Subscription, Resource Group, and the type of Cognitive Service you want to use (e.g., Text Analytics, Computer Vision, etc.).
- Once the service is created, navigate to the resource page to find your Endpoint and Keys.
Create a GitHub Repository
- Go to GitHub and log into your account. Click on the "+" icon at the top right corner and select "New repository".
- Provide a name for your repository and a description (optional). Choose visibility settings (public or private) and click "Create repository".
Set Up Environment Variables
- Create a new file in the root of your repository named
.env
. This will be used to store your sensitive Azure details like Endpoint and Keys.
AZURE_ENDPOINT=<Your Azure Cognitive Services Endpoint>
AZURE_KEY=<Your Azure Cognitive Services Key>
Initialize Your Project and Install Required Packages
- Clone your GitHub repository to your local machine.
- Initialize your project. If you're using Node.js, for example, you would run:
npm init -y
- Install the Azure SDK client libraries suitable for your project. For general purposes, you might use:
npm install @azure/ai-text-analytics
Integrate Cognitive Services into Your Application
- Create a new file, say
analyze.js
, to interact with Azure Cognitive Services.
- Inside your file, set up the configuration and write the code to call the Azure services. Here is an example of how you might configure a Text Analytics client:
require('dotenv').config();
const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
const endpoint = process.env.AZURE_ENDPOINT;
const apiKey = process.env.AZURE_KEY;
const textAnalyticsClient = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));
async function analyzeSentimentOfText(text) {
const results = await textAnalyticsClient.analyzeSentiment([text]);
console.log(JSON.stringify(results, null, 2));
}
analyzeSentimentOfText("Azure Cognitive Services are pretty cool!");
Push Changes to GitHub
- Add your newly created files to git:
git add .
git commit -m "Set up Azure Cognitive Services integration"
- Push your changes to the GitHub repository:
git push origin main
Secure Your Configuration
- Ensure your
.env
file is listed in the .gitignore
file to prevent sensitive information from being pushed to your GitHub repository.
.env
Verify Integration
- Once pushed, you can verify if the integration is working by running your application and checking the output of the Cognitive Services operations.