Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
updated va to sdk 4.4 (#1214)
Browse files Browse the repository at this point in the history
  • Loading branch information
lauren-mills committed May 1, 2019
1 parent 9b157f9 commit edfad69
Show file tree
Hide file tree
Showing 18 changed files with 314 additions and 275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Builder.Solutions;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Builder.Solutions.Testing;
using Microsoft.Bot.Builder.Skills;
using Microsoft.Bot.Builder.AI.QnA;
using Microsoft.Bot.Builder.AI.Luis;

namespace VirtualAssistantSample.Tests
{
Expand All @@ -32,7 +33,7 @@ public virtual void Initialize()
{ "en", new CognitiveModelSet
{
DispatchService = DispatchTestUtil.CreateRecognizer(),
LuisServices = new Dictionary<string, IRecognizer>
LuisServices = new Dictionary<string, ITelemetryRecognizer>
{
{ "general", GeneralTestUtil.CreateRecognizer() }
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Builder.AI.Luis;

namespace VirtualAssistantSample.Tests.Mocks
{
public class MockLuisRecognizer : ITelemetryLuisRecognizer
public class MockLuisRecognizer : ITelemetryRecognizer
{
public MockLuisRecognizer(IRecognizerConvert defaultIntent)
{
Expand All @@ -20,7 +20,9 @@ public MockLuisRecognizer(IRecognizerConvert defaultIntent)

private IRecognizerConvert DefaultIntent { get; set; }

public bool LogPersonalInformation => throw new NotImplementedException();
public bool LogPersonalInformation { get; set; } = false;

public IBotTelemetryClient TelemetryClient { get; set; } = new NullBotTelemetryClient();

public void RegisterUtterances(Dictionary<string, IRecognizerConvert> utterances)
{
Expand Down Expand Up @@ -52,5 +54,15 @@ public Task<T> RecognizeAsync<T>(ITurnContext turnContext, CancellationToken can
var mockResult = TestUtterances.GetValueOrDefault(text, DefaultIntent);
return Task.FromResult((T)mockResult);
}

public Task<RecognizerResult> RecognizeAsync(ITurnContext turnContext, Dictionary<string, string> telemetryProperties, Dictionary<string, double> telemetryMetrics, CancellationToken cancellationToken = default(CancellationToken))
{
throw new NotImplementedException();
}

public Task<T> RecognizeAsync<T>(ITurnContext turnContext, Dictionary<string, string> telemetryProperties, Dictionary<string, double> telemetryMetrics, CancellationToken cancellationToken = default(CancellationToken)) where T : IRecognizerConvert, new()
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.AI.QnA;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
Expand All @@ -19,7 +18,9 @@ public MockQnAMaker(QueryResult[] defaultAnswer)

private QueryResult[] DefaultAnswer { get; set; }

public bool LogPersonalInformation => throw new NotImplementedException();
public bool LogPersonalInformation { get; set; } = false;

public IBotTelemetryClient TelemetryClient { get; set; } = new NullBotTelemetryClient();

public void RegisterAnswers(Dictionary<string, QueryResult[]> utterances)
{
Expand All @@ -36,5 +37,13 @@ public Task<QueryResult[]> GetAnswersAsync(ITurnContext context, QnAMakerOptions
var mockResult = TestAnswers.GetValueOrDefault(text, DefaultAnswer);
return Task.FromResult(mockResult);
}

public Task<QueryResult[]> GetAnswersAsync(ITurnContext turnContext, QnAMakerOptions options, Dictionary<string, string> telemetryProperties, Dictionary<string, double> telemetryMetrics = null)
{
var text = turnContext.Activity.Text;

var mockResult = TestAnswers.GetValueOrDefault(text, DefaultAnswer);
return Task.FromResult(mockResult);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace VirtualAssistantSample.Tests.Utilities
{
public class GeneralTestUtil
{
private static Dictionary<string, IRecognizerConvert> _utterances = new Dictionary<string, IRecognizerConvert>
private static readonly Dictionary<string, IRecognizerConvert> _utterances = new Dictionary<string, IRecognizerConvert>
{
{ GeneralUtterances.Cancel, CreateIntent(GeneralUtterances.Cancel, GeneralLuis.Intent.Cancel) },
{ GeneralUtterances.Escalate, CreateIntent(GeneralUtterances.Escalate, GeneralLuis.Intent.Escalate) },
Expand All @@ -25,7 +25,7 @@ public class GeneralTestUtil
{ GeneralUtterances.Stop, CreateIntent(GeneralUtterances.Stop, GeneralLuis.Intent.Stop) },
};

public static IRecognizer CreateRecognizer()
public static MockLuisRecognizer CreateRecognizer()
{
var recognizer = new MockLuisRecognizer(defaultIntent: CreateIntent(string.Empty, GeneralLuis.Intent.None));
recognizer.RegisterUtterances(_utterances);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.2" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.4.0-RC4" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.Solutions.Middleware;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;
using VirtualAssistantSample.Responses.Main;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using Microsoft.Bot.Builder.Solutions.Dialogs;
using Microsoft.Bot.Schema;
using Newtonsoft.Json.Linq;
using VirtualAssistantSample.Models;
using VirtualAssistantSample.Responses.Cancel;
using VirtualAssistantSample.Responses.Main;
using VirtualAssistantSample.Services;
Expand Down Expand Up @@ -129,7 +128,7 @@ public MainDialog(
}
else
{
var answers = await qnaService.GetAnswersAsync(dc.Context);
var answers = await qnaService.GetAnswersAsync(dc.Context, null, null);

if (answers != null && answers.Count() > 0)
{
Expand All @@ -151,7 +150,7 @@ public MainDialog(
}
else
{
var answers = await qnaService.GetAnswersAsync(dc.Context);
var answers = await qnaService.GetAnswersAsync(dc.Context, null, null);

if (answers != null && answers.Count() > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.Bot.Builder.AI.Luis;
using Microsoft.Bot.Builder.AI.QnA;
using Microsoft.Bot.Builder.Solutions;
using Microsoft.Bot.Builder.Solutions.Telemetry;

namespace VirtualAssistantSample.Services
{
Expand All @@ -24,14 +23,14 @@ public BotServices(BotSettings settings)
var config = pair.Value;

var dispatchApp = new LuisApplication(config.DispatchModel.AppId, config.DispatchModel.SubscriptionKey, config.DispatchModel.GetEndpoint());
set.DispatchService = new TelemetryLuisRecognizer(dispatchApp);
set.DispatchService = new LuisRecognizer(dispatchApp);

if (config.LanguageModels != null)
{
foreach (var model in config.LanguageModels)
{
var luisApp = new LuisApplication(model.AppId, model.SubscriptionKey, model.GetEndpoint());
set.LuisServices.Add(model.Id, new TelemetryLuisRecognizer(luisApp));
set.LuisServices.Add(model.Id, new LuisRecognizer(luisApp));
}
}

Expand All @@ -43,7 +42,7 @@ public BotServices(BotSettings settings)
EndpointKey = kb.EndpointKey,
Host = kb.Hostname,
};
var qnaMaker = new TelemetryQnAMaker(qnaEndpoint);
var qnaMaker = new QnAMaker(qnaEndpoint);
set.QnAServices.Add(kb.Id, qnaMaker);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.2" />
<PackageReference Include="Microsoft.Azure.CognitiveServices.ContentModerator" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.CognitiveServices.Language" Version="1.0.1-preview" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.AI.Luis" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.AI.QnA" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.ApplicationInsights" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Azure" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.ApplicationInsights.Core" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Skills" Version="4.4.0-preview48" />
<PackageReference Include="Microsoft.Bot.Builder.Solutions" Version="4.4.0-preview48" />
<PackageReference Include="Microsoft.Bot.Builder.TemplateManager" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Configuration" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Connector" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Schema" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.4.0-RC4" />
<PackageReference Include="Microsoft.Bot.Builder.AI.Luis" Version="4.4.0-RC4" />
<PackageReference Include="Microsoft.Bot.Builder.AI.QnA" Version="4.4.0-RC4" />
<PackageReference Include="Microsoft.Bot.Builder.ApplicationInsights" Version="4.4.0-RC4" />
<PackageReference Include="Microsoft.Bot.Builder.Azure" Version="4.4.0-RC4" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.4.0-RC4" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.ApplicationInsights.Core" Version="4.4.0-RC4" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.4.0-RC4" />
<PackageReference Include="Microsoft.Bot.Builder.Skills" Version="4.4.0-preview49" />
<PackageReference Include="Microsoft.Bot.Builder.Solutions" Version="4.4.0-preview49" />
<PackageReference Include="Microsoft.Bot.Builder.TemplateManager" Version="4.4.0-RC4" />
<PackageReference Include="Microsoft.Bot.Configuration" Version="4.4.0-RC4" />
<PackageReference Include="Microsoft.Bot.Connector" Version="4.4.0-RC4" />
<PackageReference Include="Microsoft.Bot.Schema" Version="4.4.0-RC4" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using System.Collections.Generic;
using System.Threading;
using $safeprojectname$.Utilities;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Adapters;
using Microsoft.Bot.Builder.AI.QnA;
using Microsoft.Bot.Builder.AI.Luis;
using Microsoft.Bot.Builder.Skills;
using Microsoft.Bot.Builder.Solutions;
using Microsoft.Bot.Builder.Solutions.Testing;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using $safeprojectname$.Utilities;
using $ext_safeprojectname$.Services;
using $ext_safeprojectname$.Bots;
using $ext_safeprojectname$.Dialogs;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Builder.Solutions;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Builder.Solutions.Testing;
using Microsoft.Bot.Builder.Skills;

namespace $safeprojectname$
{
Expand All @@ -32,7 +33,7 @@ public virtual void Initialize()
{ "en", new CognitiveModelSet
{
DispatchService = DispatchTestUtil.CreateRecognizer(),
LuisServices = new Dictionary<string, IRecognizer>
LuisServices = new Dictionary<string, ITelemetryRecognizer>
{
{ "general", GeneralTestUtil.CreateRecognizer() }
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.AI.Luis;
using Microsoft.Bot.Builder.Dialogs;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Solutions.Telemetry;

namespace $safeprojectname$.Mocks
{
public class MockLuisRecognizer : ITelemetryLuisRecognizer
public class MockLuisRecognizer : ITelemetryRecognizer
{
public MockLuisRecognizer(IRecognizerConvert defaultIntent)
{
Expand All @@ -20,7 +20,9 @@ public MockLuisRecognizer(IRecognizerConvert defaultIntent)

private IRecognizerConvert DefaultIntent { get; set; }

public bool LogPersonalInformation => throw new NotImplementedException();
public bool LogPersonalInformation { get; set; } = false;

public IBotTelemetryClient TelemetryClient { get; set; } = new NullBotTelemetryClient();

public void RegisterUtterances(Dictionary<string, IRecognizerConvert> utterances)
{
Expand Down Expand Up @@ -52,5 +54,15 @@ public Task<T> RecognizeAsync<T>(ITurnContext turnContext, CancellationToken can
var mockResult = TestUtterances.GetValueOrDefault(text, DefaultIntent);
return Task.FromResult((T)mockResult);
}

public Task<RecognizerResult> RecognizeAsync(ITurnContext turnContext, Dictionary<string, string> telemetryProperties, Dictionary<string, double> telemetryMetrics, CancellationToken cancellationToken = default(CancellationToken))
{
throw new NotImplementedException();
}

public Task<T> RecognizeAsync<T>(ITurnContext turnContext, Dictionary<string, string> telemetryProperties, Dictionary<string, double> telemetryMetrics, CancellationToken cancellationToken = default(CancellationToken)) where T : IRecognizerConvert, new()
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.AI.QnA;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
Expand All @@ -19,7 +18,9 @@ public MockQnAMaker(QueryResult[] defaultAnswer)

private QueryResult[] DefaultAnswer { get; set; }

public bool LogPersonalInformation => throw new NotImplementedException();
public bool LogPersonalInformation { get; set; } = false;

public IBotTelemetryClient TelemetryClient { get; set; } = new NullBotTelemetryClient();

public void RegisterAnswers(Dictionary<string, QueryResult[]> utterances)
{
Expand All @@ -36,5 +37,13 @@ public Task<QueryResult[]> GetAnswersAsync(ITurnContext context, QnAMakerOptions
var mockResult = TestAnswers.GetValueOrDefault(text, DefaultAnswer);
return Task.FromResult(mockResult);
}

public Task<QueryResult[]> GetAnswersAsync(ITurnContext turnContext, QnAMakerOptions options, Dictionary<string, string> telemetryProperties, Dictionary<string, double> telemetryMetrics = null)
{
var text = turnContext.Activity.Text;

var mockResult = TestAnswers.GetValueOrDefault(text, DefaultAnswer);
return Task.FromResult(mockResult);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace $safeprojectname$.Utilities
{
public class GeneralTestUtil
{
private static Dictionary<string, IRecognizerConvert> _utterances = new Dictionary<string, IRecognizerConvert>
private static readonly Dictionary<string, IRecognizerConvert> _utterances = new Dictionary<string, IRecognizerConvert>
{
{ GeneralUtterances.Cancel, CreateIntent(GeneralUtterances.Cancel, GeneralLuis.Intent.Cancel) },
{ GeneralUtterances.Escalate, CreateIntent(GeneralUtterances.Escalate, GeneralLuis.Intent.Escalate) },
Expand All @@ -25,7 +25,7 @@ public class GeneralTestUtil
{ GeneralUtterances.Stop, CreateIntent(GeneralUtterances.Stop, GeneralLuis.Intent.Stop) },
};

public static IRecognizer CreateRecognizer()
public static MockLuisRecognizer CreateRecognizer()
{
var recognizer = new MockLuisRecognizer(defaultIntent: CreateIntent(string.Empty, GeneralLuis.Intent.None));
recognizer.RegisterUtterances(_utterances);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.2" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.4.0-RC4" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.Solutions.Middleware;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;
using $safeprojectname$.Responses.Main;
Expand Down
Loading

0 comments on commit edfad69

Please sign in to comment.