Skip to content

Commit

Permalink
Add RankProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhuang01 committed Dec 24, 2021
1 parent c586920 commit 43967d3
Show file tree
Hide file tree
Showing 18 changed files with 502 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(RequiredTargetFrameworks);net47</TargetFrameworks>
<NoWarn>$(NoWarn);SYSLIB0023</NoWarn>
<NoWarn>$(NoWarn);CS8032</NoWarn>
<IncludeGeneratorSharedCode>true</IncludeGeneratorSharedCode>
</PropertyGroup>
<ItemGroup>
Expand Down
10 changes: 8 additions & 2 deletions sdk/personalizer/Azure.AI.Personalizer.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31410.414
# Visual Studio Version 16
VisualStudioVersion = 16.0.32002.261
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.AI.Personalizer", "Azure.AI.Personalizer\src\Azure.AI.Personalizer.csproj", "{B940AE9B-814A-4A20-9C81-3B8E5345E3B4}"
EndProject
Expand All @@ -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 @@ -32,6 +32,8 @@

<ItemGroup>
<PackageReference Include="Azure.Core" />
<PackageReference Include="Microsoft.RL" VersionOverride="1.0.18120003-INTERNAL" />
<PackageReference Include="Newtonsoft.Json" VersionOverride="13.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.

24 changes: 21 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.

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

using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

namespace Azure.AI.Personalizer
{
/// <summary> The Decision Context. </summary>
public class DecisionContext
{
/// <summary> The Decision Context. </summary>
public DecisionContext()
{
}

/// <summary> Initializes a new instance of DecisionContext. </summary>
/// <param name="rankRequest"> Personalizer Rank Options </param>
public DecisionContext(PersonalizerRankOptions rankRequest)
{
List<string> jsonFeatures = rankRequest.ContextFeatures.Select(f => JsonConvert.SerializeObject(f)).ToList();
this.SharedFromUrl = jsonFeatures;

this.Documents = rankRequest.Actions
.Select(action =>
{
string ids = null;
List<string> jsonFeatures = action.Features.Select(f => JsonConvert.SerializeObject(f)).ToList();
//if (action.Ids != null)
//{
// ids = string.Join(",", action.Ids);
//}
var doc = new DecisionContextDocument
{
ID = ids,
JSON = jsonFeatures,
};
//if (action.ActionSet != null && action.ActionSet?.Id != null)
// doc.Source = new DecisionContextDocumentSource
// {
// Set = action.ActionSet.Id.Id,
// Parameter = action.ActionSet.Parameter
// };
return doc;
}).ToArray();

//this.Slots = decisionRequest.Slots?
// .Select(slot => new DecisionContextDocument {
// SlotId = slot.Id,
// SlotJson = slot.JsonFeatures
// }).ToArray();
}

/// <summary> Properties from url </summary>
[JsonProperty("FromUrl", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(JsonRawStringListConverter))]
#pragma warning disable CA2227 // Collection properties should be read only
public List<string> SharedFromUrl { get; set; }
#pragma warning restore CA2227 // Collection properties should be read only

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

/// <summary> Properties of slots </summary>
[JsonProperty("_slots", NullValueHandling = NullValueHandling.Ignore)]
public DecisionContextDocument[] Slots { get; set; }
}
}

0 comments on commit 43967d3

Please sign in to comment.