-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
13309375: Improve the tests by mocking LiveModel when test mode is #14
Changes from all commits
a6d181f
0b11fc1
908d7c8
3d0b3d8
30b35de
370ceee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.
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 was deleted.
This file was deleted.
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); | ||
} | ||
} |
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); | ||
} | ||
} | ||
} |
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(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] it is one json with one or more action features, this reads as multiple jsons for action features
same thing goes for slot below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are actually a list of json strings. See the following screenshot:

