Skip to content

Commit

Permalink
12768045: Add rank processor for single slot (Azure#3)
Browse files Browse the repository at this point in the history
Add RankProcessor

Remove unused file

Remove some key

Toggle commented codes so that most tests can pass

RankProcessor is working. Still need to clean up the codes

Add test json files

only construct LiveModel when localInference is true

Move rankprocessor to under model

Add latest generated files from autorest

Add autogenerated files from autorest

Fix the setting in DecisionContext

Remove wrong comment

Revert unexpected auto-generated file changes

Addressed a comment

Move suppression to GlobalSuppressions.cs

Remove the decoration in MultiSlotClient.cs

Refactor rankProcessor so that the actions is not modified and restored;
added a converter between sdk and Rl.Net; replace Newtonsoft.json with
System.Text.Json

Address comments

Refactor RlObjuectConverter; remove some unneeded setters, etc.

Added unit tests for RlObjectConverter, DecisionContext,
JsonRawStringListConverter

Remove unused using
  • Loading branch information
johnhuang01 authored Jan 26, 2022
1 parent 7616f7c commit 062871e
Show file tree
Hide file tree
Showing 30 changed files with 1,014 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(RequiredTargetFrameworks);net47</TargetFrameworks>
<NoWarn>$(NoWarn);CS8032</NoWarn>
<IncludeGeneratorSharedCode>true</IncludeGeneratorSharedCode>
</PropertyGroup>
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions sdk/core/Azure.Core.TestFramework/src/TestRecording.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,12 @@ public TestRandom Random
#if NET6_0_OR_GREATER
var liveSeed = RandomNumberGenerator.GetInt32(int.MaxValue);
#else
#pragma warning disable SYSLIB0023
var csp = new RNGCryptoServiceProvider();
var bytes = new byte[4];
csp.GetBytes(bytes);
var liveSeed = BitConverter.ToInt32(bytes, 0);
#pragma warning restore SYSLIB0023
#endif
_random = new TestRandom(Mode, liveSeed);
break;
Expand Down
6 changes: 6 additions & 0 deletions sdk/personalizer/Azure.AI.Personalizer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework", "..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{0F88C67F-34D2-4C68-B5BF-08A547D4CC2E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core", "..\core\Azure.Core\src\Azure.Core.csproj", "{CFB35402-69EB-448F-82B7-2D284730B0A6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -35,6 +37,10 @@ Global
{0F88C67F-34D2-4C68-B5BF-08A547D4CC2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F88C67F-34D2-4C68-B5BF-08A547D4CC2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F88C67F-34D2-4C68-B5BF-08A547D4CC2E}.Release|Any CPU.Build.0 = Release|Any CPU
{CFB35402-69EB-448F-82B7-2D284730B0A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CFB35402-69EB-448F-82B7-2D284730B0A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CFB35402-69EB-448F-82B7-2D284730B0A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CFB35402-69EB-448F-82B7-2D284730B0A6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>Microsoft Azure.AI.Personalizer client library</AssemblyTitle>
<Version>2.0.0-beta.2</Version>
Expand Down Expand Up @@ -33,6 +33,7 @@
<ItemGroup>
<PackageReference Include="Azure.Core" />
<PackageReference Include="Microsoft.RL" VersionOverride="1.0.18120003-INTERNAL" />
<PackageReference Include="System.Text.Json" VersionOverride="6.0.1" />
</ItemGroup>

</Project>

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

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

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

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

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

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

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

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

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

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

30 changes: 27 additions & 3 deletions sdk/personalizer/Azure.AI.Personalizer/src/Generated/RankClient.cs

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
@@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Text.Json;
using System.Text.Json.Serialization;
using System.Collections.Generic;
using System.Linq;

namespace Azure.AI.Personalizer
{
/// <summary> The Decision Context. </summary>
public class DecisionContext
{
/// <summary> The Decision Context used to serialize an object. </summary>
public DecisionContext()
{
}

/// <summary> Initializes a new instance of DecisionContext. </summary>
/// <param name="contextFeatures"> The context feature </param>
/// <param name="rankableActions"> Rankable actions </param>
public DecisionContext(IEnumerable<object> contextFeatures, List<PersonalizerRankableAction> rankableActions)
{
this.ContextFeatures = contextFeatures.Select(f => JsonSerializer.Serialize(f)).ToList();
this.Documents = rankableActions
.Select(action =>
{
List<string> actionFeatures = action.Features.Select(f => JsonSerializer.Serialize(f)).ToList();
return new DecisionContextDocument(action.Id, actionFeatures);
}).ToArray();
}

/// <summary> Properties from url </summary>
[JsonPropertyName("FromUrl")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonConverter(typeof(JsonRawStringListConverter))]
public List<string> ContextFeatures { get; }

/// <summary> Properties of documents </summary>
[JsonPropertyName("_multi")]
public DecisionContextDocument[] Documents { get; set; }

/// <summary> Properties of slots </summary>
[JsonPropertyName("_slots")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public DecisionContextDocument[] Slots { get; set; }
}
}
Loading

0 comments on commit 062871e

Please sign in to comment.