Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thick clent feature #5

Merged
merged 24 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c586920
12767907: Add a package dependency on Microsoft.RL
johnhuang01 Dec 11, 2021
43967d3
Add RankProcessor
johnhuang01 Dec 24, 2021
1e400a8
Remove unused file
johnhuang01 Dec 24, 2021
8e1be98
Remove some key
johnhuang01 Dec 24, 2021
7ec50ec
Toggle commented codes so that most tests can pass
johnhuang01 Jan 7, 2022
0d83604
Getting the required config details for rankprocessor to enable livemode
Tparuchuri Jan 13, 2022
7bef96f
Updating the wrong variable name
Tparuchuri Jan 13, 2022
db8c651
Cleanup
Tparuchuri Jan 14, 2022
d6df6b5
Revert "12767907: Add a package dependency on Microsoft.RL"
Tparuchuri Jan 14, 2022
70c9738
Revert "Add RankProcessor"
Tparuchuri Jan 14, 2022
ebbbdad
Revert "Remove unused file"
Tparuchuri Jan 14, 2022
9856a35
Revert "Toggle commented codes so that most tests can pass"
Tparuchuri Jan 14, 2022
4255840
Delete DisposeHelper.cs
Tparuchuri Jan 14, 2022
86532d3
Revert "Revert "12767907: Add a package dependency on Microsoft.RL""
Tparuchuri Jan 14, 2022
8156ddb
Merge branch 'ClientConfiguration' of https://github.com/johnhuang01/…
Tparuchuri Jan 14, 2022
c37c4d3
Cleanup after reverting
Tparuchuri Jan 14, 2022
6b75695
generating client configuration using autorest
Tparuchuri Jan 18, 2022
1f0a161
Revert "generating client configuration using autorest"
Tparuchuri Jan 20, 2022
59e364e
Configuration details for livemodel
Tparuchuri Jan 20, 2022
92f6ba3
cleanup
Tparuchuri Jan 20, 2022
2c7e79c
cleanup
Tparuchuri Jan 20, 2022
23d1c93
Added ToDo comments
Tparuchuri Jan 20, 2022
a914445
correct the version in endpoints
Tparuchuri Jan 21, 2022
355227d
Merge pull request #4 from johnhuang01/ClientConfiguration
Tparuchuri Jan 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Used for azure-sdk-tools repo until issue https://github.com/Azure/azure-sdk-tools/issues/1329 is addressed
-->
<add key="azure-sdk-tools" value="https://azuresdkartifacts.blob.core.windows.net/azure-sdk-tools/index.json" />
<add key="air-msrai-decisionservice-Consumption" value="https://msazure.pkgs.visualstudio.com/one/_packaging/air-msrai-decisionservice-Consumption/nuget/v3/index.json" />
</packageSources>
<disabledPackageSources>
<clear />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

<ItemGroup>
<PackageReference Include="Azure.Core" />
<PackageReference Include="Microsoft.RL" VersionOverride="1.0.18120003-INTERNAL" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Core.Pipeline;
using Rl.Net;

namespace Azure.AI.Personalizer
{
Expand All @@ -17,10 +21,17 @@ public class PersonalizerClient
private readonly ClientDiagnostics _clientDiagnostics;
private readonly HttpPipeline _pipeline;
private readonly bool _isLocalInference;
private string stringEndpoint;
private string apiKey;

internal RankRestClient RankRestClient { get; set; }
internal EventsRestClient EventsRestClient { get; set; }
internal MultiSlotRestClient MultiSlotRestClient { get; set; }
internal MultiSlotEventsRestClient MultiSlotEventsRestClient { get; set; }
internal ServiceConfigurationRestClient ServiceConfigurationRestClient { get; set; }
internal PolicyRestClient PolicyRestClient { get; set; }
internal PersonalizerServiceProperties _personalizerServiceProperties { get; set; }
internal PersonalizerPolicy _personalizerPolicy { get; set; }

/// <summary> Initializes a new instance of Personalizer Client for mocking. </summary>
protected PersonalizerClient()
Expand All @@ -46,11 +57,13 @@ public PersonalizerClient(Uri endpoint, TokenCredential credential, Personalizer
_clientDiagnostics = new ClientDiagnostics(options);
string[] scopes = { "https://cognitiveservices.azure.com/.default" };
_pipeline = HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(credential, scopes));
string stringEndpoint = endpoint.AbsoluteUri;
stringEndpoint = endpoint.AbsoluteUri;
RankRestClient = new RankRestClient(_clientDiagnostics, _pipeline, stringEndpoint);
EventsRestClient = new EventsRestClient(_clientDiagnostics, _pipeline, stringEndpoint);
MultiSlotRestClient = new MultiSlotRestClient(_clientDiagnostics, _pipeline, stringEndpoint);
MultiSlotEventsRestClient = new MultiSlotEventsRestClient(_clientDiagnostics, _pipeline, stringEndpoint);
ServiceConfigurationRestClient = new ServiceConfigurationRestClient(_clientDiagnostics, _pipeline, stringEndpoint);
PolicyRestClient = new PolicyRestClient(_clientDiagnostics, _pipeline, stringEndpoint);
}

