protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { var appId = "a4fe9ae0-be39-4837-b2d9-ed3ca0b33af2"; var key = "127183aa64af4de893cc822599f2a4ec"; var predictionResourceName = "luisgroup"; var predictionEndpoint = $"https://{predictionResourceName}.cognitiveservices.azure.com/"; var credentials = new Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring.ApiKeyServiceClientCredentials(key); var runtimeClient = new LUISRuntimeClient(credentials) { Endpoint = predictionEndpoint }; var gAppId = new Guid(appId); var request = new PredictionRequest { Query = "add tomatoes to rakata1" }; var predi = await runtimeClient.Prediction.GetSlotPredictionAsync(gAppId, "Production", request); var topIntent = predi.Prediction.TopIntent; switch (topIntent) { /* * aqui estara todas las opciones que ahorita se ocupan de luis */ } }
public static IServiceCollection AddLUIS(this IServiceCollection services, IConfiguration configuration) { services.Configure <LuisSettings>(configuration.GetSection("Luis")); var settings = services.BuildServiceProvider().GetRequiredService <IOptions <LuisSettings> >()?.Value ?? throw new ArgumentNullException(nameof(LuisSettings)); services.AddScoped <ILUISAuthoringClient>(_ => { var credentials = new ApiKeyServiceClientCredentials(settings.AuthoringKey); var client = new LUISAuthoringClient(credentials); client.Endpoint = settings.AuthoringEndpoint; return(client); }) .AddScoped <ILUISRuntimeClient>(_ => { var credentials = new ApiKeyServiceClientCredentials(settings.SubscriptionKey); var client = new LUISRuntimeClient(credentials); client.Endpoint = settings.RuntimeEndpoint; return(client); }); return(services); }
async static Task RunQuickstart() { var credentials = new Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring.ApiKeyServiceClientCredentials(subscriptionKey); var client = new LUISAuthoringClient(credentials, new System.Net.Http.DelegatingHandler[] { }) { Endpoint = "https://" + region + ".api.cognitive.microsoft.com" }; var app_info = await GetOrCreateApplication(client); await AddEntities(client, app_info); await AddIntents(client, app_info); await AddUtterances(client, app_info); Console.WriteLine("You can now train and publish this LUIS application (see Publish.cs)."); }
async static Task RunQuickstart() { // Generate the credentials and create the authoring client. var authoring_credentials = new Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring.ApiKeyServiceClientCredentials(authoring_key); var authoring_client = new LUISAuthoringClient(authoring_credentials, new System.Net.Http.DelegatingHandler[] { }) { Endpoint = authoring_endpoint }; // Generate the credentials and create the runtime client. var runtime_credentials = new Microsoft.Azure.CognitiveServices.Language.LUIS.Runtime.ApiKeyServiceClientCredentials(runtime_key); var runtime_client = new LUISRuntimeClient(runtime_credentials, new System.Net.Http.DelegatingHandler[] { }) { Endpoint = runtime_endpoint }; Console.WriteLine("Creating application..."); var app = await CreateApplication(authoring_client); Console.WriteLine(); /* We skip adding entities, intents, and utterances because the * predict method will not find the app anyway. */ Console.WriteLine("Training application..."); await Train_App(authoring_client, app); Console.WriteLine("Waiting 30 seconds for training to complete..."); System.Threading.Thread.Sleep(30000); Console.WriteLine(); Console.WriteLine("Publishing application..."); await Publish_App(authoring_client, app); Console.WriteLine(); Console.WriteLine("Querying application..."); /* It doesn't matter what query we send because the predict method * will not find the app anyway. */ await Query_App(runtime_client, app, "test"); Console.WriteLine(); Console.WriteLine("Deleting application..."); await Delete_App(authoring_client, app); }
// </AuthoringPublishVersionAndSlot> async static Task RunQuickstart() { // <AuthoringCreateClient> // Generate the credentials and create the client. var credentials = new Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring.ApiKeyServiceClientCredentials(authoring_key); var client = new LUISAuthoringClient(credentials, new System.Net.Http.DelegatingHandler[] { }) { Endpoint = authoring_endpoint }; // </AuthoringCreateClient> Console.WriteLine("Creating application..."); var app = await CreateApplication(client); Console.WriteLine(); Console.WriteLine("Adding entities to application..."); await AddEntities(client, app); Console.WriteLine(); Console.WriteLine("Adding intents to application..."); await AddIntents(client, app); Console.WriteLine(); Console.WriteLine("Adding utterances to application..."); await AddUtterances(client, app); Console.WriteLine(); Console.WriteLine("Training application..."); await Train_App(client, app); Console.WriteLine("Waiting 30 seconds for training to complete..."); System.Threading.Thread.Sleep(30000); Console.WriteLine(); Console.WriteLine("Publishing application..."); await Publish_App(client, app); Console.WriteLine(); }
async static Task RunQuickstart() { // Generate the credentials and create the client. var credentials = new Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring.ApiKeyServiceClientCredentials(subscriptionKey); var client = new LUISAuthoringClient(credentials, new System.Net.Http.DelegatingHandler[] { }) { Endpoint = "https://" + region + ".api.cognitive.microsoft.com" }; var response = await Train_App(client); Console.WriteLine("Training status: " + response.Status); // Publish the application and show the endpoint URL for the published application. var info = await Publish_App(client); Console.WriteLine("Endpoint URL: " + info.EndpointUrl); }
public LuisClient( string authoringKey, string authoringRegion, string endpointKey, string endpointRegion, AzureSubscriptionInfo azureSubscriptionInfo, bool isStaging) { this.IsStaging = isStaging; var endpointOrAuthoringKey = endpointKey ?? authoringKey ?? throw new ArgumentException($"Must specify either '{nameof(authoringKey)}' or '{nameof(endpointKey)}'."); this.EndpointRegion = endpointRegion ?? authoringRegion ?? throw new ArgumentException($"Must specify either '{nameof(authoringRegion)}' or '{nameof(endpointRegion)}'."); this.AzureSubscriptionInfo = azureSubscriptionInfo; this.AuthoringKey = authoringKey; var endpointCredentials = new Microsoft.Azure.CognitiveServices.Language.LUIS.Runtime.ApiKeyServiceClientCredentials(endpointOrAuthoringKey); this.RuntimeClient = new LUISRuntimeClient(endpointCredentials) { Endpoint = $"{Protocol}{this.EndpointRegion}{Domain}", }; this.LazyAuthoringClient = new Lazy <LUISAuthoringClient>(() => { if (authoringKey == null || authoringRegion == null) { throw new InvalidOperationException("Must provide authoring key and region to perform authoring operations."); } var authoringCredentials = new Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring.ApiKeyServiceClientCredentials(authoringKey); return(new LUISAuthoringClient(authoringCredentials) { Endpoint = $"{Protocol}{authoringRegion}{Domain}", }); }); this.LazySpeechConfig = new Lazy <SpeechConfig>(() => SpeechConfig.FromSubscription(endpointKey, endpointRegion)); }
public static async Task Main() { // <VariablesYouChange> var key = "REPLACE-WITH-YOUR-AUTHORING-KEY"; var authoringResourceName = "REPLACE-WITH-YOUR-AUTHORING-RESOURCE-NAME"; var predictionResourceName = "REPLACE-WITH-YOUR-PREDICTION-RESOURCE-NAME"; // </VariablesYouChange> // <VariablesYouDontNeedToChangeChange> var authoringEndpoint = String.Format("https://{0}.cognitiveservices.azure.com/", authoringResourceName); var predictionEndpoint = String.Format("https://{0}.cognitiveservices.azure.com/", predictionResourceName); var appName = "Contoso Pizza Company"; var versionId = "0.1"; var intentName = "OrderPizzaIntent"; // </VariablesYouDontNeedToChangeChange> // <AuthoringCreateClient> var credentials = new Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring.ApiKeyServiceClientCredentials(key); var client = new LUISAuthoringClient(credentials) { Endpoint = authoringEndpoint }; // </AuthoringCreateClient> // Create app var appId = await CreateApplication(client, appName, versionId); // <AddIntent> await client.Model.AddIntentAsync(appId, versionId, new ModelCreateObject() { Name = intentName }); // </AddIntent> // Add Entities await AddEntities(client, appId, versionId); // Add Labeled example utterance await AddLabeledExample(client, appId, versionId, intentName); // <TrainAppVersion> await client.Train.TrainVersionAsync(appId, versionId); while (true) { var status = await client.Train.GetStatusAsync(appId, versionId); if (status.All(m => m.Details.Status == "Success")) { // Assumes that we never fail, and that eventually we'll always succeed. break; } } // </TrainAppVersion> // <PublishVersion> await client.Apps.PublishAsync(appId, new ApplicationPublishObject { VersionId = versionId, IsStaging = false }); // </PublishVersion> // <PredictionCreateClient> var runtimeClient = new LUISRuntimeClient(credentials) { Endpoint = predictionEndpoint }; // </PredictionCreateClient> // <QueryPredictionEndpoint> // Production == slot name var request = new PredictionRequest { Query = "I want two small pepperoni pizzas with more salsa" }; var prediction = await runtimeClient.Prediction.GetSlotPredictionAsync(appId, "Production", request); Console.Write(JsonConvert.SerializeObject(prediction, Formatting.Indented)); // </QueryPredictionEndpoint> }
// It's always a good idea to access services in an async fashion public static async Task Main() { var authoringEndpoint = String.Format("https://{0}.cognitiveservices.azure.com/", AUTHORING_RESOURCE_NAME); var predictionEndpoint = String.Format("https://{0}.cognitiveservices.azure.com/", PREDICTION_RESOURCE_NAME); var appName = "Contoso Pizza Company"; var versionId = "0.1"; var intentName = "OrderPizza"; // Authenticate the client Console.WriteLine("Authenticating the client..."); var credentials = new Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring.ApiKeyServiceClientCredentials(AUTHORING_KEY); var client = new LUISAuthoringClient(credentials) { Endpoint = authoringEndpoint }; // Create a LUIS app var newApp = new ApplicationCreateObject { Culture = "en-us", Name = appName, InitialVersionId = versionId }; Console.WriteLine("Creating a LUIS app..."); var appId = await client.Apps.AddAsync(newApp); // Create intent for the app Console.WriteLine("Creating intent for the app..."); await client.Model.AddIntentAsync(appId, versionId, new ModelCreateObject() { Name = intentName }); // Create entities for the app Console.WriteLine("Creating entities for the app..."); // Add Prebuilt entity await client.Model.AddPrebuiltAsync(appId, versionId, new[] { "number" }); // Define ml entity with children and grandchildren var mlEntityDefinition = new EntityModelCreateObject { Name = "Pizza order", Children = new[] { new ChildEntityModelCreateObject { Name = "Pizza", Children = new[] { new ChildEntityModelCreateObject { Name = "Quantity" }, new ChildEntityModelCreateObject { Name = "Type" }, new ChildEntityModelCreateObject { Name = "Size" } } }, new ChildEntityModelCreateObject { Name = "Toppings", Children = new[] { new ChildEntityModelCreateObject { Name = "Type" }, new ChildEntityModelCreateObject { Name = "Quantity" } } } } }; // Add ML entity var mlEntityId = await client.Model.AddEntityAsync(appId, versionId, mlEntityDefinition);; // Add phraselist feature var phraselistId = await client.Features.AddPhraseListAsync(appId, versionId, new PhraselistCreateObject { EnabledForAllModels = false, IsExchangeable = true, Name = "QuantityPhraselist", Phrases = "few,more,extra" }); // Get entity and subentities var model = await client.Model.GetEntityAsync(appId, versionId, mlEntityId); var toppingQuantityId = GetModelGrandchild(model, "Toppings", "Quantity"); var pizzaQuantityId = GetModelGrandchild(model, "Pizza", "Quantity"); // add model as feature to subentity model await client.Features.AddEntityFeatureAsync(appId, versionId, pizzaQuantityId, new ModelFeatureInformation { ModelName = "number", IsRequired = true }); await client.Features.AddEntityFeatureAsync(appId, versionId, toppingQuantityId, new ModelFeatureInformation { ModelName = "number" }); // add phrase list as feature to subentity model await client.Features.AddEntityFeatureAsync(appId, versionId, toppingQuantityId, new ModelFeatureInformation { FeatureName = "QuantityPhraselist" }); // Add example utterance to intent Console.WriteLine("Adding example utterance to intent..."); // Define labeled example var labeledExampleUtteranceWithMLEntity = new ExampleLabelObject { Text = "I want two small seafood pizzas with extra cheese.", IntentName = intentName, EntityLabels = new[] { new EntityLabelObject { StartCharIndex = 7, EndCharIndex = 48, EntityName = "Pizza order", Children = new[] { new EntityLabelObject { StartCharIndex = 7, EndCharIndex = 30, EntityName = "Pizza", Children = new[] { new EntityLabelObject { StartCharIndex = 7, EndCharIndex = 9, EntityName = "Quantity" }, new EntityLabelObject { StartCharIndex = 11, EndCharIndex = 15, EntityName = "Size" }, new EntityLabelObject { StartCharIndex = 17, EndCharIndex = 23, EntityName = "Type" } } }, new EntityLabelObject { StartCharIndex = 37, EndCharIndex = 48, EntityName = "Toppings", Children = new[] { new EntityLabelObject { StartCharIndex = 37, EndCharIndex = 41, EntityName = "Quantity" }, new EntityLabelObject { StartCharIndex = 43, EndCharIndex = 48, EntityName = "Type" } } } } }, } }; // Add an example for the entity. // Enable nested children to allow using multiple models with the same name. // The quantity subentity and the phraselist could have the same exact name if this is set to True await client.Examples.AddAsync(appId, versionId, labeledExampleUtteranceWithMLEntity, enableNestedChildren : true); // Train the app Console.WriteLine("Training the app..."); await client.Train.TrainVersionAsync(appId, versionId); while (true) { var status = await client.Train.GetStatusAsync(appId, versionId); if (status.All(m => m.Details.Status == "Success")) { // Assumes that we never fail, and that eventually we'll always succeed. break; } } // Publish app to production slot Console.WriteLine("Publishing the app to production slot..."); await client.Apps.PublishAsync(appId, new ApplicationPublishObject { VersionId = versionId, IsStaging = false }); // Authenticate the prediction runtime client Console.WriteLine("Authenticating the prediction client..."); credentials = new Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring.ApiKeyServiceClientCredentials(PREDICTION_KEY); var runtimeClient = new LUISRuntimeClient(credentials) { Endpoint = predictionEndpoint }; // Get prediction from runtime // Production == slot name Console.WriteLine("Getting prediction..."); var request = new PredictionRequest { Query = "I want two small pepperoni pizzas with more salsa" }; var prediction = await runtimeClient.Prediction.GetSlotPredictionAsync(appId, "Production", request); Console.Write(JsonConvert.SerializeObject(prediction, Formatting.Indented)); }