forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
13309375: Improve the tests by mocking LiveModel when test mode is (A…
…zure#14) * 13309375: Improve the tests by mocking LiveModel when test mode is Playback but using real LiveModel when test mode is Live * Change some public classes to private * Address those comments in the main PR * Update Microsoft.RL version * Rename some properties * Update Microsoft.RL version
- Loading branch information
1 parent
fc8a166
commit 356fcbc
Showing
27 changed files
with
1,499 additions
and
917 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
sdk/personalizer/Azure.AI.Personalizer/src/Generated/Models/PersonalizerRankResult.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
sdk/personalizer/Azure.AI.Personalizer/src/Generated/Models/PersonalizerRankedAction.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 4 additions & 2 deletions
6
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.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
sdk/personalizer/Azure.AI.Personalizer/src/Models/ActionProbabilityWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Rl.Net; | ||
|
||
namespace Azure.AI.Personalizer | ||
{ | ||
/// <summary> The Wrapper for Rl.Net.ActionProbability </summary> | ||
public class ActionProbabilityWrapper | ||
{ | ||
private readonly ActionProbability _actionProbability; | ||
|
||
/// <summary> The probability </summary> | ||
public virtual float Probability { get { return _actionProbability.Probability; } } | ||
|
||
/// <summary> The action index </summary> | ||
public virtual long ActionIndex { get { return _actionProbability.ActionIndex; } } | ||
|
||
/// <summary> Initializes a new instance of ActionProbabilityWrapper. </summary> | ||
public ActionProbabilityWrapper() | ||
{ | ||
} | ||
|
||
/// <summary> Initializes a new instance of ActionProbabilityWrapper. </summary> | ||
/// <param name="actionProbability"> An action probability </param> | ||
public ActionProbabilityWrapper(ActionProbability actionProbability) | ||
{ | ||
_actionProbability = actionProbability; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
sdk/personalizer/Azure.AI.Personalizer/src/Models/DecisionContextDocumentId.cs
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
sdk/personalizer/Azure.AI.Personalizer/src/Models/DecisionContextDocumentSource.cs
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
sdk/personalizer/Azure.AI.Personalizer/src/Models/ILiveModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Rl.Net; | ||
using System; | ||
|
||
namespace Azure.AI.Personalizer | ||
{ | ||
/// <summary> An interface for Rl.Net.LiveModel </summary> | ||
public interface ILiveModel | ||
{ | ||
/// <summary> Init LiveModel </summary> | ||
void Init(); | ||
|
||
/// <summary> Wrapper method of ChooseRank </summary> | ||
RankingResponseWrapper ChooseRank(string eventId, string contextJson, ActionFlags flags); | ||
|
||
/// <summary> Wrapper method of RequestMultiSlotDecisionDetailed </summary> | ||
MultiSlotResponseDetailedWrapper RequestMultiSlotDecisionDetailed(string eventId, string contextJson, ActionFlags flags, int[] baselineActions); | ||
|
||
/// <summary> Wrapper method of QueueOutcomeEvent </summary> | ||
void QueueOutcomeEvent(string eventId, float outcome); | ||
|
||
/// <summary> Wrapper method of RequestMultiSlotDecisionDetailed </summary> | ||
void QueueOutcomeEvent(string eventId, string slotId, float outcome); | ||
|
||
/// <summary> Wrapper method of QueueActionTakenEvent </summary> | ||
void QueueActionTakenEvent(string eventId); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
sdk/personalizer/Azure.AI.Personalizer/src/Models/LiveModelAdapter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Rl.Net; | ||
using System; | ||
|
||
namespace Azure.AI.Personalizer | ||
{ | ||
/// <summary> An adapter class of Rl.Net.LiveModel </summary> | ||
public class LiveModelAdapter : ILiveModel | ||
{ | ||
private readonly LiveModel liveModel; | ||
|
||
/// <summary> Initializes a new instance of LiveModelAdapter. </summary> | ||
public LiveModelAdapter(LiveModel liveModel) | ||
{ | ||
this.liveModel = liveModel ?? throw new ArgumentNullException(nameof(liveModel)); | ||
} | ||
|
||
/// <summary> Init LiveModel </summary> | ||
public void Init() | ||
{ | ||
liveModel.Init(); | ||
} | ||
|
||
/// <summary> Wrapper method of ChooseRank </summary> | ||
public RankingResponseWrapper ChooseRank(string eventId, string contextJson, ActionFlags flags) | ||
{ | ||
RankingResponse rankingResponse = liveModel.ChooseRank(eventId, contextJson, flags); | ||
RankingResponseWrapper rankingResponseWrapper = rankingResponse == null ? null : new RankingResponseWrapper(rankingResponse); | ||
|
||
return rankingResponseWrapper; | ||
} | ||
|
||
/// <summary> Wrapper method of RequestMultiSlotDecisionDetailed </summary> | ||
public MultiSlotResponseDetailedWrapper RequestMultiSlotDecisionDetailed(string eventId, string contextJson, ActionFlags flags, int[] baselineActions) | ||
{ | ||
MultiSlotResponseDetailed multiSlotResponse = liveModel.RequestMultiSlotDecisionDetailed(eventId, contextJson, flags, baselineActions); | ||
MultiSlotResponseDetailedWrapper multiSlotResponseDetailedWrapper = multiSlotResponse == null ? null : new MultiSlotResponseDetailedWrapper(multiSlotResponse); | ||
return multiSlotResponseDetailedWrapper; | ||
} | ||
|
||
/// <summary> Wrapper method of QueueOutcomeEvent </summary> | ||
public void QueueOutcomeEvent(string eventId, float outcome) | ||
{ | ||
liveModel.QueueOutcomeEvent(eventId, outcome); | ||
} | ||
|
||
/// <summary> Wrapper method of RequestMultiSlotDecisionDetailed </summary> | ||
public void QueueOutcomeEvent(string eventId, string slotId, float outcome) | ||
{ | ||
liveModel.QueueOutcomeEvent(eventId, slotId, outcome); | ||
} | ||
|
||
/// <summary> Wrapper method of QueueActionTakenEvent </summary> | ||
public void QueueActionTakenEvent(string eventId) | ||
{ | ||
liveModel.QueueActionTakenEvent(eventId); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
sdk/personalizer/Azure.AI.Personalizer/src/Models/MultiSlotResponseDetailedWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Rl.Net; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace Azure.AI.Personalizer | ||
{ | ||
/// <summary> The Wrapper for Rl.Net.MultiSlotResponseDetailed </summary> | ||
public class MultiSlotResponseDetailedWrapper : IEnumerable<SlotRankingResponseWrapper> | ||
{ | ||
private readonly MultiSlotResponseDetailed _multiSlotResponse; | ||
|
||
/// <summary> Initializes a new instance of ActionProbabilityWrapper. </summary> | ||
public MultiSlotResponseDetailedWrapper() | ||
{ | ||
} | ||
|
||
/// <summary> Initializes a new instance of ActionProbabilityWrapper. </summary> | ||
public MultiSlotResponseDetailedWrapper(MultiSlotResponseDetailed multiSlotResponse) | ||
{ | ||
_multiSlotResponse = multiSlotResponse ?? throw new ArgumentNullException(nameof(multiSlotResponse)); | ||
} | ||
|
||
/// <summary> Get the enumerator </summary> | ||
public virtual IEnumerator<SlotRankingResponseWrapper> GetEnumerator() | ||
{ | ||
var enu = _multiSlotResponse.GetEnumerator(); | ||
while (enu.MoveNext()) | ||
{ | ||
yield return new SlotRankingResponseWrapper(enu.Current); | ||
} | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
} | ||
} |
Oops, something went wrong.