How to use the ms-rest-azure.CognitiveServicesCredentials function in ms-rest-azure

To help you get started, we’ve selected a few ms-rest-azure examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure-Samples / cognitive-services-node-sdk-samples / Samples / computerVision.js View on Github external
// Add your Computer Vision endpoint and subscription key to your environment variables.
let keyVar = 'COMPUTER_VISION_SUBSCRIPTION_KEY';
let endpoint = process.env['COMPUTER_VISION_ENDPOINT']

if (!process.env[keyVar]) {
  throw new Error('Please set/export the following environment variable: ' + keyVar);
}

let serviceKey = process.env[keyVar];


///////////////////////////////////////////
//     Entrypoint for sample script      //
///////////////////////////////////////////

let credentials = new CognitiveServicesCredentials(serviceKey);
let computerVisionApiClient = new Vision.ComputerVisionAPIClient(credentials, endpoint);
let cvModels = computerVisionApiClient.models;

function sample() {
  async.series([
    async function () {
      console.log("1. This will analyze a house image and describe it.");
      let fileStream = fs.createReadStream('Data/house.jpg');

      let result = await computerVisionApiClient.analyzeImageInStream(fileStream, {
        visualFeatures: ["Categories", "Tags", "Description", "Color", "Faces", "ImageType"]
      });

      // Description Results
      if (((result.description || {}).captions || {}).length > 0){
        console.log(`The image can be described as: ${result.description.captions[0].text}`);
github Azure-Samples / cognitive-services-node-sdk-samples / Samples / imageSearch.js View on Github external
const CognitiveServicesCredentials = require('ms-rest-azure').CognitiveServicesCredentials;

let keyVar = 'AZURE_IMAGE_SEARCH_KEY';

if (!process.env[keyVar]) {
  throw new Error('please set/export the following environment variable: ' + keyVar);
}

let serviceKey = process.env[keyVar];


///////////////////////////////////////////
//     Entrypoint for sample script      //
///////////////////////////////////////////

let credentials = new CognitiveServicesCredentials(serviceKey);
let imageSearchApiClient = new Search.ImageSearchAPIClient(credentials);

function sample() {
  async.series([
    async function () {
      console.log("1. This will search images for (canadian rockies) then verify number of results and print out first image result, pivot suggestion, and query expansion");

      let imageResults = await imageSearchApiClient.imagesOperations.search("canadian rockies");
      console.log("Search images for query \"canadian rockies\"");

      if (imageResults == null) {
        console.log("No image result data.");
      }
      else {
        // Image results
        if (imageResults.value.length > 0) {
github Azure-Samples / cognitive-services-node-sdk-samples / Samples / visualSearch.js View on Github external
const CognitiveServicesCredentials = require('ms-rest-azure').CognitiveServicesCredentials;

// Add your Bing Search V7 subscription key to your environment variables.
let keyVar = process.env['BING_SEARCH_V7_SUBSCRIPTION_KEY']

if (!process.env[keyVar]) {
  throw new Error('please set/export the following environment variable: ' + keyVar);
}

let serviceKey = process.env[keyVar];

///////////////////////////////////////////
//     Entrypoint for sample script      //
///////////////////////////////////////////

let credentials = new CognitiveServicesCredentials(serviceKey);
let visualSearchApiClient = new Search.VisualSearchAPIClient(credentials);
let visualModels = visualSearchApiClient.models;

function sample() {
  async.series([
    async function () {
      let fileStream = fs.createReadStream('Data/image.jpg');
      let visualSearchRequest = JSON.stringify({});
      let visualSearchResults;
      try {
        visualSearchResults = await visualSearchApiClient.images.visualSearch({
          image: fileStream,
          knowledgeRequest: visualSearchRequest
        });
        console.log("Search visual search request with binary of dog image");
      } catch (err) {
github Azure-Samples / cognitive-services-node-sdk-samples / Samples / autoSuggest.js View on Github external
// Add your Bing Autosuggest subscription key to your environment variables.
const keyVar = process.env['BING_AUTOSUGGEST_SUBSCRIPTION_KEY']

if (!process.env[keyVar]) {
  throw new Error('please set/export the following environment variable: ' + keyVar);
}

const serviceKey = process.env[keyVar];

const query = "Satya Nadella";

///////////////////////////////////////////
//     Entrypoint for sample script      //
///////////////////////////////////////////

const credentials = new CognitiveServicesCredentials(serviceKey);
const autoSuggestApiClient = new Search.AutoSuggestAPIClient(credentials);
const autoSuggestModels = autoSuggestApiClient.models;

function sample() {
  async.series([
    async function () {
      let autoSuggestResults;
      try {
        autoSuggestResults = await autoSuggestApiClient.autoSuggest(query);
        console.log("Request autosuggestions for '" + query + "'");
      } catch (err) {
        console.log("Encountered exception. " + err.message);
      }
      if (!autoSuggestResults) {
        console.log("No autosuggest result data. ");
      } else {
github Azure-Samples / cognitive-services-node-sdk-samples / Samples / entitySearch.js View on Github external
const CognitiveServicesCredentials = require('ms-rest-azure').CognitiveServicesCredentials;

let keyVar = 'AZURE_ENTITY_SEARCH_KEY';

if (!process.env[keyVar]) {
  throw new Error('please set/export the following environment variable: ' + keyVar);
}

let serviceKey = process.env[keyVar];


///////////////////////////////////////////
//     Entrypoint for sample script      //
///////////////////////////////////////////

let credentials = new CognitiveServicesCredentials(serviceKey);
let entitySearchApiClient = new Search.EntitySearchAPIClient(credentials);
let entityModels = entitySearchApiClient.models;

function sample() {
  async.series([
    async function () {
      console.log("1. This will look up a single entity (Satya Nadella) and print out a short description about them.");
      let result;
      try {
        result = await entitySearchApiClient.entitiesOperations.search("Satya Nadella");
      } catch (err) {
        if (err instanceof entityModels.ErrorResponse) {
          console.log("Encountered exception. " + err.message);
        }
      }
      if (((result.entities || {}).value || {}).length > 0) {
github Azure / azure-sdk-for-node / test / services / cognitiveServicesVision / contentModeratorClient-tests.js View on Github external
suite.setupSuite(() => {
      credentials = new CognitiveServicesCredentials(process.env["AZURE_CONTENT_MODERATOR_KEY"]);
      client = new ContentModeratorClient(credentials, "westus.api.cognitive.microsoft.com");
      done();
    });
  });
github Azure / azure-sdk-for-node / test / services / cognitiveServicesSearch / videoSearch-tests.js View on Github external
suite.setupSuite(function () {
      let credentials = new CognitiveServicesCredentials(process.env["AZURE_VIDEO_SEARCH_KEY"]);
      client = new VideoSearchClient(credentials);
      done();
    });
  });
github Azure-Samples / cognitive-services-node-sdk-samples / Samples / luis / luisAuthoring.js View on Github external
async function bookingApp(subscriptionKey) {
    const credentials = new CognitiveServicesCredentials(subscriptionKey);
    const client = new LUISAuthoringClient(credentials, "https://westus.api.cognitive.microsoft.com")

    const defaultAppName = "Contoso-" + (new Date().getTime())
    const versionId = "0.1"

    console.log("Creating App %s, version %s", defaultAppName, versionId)

    const description = "New App created with LUIS Node.js sample"
    const applicationCreateObject = {
        culture: "en-us",
        initialVersionId: versionId,
        description: description,
        name: defaultAppName,
    }

    const appId = await client.apps.add(applicationCreateObject)
github microsoft / botframework-solutions / templates / Enterprise-Template / src / typescript / enterprise-bot / src / middleware / contentModeratorMiddleware.ts View on Github external
constructor(subscriptionKey: string, region: string) {
        this.contentModeratorClient = new ContentModeratorClient(
            new CognitiveServicesCredentials(subscriptionKey),
            `https://${region}.api.cognitive.microsoft.com`
            );
    }
github microsoft / BotBuilder-Samples / samples / javascript_typescript / 52.enterprise-bot / src / middleware / contentModeratorMiddleware.ts View on Github external
constructor(subscriptionKey: string, region: string) {
        this._cmClient = new ContentModeratorClient(new CognitiveServicesCredentials(subscriptionKey), `https://${region}.api.cognitive.microsoft.com`);
    }