-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QnAMakerPreviewClient in QnAMaker SDK (#15960)
* 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
1 parent
3c52d27
commit e17944b
Showing
9 changed files
with
1,201 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
sdk/cognitiveservices/Knowledge.QnAMaker/src/Customizations/QnAMakerPreviewClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
sdk/cognitiveservices/Knowledge.QnAMaker/src/Customizations/QnAMakerPreviewRuntimeClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
sdk/cognitiveservices/Knowledge.QnAMaker/tests/QnAMakerKnowledgebasePreviewTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
sdk/cognitiveservices/Knowledge.QnAMaker/tests/QnAMakerPreviewRuntimeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.