Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public PersonalizerAdministrationClient(System.Uri endpoint, Azure.Core.TokenCre
public virtual System.Threading.Tasks.Task<Azure.Response> ResetPersonalizerModelAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.AI.Personalizer.PersonalizerPolicy> ResetPersonalizerPolicy(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Personalizer.PersonalizerPolicy>> ResetPersonalizerPolicyAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.AI.Personalizer.PersonalizerServiceProperties> UpdatePersonalizerConfiguration(Azure.AI.Personalizer.PersonalizerServiceProperties config, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Personalizer.PersonalizerServiceProperties>> UpdatePersonalizerConfigurationAsync(Azure.AI.Personalizer.PersonalizerServiceProperties config, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.AI.Personalizer.PersonalizerPolicy> UpdatePersonalizerPolicy(Azure.AI.Personalizer.PersonalizerPolicy policy, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Personalizer.PersonalizerPolicy>> UpdatePersonalizerPolicyAsync(Azure.AI.Personalizer.PersonalizerPolicy policy, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.AI.Personalizer.PersonalizerServiceProperties> UpdatePersonalizerProperties(Azure.AI.Personalizer.PersonalizerServiceProperties config, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Personalizer.PersonalizerServiceProperties>> UpdatePersonalizerPropertiesAsync(Azure.AI.Personalizer.PersonalizerServiceProperties config, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
public partial class PersonalizerClient
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ public virtual Response<PersonalizerLogProperties> GetPersonalizerLogProperties(
/// <summary> Update the Personalizer service configuration. </summary>
/// <param name="config"> The personalizer service configuration. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<PersonalizerServiceProperties >> UpdatePersonalizerConfigurationAsync(PersonalizerServiceProperties config, CancellationToken cancellationToken = default)
public virtual async Task<Response<PersonalizerServiceProperties >> UpdatePersonalizerPropertiesAsync(PersonalizerServiceProperties config, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("PersonalizerAdministrationClient.UpdatePersonalizerConfiguration");
using var scope = _clientDiagnostics.CreateScope("PersonalizerAdministrationClient.UpdatePersonalizerProperties");
scope.Start();
try
{
Expand All @@ -185,9 +185,9 @@ public virtual async Task<Response<PersonalizerServiceProperties >> UpdatePerson
/// <summary> Update the Personalizer service configuration. </summary>
/// <param name="config"> The personalizer service configuration. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<PersonalizerServiceProperties > UpdatePersonalizerConfiguration(PersonalizerServiceProperties config, CancellationToken cancellationToken = default)
public virtual Response<PersonalizerServiceProperties > UpdatePersonalizerProperties(PersonalizerServiceProperties config, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("PersonalizerAdministrationClient.UpdatePersonalizerConfiguration");
using var scope = _clientDiagnostics.CreateScope("PersonalizerAdministrationClient.UpdatePersonalizerProperties");
scope.Start();
try
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Text.Json;
using Azure.Core;

Expand All @@ -21,10 +22,10 @@ internal static PersonalizerLogProperties DeserializePersonalizerLogProperties(J
continue;
}
dateRange = PersonalizerLogPropertiesDateRange.DeserializePersonalizerLogPropertiesDateRange(property.Value);
continue;
return new PersonalizerLogProperties(dateRange.Value.From, dateRange.Value.To);
}
}
return new PersonalizerLogProperties(dateRange.Value.From, dateRange.Value.To);
return new PersonalizerLogProperties(DateTime.MinValue, DateTime.MinValue);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace Azure.AI.Personalizer.Tests
{
public class PersonalizerRecordedTestSanitizer: RecordedTestSanitizer
public class PersonalizerRecordedTestSanitizer : RecordedTestSanitizer
{
public PersonalizerRecordedTestSanitizer(): base()
public PersonalizerRecordedTestSanitizer() : base()
{
AddJsonPathSanitizer("$..accessToken");
AddJsonPathSanitizer("$..source");
Expand All @@ -30,7 +30,8 @@ public override string SanitizeVariable(string variableName, string environmentV
{
return variableName switch
{
PersonalizerTestEnvironment.ApiKeyEnvironmentVariableName => SanitizeValue,
PersonalizerTestEnvironment.MultiSlotApiKeyEnvironmentVariableName => SanitizeValue,
PersonalizerTestEnvironment.SingleSlotApiKeyEnvironmentVariableName => SanitizeValue,
_ => base.SanitizeVariable(variableName, environmentVariableValue)
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Threading.Tasks;
using Azure.Core.TestFramework;

namespace Azure.AI.Personalizer.Tests
Expand All @@ -12,25 +13,50 @@ public abstract class PersonalizerTestBase : RecordedTestBase<PersonalizerTestEn

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 PersonalizerClient GetPersonalizerClient()
protected async Task<PersonalizerClient> GetPersonalizerClientAsync(bool isSingleSlot = false)
{
var credential = new AzureKeyCredential(TestEnvironment.ApiKey);
string endpoint = isSingleSlot ? TestEnvironment.SingleSlotEndpoint : TestEnvironment.MultiSlotEndpoint;
string apiKey = isSingleSlot ? TestEnvironment.SingleSlotApiKey : TestEnvironment.MultiSlotApiKey;
PersonalizerAdministrationClient adminClient = GetAdministrationClient(isSingleSlot);
if (!isSingleSlot)
{
await EnableMultiSlot(adminClient);
}
var credential = new AzureKeyCredential(apiKey);
var options = InstrumentClientOptions(new PersonalizerClientOptions());
PersonalizerClient personalizerClient = new PersonalizerClient(new Uri(TestEnvironment.Endpoint), credential, options);
PersonalizerClient personalizerClient = new PersonalizerClient(new Uri(endpoint), credential, options);
personalizerClient = InstrumentClient(personalizerClient);
return personalizerClient;
}

protected PersonalizerAdministrationClient GetPersonalizerAdministrationClient()
protected PersonalizerAdministrationClient GetAdministrationClient(bool isSingleSlot = false)
{
var credential = new AzureKeyCredential(TestEnvironment.ApiKey);
string endpoint = isSingleSlot ? TestEnvironment.SingleSlotEndpoint : TestEnvironment.MultiSlotEndpoint;
string apiKey = isSingleSlot ? TestEnvironment.SingleSlotApiKey : TestEnvironment.MultiSlotApiKey;
var credential = new AzureKeyCredential(apiKey);
var options = InstrumentClientOptions(new PersonalizerClientOptions());
PersonalizerAdministrationClient PersonalizerAdministrationClient = new PersonalizerAdministrationClient(new Uri(TestEnvironment.Endpoint), credential, options);
PersonalizerAdministrationClient = InstrumentClient(PersonalizerAdministrationClient);
return PersonalizerAdministrationClient;
PersonalizerAdministrationClient personalizerAdministrationClient = new PersonalizerAdministrationClient(new Uri(endpoint), credential, options);
personalizerAdministrationClient = InstrumentClient(personalizerAdministrationClient);
return personalizerAdministrationClient;
}

private async Task EnableMultiSlot(PersonalizerAdministrationClient adminClient)
{
PersonalizerServiceProperties properties = await adminClient.GetPersonalizerPropertiesAsync();
if (properties.IsAutoOptimizationEnabled != false)
{
properties.IsAutoOptimizationEnabled = false;
await adminClient.UpdatePersonalizerPropertiesAsync(properties);
await Task.Delay(30000);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not ideal. It makes the playback test take a minute.

await adminClient.UpdatePersonalizerPolicyAsync(new PersonalizerPolicy("multiSlot", "--ccb_explore_adf --epsilon 0.2 --power_t 0 -l 0.001 --cb_type mtr -q ::"));
//sleep 30 seconds to allow settings to propagate
await Task.Delay(30000);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@ namespace Azure.AI.Personalizer.Tests
public class PersonalizerTestEnvironment: TestEnvironment
{
/// <summary>The name of the environment variable from which Personalizer resource's endpoint will be extracted for the live tests.</summary>
internal const string EndpointEnvironmentVariableName = "PERSONALIZER_ENDPOINT";
internal const string MultiSlotEndpointEnvironmentVariableName = "PERSONALIZER_ENDPOINT_MULTI_SLOT";

/// <summary>The name of the environment variable from which the Personalizer resource's API key will be extracted for the live tests.</summary>
internal const string ApiKeyEnvironmentVariableName = "PERSONALIZER_API_KEY";
internal const string MultiSlotApiKeyEnvironmentVariableName = "PERSONALIZER_API_KEY_MULTI_SLOT";

public string ApiKey => GetRecordedVariable(ApiKeyEnvironmentVariableName);
public string Endpoint => GetRecordedVariable(EndpointEnvironmentVariableName);
/// <summary>The name of the environment variable from which Personalizer resource's endpoint will be extracted for the live tests.</summary>
internal const string SingleSlotEndpointEnvironmentVariableName = "PERSONALIZER_ENDPOINT_SINGLE_SLOT";

/// <summary>The name of the environment variable from which the Personalizer resource's API key will be extracted for the live tests.</summary>
internal const string SingleSlotApiKeyEnvironmentVariableName = "PERSONALIZER_API_KEY_SINGLE_SLOT";

public string SingleSlotApiKey => GetRecordedVariable(SingleSlotApiKeyEnvironmentVariableName);
public string SingleSlotEndpoint => GetRecordedVariable(SingleSlotEndpointEnvironmentVariableName);

public string MultiSlotApiKey => GetRecordedVariable(MultiSlotApiKeyEnvironmentVariableName);
public string MultiSlotEndpoint => GetRecordedVariable(MultiSlotEndpointEnvironmentVariableName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,79 +14,71 @@ public ConfigurationsTests(bool isAsync): base(isAsync)
}

[Test]
public async Task GetServiceConfiguration()
public async Task ConfigurationTests()
{
PersonalizerAdministrationClient client = GetPersonalizerAdministrationClient();
PersonalizerServiceProperties defaultConfig = await client.GetPersonalizerPropertiesAsync();
Assert.AreEqual(TimeSpan.FromMinutes(1), defaultConfig.RewardWaitTime);
Assert.AreEqual(TimeSpan.FromHours(1), defaultConfig.ModelExportFrequency);
Assert.AreEqual(1, defaultConfig.DefaultReward);
Assert.AreEqual(0.2, defaultConfig.ExplorationPercentage, 0.00000001);
Assert.AreEqual(0, defaultConfig.LogRetentionDays);
}

[Test]
public async Task ApplyFromEvaluation()
{
PersonalizerAdministrationClient client = GetPersonalizerAdministrationClient();
PersonalizerPolicyReferenceOptions policyReferenceContract = new PersonalizerPolicyReferenceOptions("628a6299-ce45-4a9d-98a6-017c2c9ff008", "Inter-len1");
await client.ApplyPersonalizerEvaluationAsync(policyReferenceContract);
}

[Test]
public async Task UpdateServiceConfiguration()
{
PersonalizerAdministrationClient client = GetPersonalizerAdministrationClient();
TimeSpan newExperimentalUnitDuration = TimeSpan.FromMinutes(1);
TimeSpan modelExportFrequency = TimeSpan.FromHours(1);
TimeSpan newExperimentalUnitDuration = TimeSpan.FromSeconds(7);
TimeSpan modelExportFrequency = TimeSpan.FromMinutes(3);
double newDefaultReward = 1.0;
string newRewardFuntion = "average";
double newExplorationPercentage = 0.2f;
var config = new PersonalizerServiceProperties (
float newExplorationPercentage = 0.2f;
var properties = new PersonalizerServiceProperties(
rewardAggregation: newRewardFuntion,
modelExportFrequency: modelExportFrequency,
defaultReward: (float)newDefaultReward,
rewardWaitTime: newExperimentalUnitDuration,
explorationPercentage: (float)newExplorationPercentage,
explorationPercentage: newExplorationPercentage,
logRetentionDays: int.MaxValue
);
PersonalizerServiceProperties result = await client.UpdatePersonalizerConfigurationAsync(config);
Assert.AreEqual(config.DefaultReward, result.DefaultReward);
Assert.True(Math.Abs(config.ExplorationPercentage - result.ExplorationPercentage) < 1e-3);
Assert.AreEqual(config.ModelExportFrequency, result.ModelExportFrequency);
Assert.AreEqual(config.RewardAggregation, result.RewardAggregation);
Assert.AreEqual(config.RewardWaitTime, result.RewardWaitTime);
PersonalizerAdministrationClient client = GetAdministrationClient(isSingleSlot: true);
await UpdateProperties(client, properties);
await GetProperties(client, properties);
await UpdateAndGetPolicy(client);
await ResetPolicy(client);
}

[Test]
public async Task GetPolicy()
private async Task GetProperties(PersonalizerAdministrationClient client, PersonalizerServiceProperties properties)
{
PersonalizerAdministrationClient client = GetPersonalizerAdministrationClient();
PersonalizerPolicy policy = await client.GetPersonalizerPolicyAsync();
Assert.AreEqual("app1", policy.Name);
Assert.AreEqual("--cb_explore_adf --quadratic GT --quadratic MR --quadratic GR --quadratic ME --quadratic OT --quadratic OE --quadratic OR --quadratic MS --quadratic GX --ignore A --cb_type ips --epsilon 0.2",
policy.Arguments);
PersonalizerServiceProperties result = await client.GetPersonalizerPropertiesAsync();
Assert.AreEqual(properties.DefaultReward, result.DefaultReward);
Assert.True(Math.Abs(properties.ExplorationPercentage - result.ExplorationPercentage) < 1e-3);
Assert.AreEqual(properties.ModelExportFrequency, result.ModelExportFrequency);
Assert.AreEqual(properties.RewardAggregation, result.RewardAggregation);
Assert.AreEqual(properties.RewardWaitTime, result.RewardWaitTime);
}

[Test]
public async Task UpdatePolicy()
private async Task UpdateProperties(PersonalizerAdministrationClient client, PersonalizerServiceProperties properties)
{
PersonalizerServiceProperties result = await client.UpdatePersonalizerPropertiesAsync(properties);
Assert.AreEqual(properties.DefaultReward, result.DefaultReward);
Assert.True(Math.Abs(properties.ExplorationPercentage - result.ExplorationPercentage) < 1e-3);
Assert.AreEqual(properties.ModelExportFrequency, result.ModelExportFrequency);
Assert.AreEqual(properties.RewardAggregation, result.RewardAggregation);
Assert.AreEqual(properties.RewardWaitTime, result.RewardWaitTime);
if (Environment.GetEnvironmentVariable("AZURE_TEST_MODE") == "Record")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a Mode property on the base type

{
await Task.Delay(60000);
}
}

private async Task UpdateAndGetPolicy(PersonalizerAdministrationClient client)
{
PersonalizerAdministrationClient client = GetPersonalizerAdministrationClient();
var policy = new PersonalizerPolicy(
var newPolicy = new PersonalizerPolicy(
name: "app1",
arguments: "--cb_explore_adf --quadratic GT --quadratic MR --quadratic GR --quadratic ME --quadratic OT --quadratic OE --quadratic OR --quadratic MS --quadratic GX --ignore A --cb_type ips --epsilon 0.2"
);
PersonalizerPolicy updatedPolicy = await client.UpdatePersonalizerPolicyAsync(policy);
PersonalizerPolicy updatedPolicy = await client.UpdatePersonalizerPolicyAsync(newPolicy);
Assert.NotNull(updatedPolicy);
Assert.AreEqual(policy.Arguments, updatedPolicy.Arguments);
Assert.AreEqual(newPolicy.Arguments, updatedPolicy.Arguments);
await Task.Delay(30000);
PersonalizerPolicy policy = await client.GetPersonalizerPolicyAsync();
// Only checking the first 190 chars because the epsilon has a float rounding addition when applied
Assert.AreEqual(newPolicy.Arguments, policy.Arguments.Substring(0,190));
}

[Test]
public async Task ResetPolicy()
private async Task ResetPolicy(PersonalizerAdministrationClient client)
{
PersonalizerAdministrationClient client = GetPersonalizerAdministrationClient();
PersonalizerPolicy policy = await client.ResetPersonalizerPolicyAsync();
Assert.AreEqual("--cb_explore_adf --quadratic GT --quadratic MR --quadratic GR --quadratic ME --quadratic OT --quadratic OE --quadratic OR --quadratic MS --quadratic GX --ignore A --cb_type ips --epsilon 0.2",
Assert.AreEqual("--cb_explore_adf --epsilon 0.2 --power_t 0 -l 0.001 --cb_type mtr -q ::",
policy.Arguments);
}
}
Expand Down
Loading