static int AddExampleUtterance(LUISAuthoringClient client, Guid appId, string versionId, string intent, string utterance, EntityLabelObject taggedEntity) { try { // creating list and adding 1 item var taggedEntities = new List <EntityLabelObject>(); taggedEntities.Add(taggedEntity); // create example object var exampleLabelObject = new ExampleLabelObject(utterance, taggedEntities, intent); // create example var response = client.Examples.AddAsync(appId, versionId, exampleLabelObject, CancellationToken.None).Result; if (response.ExampleId == null) { return(default(int)); } else { return(response.ExampleId.Value); } } catch (Exception ex) { Console.WriteLine(ex.InnerException); throw ex; } }
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); }
static Guid CreateApp(LUISAuthoringClient client, string resourceRegion, string appName, string versionId, string culture, string description) { try { // don't set because it isn't used by LUIS var domain = String.Empty; var usageScenario = String.Empty; // create app definition object var app = new ApplicationCreateObject(culture, appName, domain, description, versionId, usageScenario); // create app var response = client.Apps.AddWithHttpMessagesAsync(app, null, CancellationToken.None).Result; // get appId from `Location` header - trim away URL part to get appId var newAppId = response.Response.Headers.Location.ToString().Replace(String.Format("https://{0}.api.cognitive.microsoft.com/luis/api/v2.0/apps/", resourceRegion), ""); // convert string to guid and return it return(new Guid(newAppId)); } catch (Exception ex) { Console.WriteLine(ex.InnerException); throw ex; } }
private ILUISAuthoringClient GetClient(DelegatingHandler handler) { var client = new LUISAuthoringClient(new ApiKeyServiceClientCredentials(AuthoringKey), handlers: handler); client.Endpoint = "https://westus.api.cognitive.microsoft.com"; return(client); }
// </AuthoringAddIntents> // <AuthoringBatchAddUtterancesForIntent> async static Task AddUtterances(LUISAuthoringClient client, ApplicationInfo app_info) { var utterances = new List <ExampleLabelObject>() { CreateUtterance("FindFlights", "find flights in economy to Madrid on July 1st", new Dictionary <string, string>() { { "Flight", "economy to Madrid" }, { "Location", "Madrid" }, { "Class", "economy" } }), CreateUtterance("FindFlights", "find flights from seattle to London in first class", new Dictionary <string, string>() { { "Flight", "London in first class" }, { "Location", "London" }, { "Class", "first" } }), CreateUtterance("FindFlights", "find flights to London in first class", new Dictionary <string, string>() { { "Flight", "London in first class" }, { "Location", "London" }, { "Class", "first" } }), //Role not supported in SDK yet //CreateUtterance ("FindFlights", "find flights to Paris in first class", new Dictionary<string, string>() { { "Flight", "London in first class" }, { "Location::Destination", "Paris" }, { "Class", "first" } }) }; var resultsList = await client.Examples.BatchAsync(app_info.ID, app_info.Version, utterances); foreach (var x in resultsList) { var result = (!x.HasError.GetValueOrDefault()) ? "succeeded": "failed"; Console.WriteLine("{0} {1}", x.Value.ExampleId, result); } }
/* Create a new LUIS application or get an existing one, depending on whether app_id * is specified. Return the application ID and version. */ async static Task <ApplicationInfo> GetOrCreateApplication(LUISAuthoringClient client) { if (String.IsNullOrEmpty(app_id)) { string app_version = "0.1"; var app_info = new ApplicationCreateObject() { Name = String.Format("Contoso {0}", DateTime.Now), InitialVersionId = app_version, Description = "Flight booking app built with LUIS .NET SDK.", Culture = "en-us" }; var app_id = await client.Apps.AddAsync(app_info); Console.WriteLine("Created new LUIS application {0}\n with ID {1}", app_info.Name, app_id); Console.WriteLine("Make a note of this ID to use this application with other samples.\n"); return(new ApplicationInfo() { ID = app_id, Version = app_version }); } else { var app_info = await client.Apps.GetAsync(new Guid(app_id)); var app_version = app_info.ActiveVersion; Console.WriteLine("Using existing LUIS application", app_info.Name, app_version); return(new ApplicationInfo() { ID = new Guid(app_id), Version = app_version }); } }
// Add entities to the LUIS application. async static Task AddEntities(LUISAuthoringClient client, ApplicationInfo app_info) { await client.Model.AddEntityAsync(app_info.ID, app_info.Version, new ModelCreateObject() { Name = "Destination" }); await client.Model.AddHierarchicalEntityAsync(app_info.ID, app_info.Version, new HierarchicalEntityModel() { Name = "Class", Children = new List <string>() { "First", "Business", "Economy" } }); await client.Model.AddCompositeEntityAsync(app_info.ID, app_info.Version, new CompositeEntityModel() { Name = "Flight", Children = new List <string>() { "Class", "Destination" } }); Console.WriteLine("Created entities Destination, Class, Flight."); }
// </AuthoringAddLabeledExamples> async static Task AddLabeledExample(LUISAuthoringClient client, Guid appId, string versionId, string intentName) { // 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. await client.Examples.AddAsync(appId, versionId, labeledExampleUtteranceWithMLEntity, enableNestedChildren : true); }
static void Main(string[] args) { ReadConfiguration(); var client = new LUISAuthoringClient(new Uri("https://" + Region + ".api.cognitive.microsoft.com/luis/api/v2.0/"), new ApiKeyServiceClientCredentials(ProgrammaticKey)); var program = new BaseProgram(client, ProgrammaticKey); program.Run(); }
// </AuthoringAddEntities> // <AuthoringAddIntents> async static Task AddIntents(LUISAuthoringClient client, ApplicationInfo app_info) { await client.Model.AddIntentAsync(app_info.ID, app_info.Version, new ModelCreateObject() { Name = "FindFlights" }); Console.WriteLine("Created intent FindFlights"); }
static void Main(string[] args) { ReadConfiguration(); EndPoint = EndPoint.Insert(EndPoint.Length - 5, "/api"); var client = new LUISAuthoringClient(new Uri(EndPoint), new ApiKeyServiceClientCredentials(ProgrammaticKey)); var program = new BaseProgram(client, ProgrammaticKey); program.Run(); }
// Publish the application. async static Task <ProductionOrStagingEndpointInfo> Publish_App(LUISAuthoringClient client) { ApplicationPublishObject obj = new ApplicationPublishObject { VersionId = app_version_id, IsStaging = true }; return(await client.Apps.PublishAsync(new Guid(app_id), obj)); }
static async Task Main(string[] args) { var credentials = new ApiKeyServiceClientCredentials(""); var client = new LUISAuthoringClient(credentials); client.Endpoint = "https://westus.api.cognitive.microsoft.com/"; var configuration = JsonConvert.DeserializeObject <BotConversation.BotConfiguration>(File.ReadAllText("../../../../Data/conversation.json")); var desiredIntents = configuration.Intents.Keys.ToArray(); var apps = await client.Apps.ListAsync(); foreach (var app in apps) { var key = configuration.Apps[app.Name].Key; var entitiesFound = new List <string>(); var existingIntents = (await client.Model.ListIntentsAsync(app.Id.Value, app.ActiveVersion)).ToDictionary(xx => xx.Name, xx => xx.Id); foreach (var intentToAdd in desiredIntents.Except(existingIntents.Keys)) { await client.Model.AddIntentAsync(app.Id.Value, app.ActiveVersion, new ModelCreateObject { Name = intentToAdd }); foreach (var utterance in configuration.Intents[intentToAdd][key]) { await client.EnsureUtterance(app, intentToAdd, utterance, entitiesFound); } } foreach (var intentToRemove in existingIntents.Keys.Except(desiredIntents)) { if (intentToRemove == "None") { continue; } await client.Model.DeleteIntentAsync(app.Id.Value, app.ActiveVersion, existingIntents[intentToRemove]); } foreach (var intentToUpdate in existingIntents.Keys.Intersect(desiredIntents)) { // nothing to do foreach (var utterance in configuration.Intents[intentToUpdate][key]) { await client.EnsureUtterance(app, intentToUpdate, utterance, entitiesFound); } } await client.Train.TrainVersionAsync(app.Id.Value, app.ActiveVersion); //await client.Apps.PublishAsync(app.Id.Value, new ApplicationPublishObject { // VersionId = app.ActiveVersion, // IsStaging = false //}); } }
static void Main(string[] args) { ReadConfiguration(); var client = new LUISAuthoringClient(new ApiKeyServiceClientCredentials(ProgrammaticKey)); client.Endpoint = EndPoint; var program = new BaseProgram(client, ProgrammaticKey); program.Run(); }
// </AuthoringTrainVersion> // <AuthoringPublishVersionAndSlot> // Publish app, display endpoint URL for the published application. async static Task Publish_App(LUISAuthoringClient client, ApplicationInfo app) { ApplicationPublishObject obj = new ApplicationPublishObject { VersionId = app.Version, IsStaging = true }; var info = await client.Apps.PublishAsync(app.ID, obj); Console.WriteLine("Endpoint URL: " + info.EndpointUrl); }
static async Task EnsureUtterance(this LUISAuthoringClient client, ApplicationInfoResponse app, string intent, string utterance, List <string> entitiesFound) { var elos = new List <EntityLabelObject>(); var effectiveUtterance = utterance; while (true) { var entityInfoCaptured = entityInfoRegex.Match(effectiveUtterance); if (!entityInfoCaptured.Success) { break; } var entityInfo = entityInfoCaptured.Groups["entityInfo"].Value.Split(':'); var entityValue = entityInfo[0]; var entityName = entityInfo[1]; if (!entitiesFound.Contains(entityName)) { // brute force insert (throws ex if exists) try { await client.Model.AddEntityAsync(app.Id.Value, app.ActiveVersion, new ModelCreateObject { Name = entityName }); } catch (Exception ex) { } finally { entitiesFound.Add(entityName); } } var elo = new EntityLabelObject { EntityName = entityName, StartCharIndex = entityInfoCaptured.Index, EndCharIndex = entityInfoCaptured.Index + entityValue.Length - 1 }; elos.Add(elo); effectiveUtterance = effectiveUtterance.Replace(entityInfoCaptured.Groups[0].Value, entityValue); } await client.Examples.AddAsync(app.Id.Value, app.ActiveVersion, new ExampleLabelObject { Text = effectiveUtterance, IntentName = intent, EntityLabels = elos }); }
// Add utterances to the LUIS application. async static Task AddUtterances(LUISAuthoringClient client, ApplicationInfo app_info) { var utterances = new List <ExampleLabelObject>() { CreateUtterance("FindFlights", "find flights in economy to Madrid", new Dictionary <string, string>() { { "Flight", "economy to Madrid" }, { "Destination", "Madrid" }, { "Class", "economy" } }), CreateUtterance("FindFlights", "find flights to London in first class", new Dictionary <string, string>() { { "Flight", "London in first class" }, { "Destination", "London" }, { "Class", "first" } }) }; await client.Examples.BatchAsync(app_info.ID, app_info.Version, utterances); }
// </AuthoringCreateApplication> // <AuthoringAddEntities> // Create entity objects async static Task AddEntities(LUISAuthoringClient client, ApplicationInfo app_info) { // Add simple entity var simpleEntityIdLocation = await client.Model.AddEntityAsync(app_info.ID, app_info.Version, new ModelCreateObject() { Name = "Location" }); // Add 'Origin' role to simple entity await client.Model.CreateEntityRoleAsync(app_info.ID, app_info.Version, simpleEntityIdLocation, new EntityRoleCreateObject() { Name = "Origin" }); // Add 'Destination' role to simple entity await client.Model.CreateEntityRoleAsync(app_info.ID, app_info.Version, simpleEntityIdLocation, new EntityRoleCreateObject() { Name = "Destination" }); // Add simple entity var simpleEntityIdClass = await client.Model.AddEntityAsync(app_info.ID, app_info.Version, new ModelCreateObject() { Name = "Class" }); // Add prebuilt number and datetime await client.Model.AddPrebuiltAsync(app_info.ID, app_info.Version, new List <string> { "number", "datetimeV2", "geographyV2", "ordinal" }); // Composite entity await client.Model.AddCompositeEntityAsync(app_info.ID, app_info.Version, new CompositeEntityModel() { Name = "Flight", Children = new List <string>() { "Location", "Class", "number", "datetimeV2", "geographyV2", "ordinal" } }); Console.WriteLine("Created entities Location, Class, number, datetimeV2, geographyV2, ordinal."); }
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); }
async static Task <Guid> CreateApplication(LUISAuthoringClient client, string appName, string versionId) { // <AuthoringCreateApplication> var newApp = new ApplicationCreateObject { Culture = "en-us", Name = appName, InitialVersionId = versionId }; var appId = await client.Apps.AddAsync(newApp); // </AuthoringCreateApplication> Console.WriteLine("New app ID {0}.", appId); return(appId); }
// </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(); }
// Create a new LUIS application. Return the application ID and version. async static Task <ApplicationInfo> CreateApplication(LUISAuthoringClient client) { string app_version = "0.1"; var app_info = new ApplicationCreateObject() { Name = String.Format("Contoso {0}", DateTime.Now), InitialVersionId = app_version, Description = "Flight booking app built with LUIS .NET SDK.", Culture = "en-us" }; var app_id = await client.Apps.AddAsync(app_info); Console.WriteLine("Created new LUIS application {0}\n with ID {1}.", app_info.Name, app_id); return(new ApplicationInfo() { ID = app_id, Version = app_version }); }
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 BaseProgram(LUISAuthoringClient client, string authoringKey) : base("LUIS Authoring API Demo", true) { Client = client; AuthoringKey = authoringKey; AddPage(new MainPage(this)); AddPage(new Management.ListAppsPage(this)); AddPage(new Management.AppInfoPage(this)); AddPage(new Management.AppDetailsPage(this)); AddPage(new Management.AppVersionIntentsPage(this)); AddPage(new Management.AppVersionEntitiesPage(this)); AddPage(new Management.AppVersionPrebuiltEntitiesPage(this)); AddPage(new Management.AppTrainPage(this)); AddPage(new Management.AppDeletePage(this)); AddPage(new Management.AppClonePage(this)); AddPage(new Management.AppImportPage(this)); AddPage(new Management.AppExportPage(this)); AddPage(new Management.AppPublishPage(this)); AddPage(new Management.AppVersionSelector(this)); AddPage(new Management.AppVersionInfoPage(this)); AddPage(new Management.AppVersionDetailsPage(this)); AddPage(new CreateAppPage <GreetingApp.StartPage>(this)); AddPage(new GreetingApp.StartPage(this)); AddPage(new GreetingApp.AddUtterancePage(this)); AddPage(new CreateAppPage <RetailApp.StartPage>(this)); AddPage(new RetailApp.StartPage(this)); AddPage(new RetailApp.FlowerpotPage(this)); AddPage(new RetailApp.AddFlowersPage(this)); AddPage(new RetailApp.SendFlowersIntentPage(this)); AddPage(new CreateAppPage <BookingApp.StartPage>(this)); AddPage(new BookingApp.StartPage(this)); AddPage(new BookingApp.FlightsEntityPage(this)); AddPage(new BookingApp.FindFlightsIntentPage(this)); AddPage(new TemplateSelectorPage(this)); AddPage(new TrainAppPage(this)); AddPage(new PublishAppPage(this)); AddPage(new ShareAppPage(this)); SetPage <MainPage>(); }
static Guid CreateIntent(LUISAuthoringClient client, string resourceRegion, Guid appId, string versionId, string intent) { try { // create model for intent // custom headers is null var response = client.Model.AddIntentWithHttpMessagesAsync(appId, versionId, new ModelCreateObject(intent), null, CancellationToken.None).Result; // get intentId from `Location` header - trim away URL part var newIntentId = response.Response.Headers.Location.ToString(); newIntentId = newIntentId.Replace(String.Format("https://{0}.api.cognitive.microsoft.com/luis/api/v2.0/apps/{1}/versions/{2}/intents/", resourceRegion, appId, versionId), ""); return(new Guid(newIntentId)); } catch (Exception ex) { Console.WriteLine(ex.InnerException); throw ex; } }
static void Main(string[] args) { // authoring Key found in LUIS portal under user settings var cogServicesAllInOneKey = "<YOUR-AUTHORING-KEY>"; var credentials = new ApiKeyServiceClientCredentials(cogServicesAllInOneKey); // set parameters for app var resourceRegion = "westus"; var culture = "en-us"; var appName = "myEnglishApp"; var description = "app made with .Net SDK"; var versionId = "0.1"; // create client object var authoringClient = new LUISAuthoringClient(credentials, new System.Net.Http.DelegatingHandler[] { }); authoringClient.Endpoint = "https://westus.api.cognitive.microsoft.com/"; // create app var appId = CreateApp(authoringClient, resourceRegion, appName, versionId, culture, description); // create intent var intent = "FindForm"; var intentID = CreateIntent(authoringClient, resourceRegion, appId, versionId, intent); // create entity `HRF-number regular express var entityRegEx = "hrf-[0-9]{6}"; var entityName = "HRF-number"; var regularExpressEntity = new RegexModelCreateObject(entityRegEx, entityName); var entityId = CreateRegularExpressionEntity(authoringClient, resourceRegion, appId, versionId, regularExpressEntity); // add example utterance with 1 entity to intent var entity = "HRF-number"; var utterance = "When was hrf-123456 published?"; var taggedEntity = new EntityLabelObject(entity, 9, 18); var exampleUtteranceId = AddExampleUtterance(authoringClient, appId, versionId, intent, utterance, taggedEntity); }
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> }
async static Task AddEntities(LUISAuthoringClient client, Guid appId, string versionId) { // <AuthoringAddEntities> // Add Prebuilt entity await client.Model.AddPrebuiltAsync(appId, versionId, new[] { "number" }); // </AuthoringCreatePrebuiltEntity> // 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" }); // </AuthoringAddEntities> }
// </AuthoringBatchAddUtterancesForIntent> // <AuthoringTrainVersion> async static Task Train_App(LUISAuthoringClient client, ApplicationInfo app) { var response = await client.Train.TrainVersionAsync(app.ID, app.Version); Console.WriteLine("Training status: " + response.Status); }