/// <summary> Initializes a new instance of PersonalizerClient. </summary>
Expand All @@ -62,12 +75,18 @@ public PersonalizerClient(Uri endpoint, TokenCredential credential, bool isLocal
this(endpoint, credential, options)
{
_isLocalInference = isLocalInference;
if (isLocalInference)
{
//Intialize liveModel and call Rank processor
//ToDo:TASK 13057958: Working on changes to support token authentication in RLClient
//Configuration config = GetConfigurationForLiveModel("Token", "token");
}
}

/// <summary> Initializes a new instance of PersonalizerClient. </summary>
/// <param name="endpoint"> Supported Cognitive Services endpoint. </param>
/// <param name="credential"> A credential used to authenticate to an Azure Service. </param>
public PersonalizerClient(Uri endpoint, TokenCredential credential) : this(endpoint, credential, null){ }
public PersonalizerClient(Uri endpoint, TokenCredential credential) : this(endpoint, credential, null) { }

/// <summary> Initializes a new instance of PersonalizerClient. </summary>
/// <param name="endpoint"> Supported Cognitive Services endpoint. </param>
Expand All @@ -83,15 +102,17 @@ public PersonalizerClient(Uri endpoint, AzureKeyCredential credential, Personali
{
throw new ArgumentNullException(nameof(credential));
}

apiKey = credential.Key;
options ??= new PersonalizerClientOptions();
_clientDiagnostics = new ClientDiagnostics(options);
_pipeline = HttpPipelineBuilder.Build(options, new AzureKeyCredentialPolicy(credential, "Ocp-Apim-Subscription-Key"));
string stringEndpoint = endpoint.AbsoluteUri;
stringEndpoint = endpoint.AbsoluteUri;
RankRestClient = new RankRestClient(_clientDiagnostics, _pipeline, stringEndpoint);
EventsRestClient = new EventsRestClient(_clientDiagnostics, _pipeline, stringEndpoint);
MultiSlotRestClient = new MultiSlotRestClient(_clientDiagnostics, _pipeline, stringEndpoint);
MultiSlotEventsRestClient = new MultiSlotEventsRestClient(_clientDiagnostics, _pipeline, stringEndpoint);
ServiceConfigurationRestClient = new ServiceConfigurationRestClient(_clientDiagnostics, _pipeline, stringEndpoint);
PolicyRestClient = new PolicyRestClient(_clientDiagnostics, _pipeline, stringEndpoint);
}

/// <summary> Initializes a new instance of PersonalizerClient. </summary>
Expand All @@ -103,12 +124,17 @@ public PersonalizerClient(Uri endpoint, AzureKeyCredential credential, bool isLo
this(endpoint, credential, options)
{
_isLocalInference = isLocalInference;
if (isLocalInference)
{
//Intialize liveModel and Rankprocessor
Configuration config = GetConfigurationForLiveModel("apiKey", apiKey);
}
}

/// <summary> Initializes a new instance of PersonalizerClient. </summary>
/// <param name="endpoint"> Supported Cognitive Services endpoint. </param>
/// <param name="credential"> A credential used to authenticate to an Azure Service. </param>
public PersonalizerClient(Uri endpoint, AzureKeyCredential credential): this(endpoint, credential, null) { }
public PersonalizerClient(Uri endpoint, AzureKeyCredential credential) : this(endpoint, credential, null) { }

/// <summary> Initializes a new instance of MultiSlotEventsClient. </summary>
/// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
Expand All @@ -134,7 +160,15 @@ public virtual async Task<Response<PersonalizerRankResult>> RankAsync(Personaliz
scope.Start();
try
{
return await RankRestClient.RankAsync(options, cancellationToken).ConfigureAwait(false);
if (_isLocalInference)
{
//return RankProcessor result here
return null;
}
else
{
return await RankRestClient.RankAsync(options, cancellationToken).ConfigureAwait(false);
}
}
catch (Exception e)
{
Expand Down Expand Up @@ -177,7 +211,15 @@ public virtual Response<PersonalizerRankResult> Rank(PersonalizerRankOptions opt
scope.Start();
try
{
return RankRestClient.Rank(options, cancellationToken);
if (_isLocalInference)
{
//return RankProcessor result here
return null;
}
else
{
return RankRestClient.Rank(options, cancellationToken);
}
}
catch (Exception e)
{
Expand Down Expand Up @@ -482,5 +524,33 @@ public virtual Response ActivateMultiSlot(string eventId, CancellationToken canc
throw;
}
}

/// <summary> Gets the configuration details for the live model to use </summary>
internal Configuration GetConfigurationForLiveModel(string authType, string authValue)
{
_personalizerServiceProperties = ServiceConfigurationRestClient.Get();
_personalizerPolicy = PolicyRestClient.Get();
Configuration config = new Configuration();
// set up the model
if (authType == "apiKey")
{
config["http.api.key"] = authValue;
}
else
{
//ToDo: TASK 13057958 Working on changes to support token authentication in RLClient
//config["http.token.key"] = authValue;
}
config["interaction.http.api.host"] = stringEndpoint+"personalizer/v1.1-preview.1/logs/interactions";
config["observation.http.api.host"] = stringEndpoint+"personalizer/v1.1-preview.1/logs/observations";
//ToDo: TASK 13057958 Working on changes to support model api in RL.Net
config["model.blob.uri"] = stringEndpoint + "personalizer/v1.1-preview.1/model";
config["vw.commandline"] = _personalizerPolicy.Arguments;
config["protocol.version"] = "2";
config["initial_exploration.epsilon"] = Convert.ToString(_personalizerServiceProperties.ExplorationPercentage, CultureInfo.InvariantCulture);
config["rank.learning.mode"] = Convert.ToString(_personalizerServiceProperties.LearningMode, CultureInfo.InvariantCulture);
//return the config model
return config;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ public abstract class PersonalizerTestBase : RecordedTestBase<PersonalizerTestEn
{
public static bool IsTestTenant = false;

public PersonalizerTestBase(bool isAsync): base(isAsync)
public PersonalizerTestBase(bool isAsync) : base(isAsync)
{
// TODO: Compare bodies again when https://github.com/Azure/azure-sdk-for-net/issues/22219 is resolved.
Matcher = new RecordMatcher(compareBodies: false);
Sanitizer = new PersonalizerRecordedTestSanitizer();
}

protected async Task<PersonalizerClient> GetPersonalizerClientAsync(bool isSingleSlot = false)
protected async Task<PersonalizerClient> GetPersonalizerClientAsync(bool isSingleSlot = false, bool isLocalInference = false)
{
string endpoint = isSingleSlot ? TestEnvironment.SingleSlotEndpoint : TestEnvironment.MultiSlotEndpoint;
string apiKey = isSingleSlot ? TestEnvironment.SingleSlotApiKey : TestEnvironment.MultiSlotApiKey;
Expand All @@ -29,7 +29,16 @@ protected async Task<PersonalizerClient> GetPersonalizerClientAsync(bool isSingl
}
var credential = new AzureKeyCredential(apiKey);
var options = InstrumentClientOptions(new PersonalizerClientOptions());
PersonalizerClient personalizerClient = new PersonalizerClient(new Uri(endpoint), credential, options);
PersonalizerClient personalizerClient = null;
if (isLocalInference)
{
personalizerClient = new PersonalizerClient(new Uri(endpoint), credential, true, options);
}
else
{
personalizerClient = new PersonalizerClient(new Uri(endpoint), credential, options);
}

personalizerClient = InstrumentClient(personalizerClient);
return personalizerClient;
}
Expand Down