Skip to content

Commit

Permalink
Merge branch 'master' into chrimc
Browse files Browse the repository at this point in the history
  • Loading branch information
chrimc62 authored Apr 21, 2018
2 parents 8e8eca1 + 1d53bb3 commit b228ba9
Show file tree
Hide file tree
Showing 52 changed files with 2,694 additions and 525 deletions.
3 changes: 1 addition & 2 deletions Microsoft.Bot.Builder.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.12
VisualStudioVersion = 15.0.27130.2027
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{4269F3C3-6B42-419B-B64A-3E6DC0F1574A}"
EndProject
Expand Down Expand Up @@ -406,7 +406,6 @@ Global
{2F77CA1D-E6F0-4DEA-96BB-8A039F4D0FF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F77CA1D-E6F0-4DEA-96BB-8A039F4D0FF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F77CA1D-E6F0-4DEA-96BB-8A039F4D0FF8}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
{2F77CA1D-E6F0-4DEA-96BB-8A039F4D0FF8}.Documentation|Any CPU.Build.0 = Debug|Any CPU
{2F77CA1D-E6F0-4DEA-96BB-8A039F4D0FF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F77CA1D-E6F0-4DEA-96BB-8A039F4D0FF8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,60 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version Condition=" '$(BUILD_BUILDNUMBER)' == '' ">4.0.0-local</Version>
<Version Condition=" '$(BUILD_BUILDNUMBER)' != '' ">$(BUILD_BUILDNUMBER)</Version>
<PackageVersion Condition=" '$(PackageVersion)' == '' ">4.0.0-local</PackageVersion>
<PackageVersion Condition=" '$(PackageVersion)' != '' ">$(PackageVersion)</PackageVersion>
<Configurations>Debug;Release;Documentation;Debug - NuGet Packages;</Configurations>
</PropertyGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version Condition=" '$(BUILD_BUILDNUMBER)' == '' ">4.0.0-local</Version>
<Version Condition=" '$(BUILD_BUILDNUMBER)' != '' ">$(BUILD_BUILDNUMBER)</Version>
<PackageVersion Condition=" '$(PackageVersion)' == '' ">4.0.0-local</PackageVersion>
<PackageVersion Condition=" '$(PackageVersion)' != '' ">$(PackageVersion)</PackageVersion>
<Configurations>Debug;Release;Documentation;Debug - NuGet Packages;</Configurations>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<SignAssembly>true</SignAssembly>
<DelaySign>true</DelaySign>
<AssemblyOriginatorKeyFile>..\..\build\35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<SignAssembly>true</SignAssembly>
<DelaySign>true</DelaySign>
<AssemblyOriginatorKeyFile>..\..\build\35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>Microsoft.Bot.Builder.Ai.LUIS</PackageId>
<Description>LUIS Middleware and Recognizers for the Microsoft Bot Builder SDK</Description>
<Summary>This library implements C# classes for building bots using LUIS.</Summary>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>Microsoft.Bot.Builder.Ai.LUIS</PackageId>
<Description>LUIS Middleware and Recognizers for the Microsoft Bot Builder SDK</Description>
<Summary>This library implements C# classes for building bots using LUIS.</Summary>
</PropertyGroup>

<PropertyGroup>
<Company>Microsoft</Company>
<Authors>microsoft,BotFramework,nugetbotbuilder</Authors>
<Product>Microsoft Bot Builder SDK</Product>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageProjectUrl>https://github.com/Microsoft/botbuilder-dotnet</PackageProjectUrl>
<PackageIconUrl>http://docs.botframework.com/images/bot_icon.png</PackageIconUrl>
<PackageLicenseUrl>https://github.com/Microsoft/BotBuilder/blob/master/LICENSE</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RepositoryUrl>https://github.com/Microsoft/botbuilder-dotnet</RepositoryUrl>
<LicenseUrl>https://github.com/Microsoft/BotBuilder-dotnet/blob/master/LICENSE</LicenseUrl>
<RepositoryType />
<PackageTags>bots;ai;botframework;botbuilder;luis</PackageTags>
<NeutralLanguage />
</PropertyGroup>
<PropertyGroup>
<Company>Microsoft</Company>
<Authors>microsoft,BotFramework,nugetbotbuilder</Authors>
<Product>Microsoft Bot Builder SDK</Product>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageProjectUrl>https://github.com/Microsoft/botbuilder-dotnet</PackageProjectUrl>
<PackageIconUrl>http://docs.botframework.com/images/bot_icon.png</PackageIconUrl>
<PackageLicenseUrl>https://github.com/Microsoft/BotBuilder/blob/master/LICENSE</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RepositoryUrl>https://github.com/Microsoft/botbuilder-dotnet</RepositoryUrl>
<LicenseUrl>https://github.com/Microsoft/BotBuilder-dotnet/blob/master/LICENSE</LicenseUrl>
<RepositoryType />
<PackageTags>bots;ai;botframework;botbuilder;luis</PackageTags>
<NeutralLanguage />
</PropertyGroup>

<PropertyGroup Condition="$(Configuration) == 'Debug - NuGet Packages'">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup Condition="$(Configuration) == 'Debug - NuGet Packages'">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Documentation|AnyCPU'">
<DocumentationFile>bin\Documentation\netstandard2.0\Microsoft.Bot.Builder.Ai.LUIS.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Documentation|AnyCPU'">
<DocumentationFile>bin\$(Configuration)\netstandard2.0\Microsoft.Bot.Builder.Ai.LUIS.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Bot.Builder.Core" Condition=" '$(PackageVersion)' == '' " Version="4.0.0-local" />
<PackageReference Include="Microsoft.Bot.Builder.Core" Condition=" '$(PackageVersion)' != '' " Version="$(PackageVersion)" />
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.10" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\$(Configuration)\netstandard2.0\Microsoft.Bot.Builder.Ai.LUIS.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Bot.Builder.Core" Condition=" '$(PackageVersion)' == '' " Version="4.0.0-local" />
<PackageReference Include="Microsoft.Bot.Builder.Core" Condition=" '$(PackageVersion)' != '' " Version="$(PackageVersion)" />
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.10" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.Bot.Builder.Core.Extensions\Microsoft.Bot.Builder.Core.Extensions.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,62 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version Condition=" '$(BUILD_BUILDNUMBER)' == '' ">4.0.0-local</Version>
<Version Condition=" '$(BUILD_BUILDNUMBER)' != '' ">$(BUILD_BUILDNUMBER)</Version>
<PackageVersion Condition=" '$(PackageVersion)' == '' ">4.0.0-local</PackageVersion>
<PackageVersion Condition=" '$(PackageVersion)' != '' ">$(PackageVersion)</PackageVersion>
<Configurations>Debug;Release;Documentation;Debug - NuGet Packages;</Configurations>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<SignAssembly>true</SignAssembly>
<DelaySign>true</DelaySign>
<AssemblyOriginatorKeyFile>..\..\build\35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>Microsoft.Bot.Builder.Ai.QnA</PackageId>
<Description>Classes for using QnA Maker Cognitive Service on the Microsoft Bot Builder SDK</Description>
<Summary>This library implements C# classes for building bots using Microsoft Cognitive services.</Summary>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<PropertyGroup>
<Company>Microsoft</Company>
<Authors>microsoft,BotFramework,nugetbotbuilder</Authors>
<Product>Microsoft Bot Builder SDK</Product>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageProjectUrl>https://github.com/Microsoft/botbuilder-dotnet</PackageProjectUrl>
<PackageIconUrl>http://docs.botframework.com/images/bot_icon.png</PackageIconUrl>
<PackageLicenseUrl>https://github.com/Microsoft/BotBuilder/blob/master/LICENSE</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RepositoryUrl>https://github.com/Microsoft/botbuilder-dotnet</RepositoryUrl>
<LicenseUrl>https://github.com/Microsoft/BotBuilder-dotnet/blob/master/LICENSE</LicenseUrl>
<RepositoryType />
<PackageTags>bots;ai;botframework;botbuilder</PackageTags>
<NeutralLanguage />
</PropertyGroup>

<PropertyGroup Condition="$(Configuration) == 'Debug - NuGet Packages'">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Documentation|AnyCPU'">
<DocumentationFile>bin\Documentation\netstandard2.0\Microsoft.Bot.Builder.Ai.QnA.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Bot.Builder" Condition=" '$(PackageVersion)' == '' " Version="4.0.0-local" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.Bot.Builder.Core.Extensions\Microsoft.Bot.Builder.Core.Extensions.csproj" />
<ProjectReference Include="..\Microsoft.Bot.Builder.Core\Microsoft.Bot.Builder.Core.csproj" />
<ProjectReference Include="..\Microsoft.Bot.Builder\Microsoft.Bot.Builder.csproj" />
<ProjectReference Include="..\Microsoft.Bot.Schema\Microsoft.Bot.Schema.csproj" />
</ItemGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version Condition=" '$(BUILD_BUILDNUMBER)' == '' ">4.0.0-local</Version>
<Version Condition=" '$(BUILD_BUILDNUMBER)' != '' ">$(BUILD_BUILDNUMBER)</Version>
<PackageVersion Condition=" '$(PackageVersion)' == '' ">4.0.0-local</PackageVersion>
<PackageVersion Condition=" '$(PackageVersion)' != '' ">$(PackageVersion)</PackageVersion>
<Configurations>Debug;Release;Documentation;Debug - NuGet Packages;</Configurations>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<SignAssembly>true</SignAssembly>
<DelaySign>true</DelaySign>
<AssemblyOriginatorKeyFile>..\..\build\35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>Microsoft.Bot.Builder.Ai.QnA</PackageId>
<Description>Classes for using QnA Maker Cognitive Service on the Microsoft Bot Builder SDK</Description>
<Summary>This library implements C# classes for building bots using Microsoft Cognitive services.</Summary>
</PropertyGroup>

<PropertyGroup>
<Company>Microsoft</Company>
<Authors>microsoft,BotFramework,nugetbotbuilder</Authors>
<Product>Microsoft Bot Builder SDK</Product>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageProjectUrl>https://github.com/Microsoft/botbuilder-dotnet</PackageProjectUrl>
<PackageIconUrl>http://docs.botframework.com/images/bot_icon.png</PackageIconUrl>
<PackageLicenseUrl>https://github.com/Microsoft/BotBuilder/blob/master/LICENSE</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RepositoryUrl>https://github.com/Microsoft/botbuilder-dotnet</RepositoryUrl>
<LicenseUrl>https://github.com/Microsoft/BotBuilder-dotnet/blob/master/LICENSE</LicenseUrl>
<RepositoryType />
<PackageTags>bots;ai;botframework;botbuilder</PackageTags>
<NeutralLanguage />
</PropertyGroup>

<PropertyGroup Condition="$(Configuration) == 'Debug - NuGet Packages'">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Documentation|AnyCPU'">
<DocumentationFile>bin\$(Configuration)\netstandard2.0\Microsoft.Bot.Builder.Ai.QnA.xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\$(Configuration)\netstandard2.0\Microsoft.Bot.Builder.Ai.QnA.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Bot.Builder" Condition=" '$(PackageVersion)' == '' " Version="4.0.0-local" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.Bot.Builder.Core.Extensions\Microsoft.Bot.Builder.Core.Extensions.csproj" />
<ProjectReference Include="..\Microsoft.Bot.Builder.Core\Microsoft.Bot.Builder.Core.csproj" />
<ProjectReference Include="..\Microsoft.Bot.Builder\Microsoft.Bot.Builder.csproj" />
<ProjectReference Include="..\Microsoft.Bot.Schema\Microsoft.Bot.Schema.csproj" />
</ItemGroup>
</Project>
66 changes: 66 additions & 0 deletions libraries/Microsoft.Bot.Builder.Ai.QnA/QnAMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,37 @@

namespace Microsoft.Bot.Builder.Ai.QnA
{
/// <summary>
/// Provides access to a QnA Maker knowledge base.
/// </summary>
public class QnAMaker
{
/// <summary>
/// The base service endpoint for QnA Maker.
/// </summary>
public const string qnaMakerServiceEndpoint = "https://westus.api.cognitive.microsoft.com/qnamaker/v3.0/knowledgebases/";

/// <summary>
/// The title for the HTTP header for the QnA Maker subscription key.
/// </summary>
public const string APIManagementHeader = "Ocp-Apim-Subscription-Key";

/// <summary>
/// The request content type.
/// </summary>
public const string JsonMimeType = "application/json";

private static HttpClient g_httpClient = new HttpClient();
private readonly HttpClient _httpClient;
private readonly QnAMakerOptions _options;
private readonly string _answerUrl;

/// <summary>
/// Creates a new <see cref="QnAMaker"/> instance.
/// </summary>
/// <param name="options">The options for the QnA Maker knowledge base.</param>
/// <param name="httpClient">A client with which to talk to QnAMaker.
/// If null, a default client is used for this instance.</param>
public QnAMaker(QnAMakerOptions options, HttpClient httpClient = null)
{
_httpClient = httpClient ?? g_httpClient;
Expand Down Expand Up @@ -52,6 +72,11 @@ public QnAMaker(QnAMakerOptions options, HttpClient httpClient = null)
}
}

/// <summary>
/// Generates an answer from the knowledge base.
/// </summary>
/// <param name="question">The user question to be queried against your knowledge base.</param>
/// <returns>A list of answers for the user query, sorted in decreasing order of ranking score.</returns>
public async Task<QueryResult[]> GetAnswers(string question)
{
var request = new HttpRequestMessage(HttpMethod.Post, _answerUrl);
Expand Down Expand Up @@ -83,12 +108,33 @@ public async Task<QueryResult[]> GetAnswers(string question)
}
}

/// <summary>
/// Defines options for the QnA Maker knowledge base.
/// </summary>
public class QnAMakerOptions
{
/// <summary>
/// The subscription key for the knowledge base.
/// </summary>
public string SubscriptionKey { get; set; }

/// <summary>
/// The knowledge base ID.
/// </summary>
public string KnowledgeBaseId { get; set; }

/// <summary>
/// The minimum score threshold, used to filter returned results.
/// </summary>
/// <remarks>Scores are normalized to the range of 0.0 to 1.0
/// before filtering.</remarks>
public float ScoreThreshold { get; set; }

/// <summary>
/// The number of ranked results you want in the output.
/// </summary>
public int Top { get; set; }

public Metadata[] StrictFilters { get; set; }
public Metadata[] MetadataBoost { get; set; }
}
Expand All @@ -103,14 +149,27 @@ public class Metadata
public string Value { get; set; }
}

/// <summary>
/// Represents an individual result from a knowledge base query.
/// </summary>
public class QueryResult
{
/// <summary>
/// The list of questions indexed in the QnA Service for the given answer.
/// </summary>
[JsonProperty("questions")]
public string[] Questions { get; set; }

/// <summary>
/// The answer text.
/// </summary>
[JsonProperty("answer")]
public string Answer { get; set; }

/// <summary>
/// The answer's score, from 0.0 (least confidence) to
/// 1.0 (greatest confidence).
/// </summary>
[JsonProperty("score")]
public float Score { get; set; }

Expand All @@ -124,8 +183,15 @@ public class QueryResult
public int QnaId { get; set; }
}

/// <summary>
/// Contains answers for a user query.
/// </summary>
public class QueryResults
{
/// <summary>
/// The answers for a user query,
/// sorted in decreasing order of ranking score.
/// </summary>
[JsonProperty("answers")]
public QueryResult[] Answers { get; set; }
}
Expand Down
Loading

0 comments on commit b228ba9

Please sign in to comment.