Skip to content

Commit

Permalink
QnAMakerPreviewClient in QnAMaker SDK (#15960)
Browse files Browse the repository at this point in the history
* BaseUri switch based on isPreview in QnAMakerClient

* Update QnAMakerPreviewClient.cs

* QnAMakerPreviewRuntimeClient in customization with v5-preview.1 version

* changelog to trigger SDK release

* added date inthe changelog

* Missed basetest changes

* place correct playback session record file
  • Loading branch information
sahithikkss-zz authored Oct 14, 2020
1 parent 3c52d27 commit e17944b
Show file tree
Hide file tree
Showing 9 changed files with 1,201 additions and 5 deletions.
5 changes: 2 additions & 3 deletions sdk/cognitiveservices/Knowledge.QnAMaker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
## 2.1.0-preview.1 (Unreleased)


## 2.1.0-preview.1 (2020-10-14)
SDK with custom clients for V5-preview.1 API
## 2.0.1 (2020-08-13)
For Minor Version release
## 2.0.0 (2020-07-16)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.Rest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker
{
public partial class QnAMakerClient
{
/// <summary>
/// Initializes a new instance of the QnAMakerClient class.
/// </summary>
/// <param name='credentials'>
/// Required. Subscription credentials which uniquely identify client subscription.
/// </param>
/// <param name="isPreview">
/// Optional. The flag used to change BaseUri if it is true.
/// </param>
/// <param name='rootHandler'>
/// Optional. The http client handler used to handle http transport.
/// </param>
/// <param name='handlers'>
/// Optional. The delegating handlers to add to the http client pipeline.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// Thrown when a required parameter is null
/// </exception>
public QnAMakerClient(ServiceClientCredentials credentials, bool isPreview = false, params DelegatingHandler[] handlers) : this(credentials, handlers)
{
if (isPreview)
{
BaseUri = "{Endpoint}/qnamaker/v5.0-preview.1";
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.Rest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker
{
public partial class QnAMakerRuntimeClient
{
/// <summary>
/// Initializes a new instance of the QnAMakerClient class.
/// </summary>
/// <param name='credentials'>
/// Required. Subscription credentials which uniquely identify client subscription.
/// </param>
/// <param name="isPreview">
/// Optional. The flag used to change BaseUri if it is true.
/// </param>
/// <param name='rootHandler'>
/// Optional. The http client handler used to handle http transport.
/// </param>
/// <param name='handlers'>
/// Optional. The delegating handlers to add to the http client pipeline.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// Thrown when a required parameter is null
/// </exception>
public QnAMakerRuntimeClient(ServiceClientCredentials credentials, bool isPreview = false, params DelegatingHandler[] handlers) : this(credentials, handlers)
{
if (isPreview)
{
BaseUri = "{RuntimeEndpoint}/qnamaker/v5.0-preview.1";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<Description>This client library provides access to the Microsoft Cognitive Services QnAMaker APIs.</Description>
<Version>2.1.0-preview.1</Version>
<ApiCompatVersion>2.0.1</ApiCompatVersion>
<PackageTags>Microsoft Cognitive Services;Cognitive Services;Cognitive Services SDK;REST HTTP client;QnAMaker;QnAMaker API;QnAMaker SDK;Vision;netcore451511</PackageTags>
<PackageTags>Microsoft Cognitive Services;Cognitive Services;Cognitive Services SDK;REST HTTP client;QnAMaker;QnAMaker API;QnAMaker SDK;QnAMakerV2;QnAMakerV5-preview.1;netcore451511</PackageTags>
<PackageReleaseNotes>
<![CDATA[
This is SDK for QnAMaker v4 API.
This is SDK for QnAMaker v4 API with custom clients for V5-preview.1.
]]>
</PackageReleaseNotes>
</PropertyGroup>
Expand Down
19 changes: 19 additions & 0 deletions sdk/cognitiveservices/Knowledge.QnAMaker/tests/BaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ protected IQnAMakerClient GetQnAMakerClient(DelegatingHandler handler)
return client;
}

protected IQnAMakerClient GetQnAMakerPreviewClient(DelegatingHandler handler)
{
IQnAMakerClient client = new QnAMakerClient(new ApiKeyServiceClientCredentials(QnAMakerSubscriptionKey), isPreview: true, handlers: handler)
{
Endpoint = "https://australiaeast.api.cognitive.microsoft.com"
};

return client;
}
protected IQnAMakerRuntimeClient GetQnAMakerRuntimeClient(DelegatingHandler handler)
{
IQnAMakerRuntimeClient client = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(QnAMakerEndpointKey), handlers: handler)
Expand All @@ -35,5 +44,15 @@ protected IQnAMakerRuntimeClient GetQnAMakerRuntimeClient(DelegatingHandler hand

return client;
}

protected IQnAMakerRuntimeClient GetQnAMakerPreviewRuntimeClient(DelegatingHandler handler)
{
IQnAMakerRuntimeClient client = new QnAMakerRuntimeClient(new ApiKeyServiceClientCredentials(QnAMakerSubscriptionKey), isPreview: true, handlers: handler)
{
RuntimeEndpoint = "https://australiaeast.api.cognitive.microsoft.com"

This comment has been minimized.

Copy link
@robch

robch Oct 16, 2020

Are previews supposed to be in a specific data center? Or all data centers? I don't recall, but I thought there was a specific data center they were all supposed to be available in... west us, central us, or somewhere... not sure... Maybe @ChrisHMSFT knows.

};

return client;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker;
using Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker.Models;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Xunit;

namespace QnAMaker.Tests
{
public class QnAMakerKnowledgebasePreviewTests: BaseTests
{
[Fact]
public void QnAMakerKnowledgebasePreviewCrud()
{
using (MockContext context = MockContext.Start(this.GetType()))
{
HttpMockServer.Initialize(this.GetType(), "QnAMakerKnowledgebasePreviewCrud");
IQnAMakerClient client = GetQnAMakerPreviewClient(HttpMockServer.CreateInstance());

// Create
var createOp = client.Knowledgebase.CreateAsync(new CreateKbDTO { Name = "testqna", QnaList = new List<QnADTO> { new QnADTO { Questions = new List<string> { "hi" }, Answer = "hello" } } }).Result;

// Loop while operation is success
createOp = OperationHelper.MonitorOperation(createOp, client);

Assert.Equal(createOp.OperationState, OperationStateType.Succeeded);

var kbid = createOp.ResourceLocation.Replace("/knowledgebases/", string.Empty);
Assert.NotEmpty(kbid);

var newKb = client.Knowledgebase.GetDetailsAsync(kbid).Result;

var kbdata = client.Knowledgebase.DownloadAsync(kbid, EnvironmentType.Test).Result;
Assert.Equal("hello", kbdata.QnaDocuments[0].Answer);

// Update
var updateOp = client.Knowledgebase.UpdateAsync(kbid, new UpdateKbOperationDTO { Add = new UpdateKbOperationDTOAdd { QnaList = new List<QnADTO> { new QnADTO { Questions = new List<string> { "bye" }, Answer = "goodbye" } } } }).Result;

// Loop while operation is success
updateOp = OperationHelper.MonitorOperation(updateOp, client);

Assert.Equal(updateOp.OperationState, OperationStateType.Succeeded);

kbdata = client.Knowledgebase.DownloadAsync(kbid, EnvironmentType.Test).Result;
Assert.Equal("goodbye", kbdata.QnaDocuments[1].Answer);

// Delete
client.Knowledgebase.DeleteAsync(kbid).Wait();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker;
using Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker.Models;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;

namespace QnAMaker.Tests
{
public class QnAMakerPreviewRuntimeTests : BaseTests
{
[Fact]
public void QnAMakerPreviewRuntimeGenerateAnswerTest()
{
using (MockContext context = MockContext.Start(this.GetType()))
{
HttpMockServer.Initialize(this.GetType(), "QnAMakerPreviewRuntimeGenerateAnswerTest");

var client = GetQnAMakerPreviewRuntimeClient(HttpMockServer.CreateInstance());
var queryDTO = new QueryDTO();
queryDTO.Question = "new question";
queryDTO.IsTest = true;
var answer = client.Runtime.GenerateAnswerAsync("192233e1-0ec8-44dc-8285-57a541b7c79c", queryDTO).Result;
Assert.Equal(1, answer.Answers.Count);
Assert.Equal(100, answer.Answers[0].Score);
}
}
}
}
Loading

0 comments on commit e17944b

Please sign in to comment.