diff --git a/NuGet.Config b/NuGet.Config
index be103949f661..7b6da4adea45 100644
--- a/NuGet.Config
+++ b/NuGet.Config
@@ -10,6 +10,7 @@
Used for azure-sdk-tools repo until issue https://github.com/Azure/azure-sdk-tools/issues/1329 is addressed
-->
+
diff --git a/sdk/personalizer/Azure.AI.Personalizer/src/Azure.AI.Personalizer.csproj b/sdk/personalizer/Azure.AI.Personalizer/src/Azure.AI.Personalizer.csproj
index 56be15a9d198..701ab2461555 100644
--- a/sdk/personalizer/Azure.AI.Personalizer/src/Azure.AI.Personalizer.csproj
+++ b/sdk/personalizer/Azure.AI.Personalizer/src/Azure.AI.Personalizer.csproj
@@ -32,6 +32,7 @@
+
diff --git a/sdk/personalizer/Azure.AI.Personalizer/src/Models/PersonalizerClient.cs b/sdk/personalizer/Azure.AI.Personalizer/src/Models/PersonalizerClient.cs
index f8f6c223eb18..f729f7305b83 100644
--- a/sdk/personalizer/Azure.AI.Personalizer/src/Models/PersonalizerClient.cs
+++ b/sdk/personalizer/Azure.AI.Personalizer/src/Models/PersonalizerClient.cs
@@ -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
{
@@ -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; }
/// Initializes a new instance of Personalizer Client for mocking.
protected PersonalizerClient()
@@ -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);
}
/// Initializes a new instance of PersonalizerClient.
@@ -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");
+ }
}
/// Initializes a new instance of PersonalizerClient.
/// Supported Cognitive Services endpoint.
/// A credential used to authenticate to an Azure Service.
- public PersonalizerClient(Uri endpoint, TokenCredential credential) : this(endpoint, credential, null){ }
+ public PersonalizerClient(Uri endpoint, TokenCredential credential) : this(endpoint, credential, null) { }
/// Initializes a new instance of PersonalizerClient.
/// Supported Cognitive Services endpoint.
@@ -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);
}
/// Initializes a new instance of PersonalizerClient.
@@ -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);
+ }
}
/// Initializes a new instance of PersonalizerClient.
/// Supported Cognitive Services endpoint.
/// A credential used to authenticate to an Azure Service.
- public PersonalizerClient(Uri endpoint, AzureKeyCredential credential): this(endpoint, credential, null) { }
+ public PersonalizerClient(Uri endpoint, AzureKeyCredential credential) : this(endpoint, credential, null) { }
/// Initializes a new instance of MultiSlotEventsClient.
/// The handler for diagnostic messaging in the client.
@@ -134,7 +160,15 @@ public virtual async Task> 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)
{
@@ -177,7 +211,15 @@ public virtual Response 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)
{
@@ -482,5 +524,33 @@ public virtual Response ActivateMultiSlot(string eventId, CancellationToken canc
throw;
}
}
+
+ /// Gets the configuration details for the live model to use
+ 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;
+ }
}
}
diff --git a/sdk/personalizer/Azure.AI.Personalizer/tests/Infrastructure/PersonalizerTestBase.cs b/sdk/personalizer/Azure.AI.Personalizer/tests/Infrastructure/PersonalizerTestBase.cs
index a27c34534ee9..d2604d28806f 100644
--- a/sdk/personalizer/Azure.AI.Personalizer/tests/Infrastructure/PersonalizerTestBase.cs
+++ b/sdk/personalizer/Azure.AI.Personalizer/tests/Infrastructure/PersonalizerTestBase.cs
@@ -11,14 +11,14 @@ public abstract class PersonalizerTestBase : RecordedTestBase GetPersonalizerClientAsync(bool isSingleSlot = false)
+ protected async Task GetPersonalizerClientAsync(bool isSingleSlot = false, bool isLocalInference = false)
{
string endpoint = isSingleSlot ? TestEnvironment.SingleSlotEndpoint : TestEnvironment.MultiSlotEndpoint;
string apiKey = isSingleSlot ? TestEnvironment.SingleSlotApiKey : TestEnvironment.MultiSlotApiKey;
@@ -29,7 +29,16 @@ protected async Task 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;
}