Skip to content

Add Variety to Az.Predictor #13480

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

Merged
merged 78 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
64a6838
psd1 & psm1 of Az.Installer with a demo cmdlet (#12698)
msJinLei Aug 19, 2020
ddcec55
Internal/az.installer (#12817)
VeryEarly Sep 1, 2020
cc9d652
Internal/az.installer (#12860)
VeryEarly Sep 4, 2020
34d0557
Cmdlet Update-AzModule (#12832)
msJinLei Sep 4, 2020
a1b007f
Add telemetry
dingmeng-xue Sep 4, 2020
79d1ed0
Merge branch 'internal/Az.Installer' of https://github.com/Azure/azur…
dingmeng-xue Sep 4, 2020
8192c7a
Support telemetry
dingmeng-xue Sep 4, 2020
0a23c60
Move Get-AzModuleUpdateList to internal (#12865)
msJinLei Sep 4, 2020
257e821
add telemetry to Uninstall-AzModule cmdlet
VeryEarly Sep 7, 2020
0d79e63
bugfix: module name was not handled properly
VeryEarly Sep 7, 2020
2eeae6d
Add environment variable to disable telemetry
dingmeng-xue Sep 7, 2020
a7efd49
Merge branch 'internal/Az.Installer' of https://github.com/Azure/azur…
dingmeng-xue Sep 7, 2020
be93bce
parallel executing Install/Uninstall module
VeryEarly Sep 7, 2020
3c1e225
Merge branch 'internal/Az.Installer' of https://github.com/Azure/azur…
VeryEarly Sep 7, 2020
ca5fc5b
update code after review
dingmeng-xue Sep 8, 2020
c8c7b31
improve performance
VeryEarly Sep 8, 2020
8846a97
Merge branch 'internal/Az.Installer' of https://github.com/Azure/azur…
VeryEarly Sep 8, 2020
021097e
Fix Update-AzModule issues
Sep 8, 2020
28cefad
bug fix
VeryEarly Sep 8, 2020
7d80590
remove unused util
VeryEarly Sep 8, 2020
4d13c4e
remove az.accounts when allow preview
VeryEarly Sep 8, 2020
6da2f26
Fix issue when no module to udpate
Sep 8, 2020
5f1e6e1
Add sign pipeline
dingmeng-xue Sep 8, 2020
385bceb
skip confirmation when remove-job
VeryEarly Sep 8, 2020
82b6ecb
Merge branch 'internal/Az.Installer' of https://github.com/Azure/azur…
VeryEarly Sep 8, 2020
42111d5
remove debug info
VeryEarly Sep 8, 2020
e339d16
fix parameter reference
VeryEarly Sep 8, 2020
7e4af16
Initial checking in AzPredictor (#12847)
kceiw Sep 9, 2020
25157f2
filter installedmodules before uninstall
VeryEarly Sep 9, 2020
7aad6d9
bugfix for uninstall
VeryEarly Sep 9, 2020
acb3b81
Add synopsis and example to exported cmdlets
dingmeng-xue Sep 9, 2020
26c6116
add default parameter set for uninstall-azmodule
VeryEarly Sep 9, 2020
cb1da08
merge from remote
VeryEarly Sep 9, 2020
82311c3
add input validatin
VeryEarly Sep 13, 2020
77f0e74
remove unnecessary warning message
VeryEarly Sep 14, 2020
a9bb931
Merge branch 'internal/Az.Installer' into internal/Az.Tools.Predictor
dingmeng-xue Sep 14, 2020
e940a50
Build and package module under artifacts folder
dingmeng-xue Sep 14, 2020
05a38c3
Improve Az.Tool.Predictor (#12922)
kceiw Sep 15, 2020
f70747d
Add Az as external dependency
dingmeng-xue Sep 15, 2020
2badd83
Add pipeline 'sign-tool-predictor'
BethanyZhou Sep 15, 2020
c69d426
Update sign-tool-predictor.yml for Azure Pipelines
BethanyZhou Sep 15, 2020
1ecb5db
Update sign-tool-predictor.yml for Azure Pipelines
BethanyZhou Sep 15, 2020
60fd57f
net.webclient.downloadfile
BethanyZhou Sep 15, 2020
815abe4
refine command
BethanyZhou Sep 15, 2020
03720c1
clean build
BethanyZhou Sep 16, 2020
c5a2050
Update sign-tool-predictor.yml for Azure Pipelines
BethanyZhou Sep 16, 2020
caf8bc1
Improve the build of Az.Tools.Predictor (#12974)
kceiw Sep 16, 2020
910e2cc
Update sign-tool-predictor.yml for Azure Pipelines
BethanyZhou Sep 16, 2020
98c6cbc
Update sign-tool-predictor.yml for Azure Pipelines
BethanyZhou Sep 16, 2020
0d27485
Update sign-tool-predictor.yml for Azure Pipelines
BethanyZhou Sep 16, 2020
58c204d
Update sign-tool-predictor.yml for Azure Pipelines
BethanyZhou Sep 16, 2020
b3bda56
Override powershellcorecommandPrefix
BethanyZhou Sep 16, 2020
84927a9
join_path
BethanyZhou Sep 16, 2020
d59c151
Update sign-tool-predictor.yml for Azure Pipelines
BethanyZhou Sep 16, 2020
716bb7d
Update sign-tool-predictor.yml for Azure Pipelines
BethanyZhou Sep 16, 2020
61c21eb
Update sign-tool-predictor.yml for Azure Pipelines
BethanyZhou Sep 16, 2020
3a74d57
Update sign-tool-predictor.yml for Azure Pipelines
BethanyZhou Sep 16, 2020
2e8d65f
Install Az
BethanyZhou Sep 16, 2020
556abe1
Update sign-tool-predictor.yml for Azure Pipelines
BethanyZhou Sep 16, 2020
2c113ea
Update sign-tool-predictor.yml for Azure Pipelines
BethanyZhou Sep 16, 2020
8405e63
Sign dll
BethanyZhou Sep 16, 2020
7893ac5
Remove dll sign
BethanyZhou Sep 16, 2020
57cab6d
Predict parameter values in the suggestion (#12984)
kceiw Sep 18, 2020
ce42552
improve telemetry (#13025)
kceiw Sep 24, 2020
e182978
return multiple suggestion (#13098)
kceiw Oct 5, 2020
822b212
Reduce the dependencies on Azure powershell common. (#13113)
kceiw Oct 8, 2020
a239d68
Add a missing file. (#13234)
kceiw Oct 17, 2020
4b1ff75
Fix duplicate text (#13326)
kceiw Oct 27, 2020
ec15095
Update how we send request and collect telemetry (#13327)
kceiw Nov 3, 2020
e0e6a65
add variety to predictions list
yemohyleyemohyle Nov 4, 2020
4fc97d2
add variety to predictions list
yemohyleyemohyle Nov 4, 2020
fff725f
Bug fixes and performance improvement (#13410)
kceiw Nov 5, 2020
33c1181
Improve the telemetry and http request (#13354)
kceiw Nov 5, 2020
99a809e
Merge remote-tracking branch 'upstream/internal/Az.Tools.Predictor' i…
yemohyleyemohyle Nov 5, 2020
868c6cb
Fixed issue of duplicate threshold consistency caused by two Query fu…
yemohyleyemohyle Nov 9, 2020
1760432
Fixed issue of duplicate threshold consistency caused by two Query fu…
yemohyleyemohyle Nov 10, 2020
0f97b51
remove commented lines, change Dictionary to IDictionary
yemohyleyemohyle Nov 16, 2020
c44d534
Merge remote-tracking branch 'upstream/master' into internal/Az.Tools…
yemohyleyemohyle Nov 19, 2020
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 @@ -62,11 +62,12 @@ public AzPredictorServiceTests(ModelFixture fixture)
public void VerifyUsingSuggestion(string userInput)
{
var predictionContext = PredictionContext.Create(userInput);
var expected = this._suggestionsPredictor.Query(predictionContext.InputAst, 1, CancellationToken.None);
var actual = this._service.GetSuggestion(predictionContext.InputAst, 1, CancellationToken.None);
var presentCommands = new System.Collections.Generic.Dictionary<string, int>();
var expected = this._suggestionsPredictor.Query(predictionContext.InputAst, presentCommands, 1, 1, CancellationToken.None);
var actual = this._service.GetSuggestion(predictionContext.InputAst, 1, 1, CancellationToken.None);
Assert.NotEmpty(actual);
Assert.NotNull(actual.First().Item1);
Assert.Equal(expected.First().Key, actual.First().Item1);
Assert.Equal(expected.Item1.First().Key, actual.First().Item1);
Assert.Equal(PredictionSource.CurrentCommand, actual.First().Item3);
}

Expand All @@ -79,11 +80,12 @@ public void VerifyUsingSuggestion(string userInput)
public void VerifyUsingCommand(string userInput)
{
var predictionContext = PredictionContext.Create(userInput);
var expected = this._commandsPredictor.Query(predictionContext.InputAst, 1, CancellationToken.None);
var actual = this._service.GetSuggestion(predictionContext.InputAst, 1, CancellationToken.None);
var presentCommands = new System.Collections.Generic.Dictionary<string, int>();
var expected = this._commandsPredictor.Query(predictionContext.InputAst, presentCommands, 1, 1, CancellationToken.None);
var actual = this._service.GetSuggestion(predictionContext.InputAst, 1, 1, CancellationToken.None);
Assert.NotEmpty(actual);
Assert.NotNull(actual.First().Item1);
Assert.Equal(expected.First().Key, actual.First().Item1);
Assert.Equal(expected.Item1.First().Key, actual.First().Item1);
Assert.Equal(PredictionSource.StaticCommands, actual.First().Item3);
}

Expand All @@ -101,7 +103,7 @@ public void VerifyUsingCommand(string userInput)
public void VerifyNoPrediction(string userInput)
{
var predictionContext = PredictionContext.Create(userInput);
var actual = this._service.GetSuggestion(predictionContext.InputAst, 1, CancellationToken.None);
var actual = this._service.GetSuggestion(predictionContext.InputAst, 1, 1, CancellationToken.None);
Assert.Empty(actual);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void VerifySupportedCommandMasked()
public void VerifySuggestion(string userInput)
{
var predictionContext = PredictionContext.Create(userInput);
var expected = this._service.GetSuggestion(predictionContext.InputAst, 1, CancellationToken.None);
var expected = this._service.GetSuggestion(predictionContext.InputAst, 1, 1, CancellationToken.None);
var actual = this._azPredictor.GetSuggestion(predictionContext, CancellationToken.None);

Assert.Equal(expected.Select(e => e.Item1), actual.Select(a => a.SuggestionText));
Expand Down
30 changes: 18 additions & 12 deletions tools/Az.Tools.Predictor/Az.Tools.Predictor.Test/PredictorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ public PredictorTests(ModelFixture fixture)
public void GetNullPredictionWithCommandName(string userInput)
{
var predictionContext = PredictionContext.Create(userInput);
var result = this._predictor.Query(predictionContext.InputAst, 1, CancellationToken.None);
Assert.Empty(result);
var presentCommands = new System.Collections.Generic.Dictionary<string, int>();
var result = this._predictor.Query(predictionContext.InputAst, presentCommands, 1, 1, CancellationToken.None);
Assert.Empty(result.Item1);
}

/// <summary>
Expand All @@ -66,8 +67,9 @@ public void GetNullPredictionWithCommandName(string userInput)
public void GetPredictionWithCommandName(string userInput)
{
var predictionContext = PredictionContext.Create(userInput);
var result = this._predictor.Query(predictionContext.InputAst, 1, CancellationToken.None);
Assert.NotEmpty(result);
var presentCommands = new System.Collections.Generic.Dictionary<string, int>();
var result = this._predictor.Query(predictionContext.InputAst, presentCommands, 1, 1, CancellationToken.None);
Assert.NotEmpty(result.Item1);
}

/// <summary>
Expand All @@ -81,8 +83,9 @@ public void GetPredictionWithCommandName(string userInput)
public void GetPredictionWithCommandNameParameters(string userInput)
{
var predictionContext = PredictionContext.Create(userInput);
var result = this._predictor.Query(predictionContext.InputAst, 1, CancellationToken.None);
Assert.NotEmpty(result);
var presentCommands = new System.Collections.Generic.Dictionary<string, int>();
var result = this._predictor.Query(predictionContext.InputAst, presentCommands, 1, 1, CancellationToken.None);
Assert.NotEmpty(result.Item1);
}

/// <summary>
Expand All @@ -97,8 +100,9 @@ public void GetPredictionWithCommandNameParameters(string userInput)
public void GetNullPredictionWithCommandNameParameters(string userInput)
{
var predictionContext = PredictionContext.Create(userInput);
var result = this._predictor.Query(predictionContext.InputAst, 1, CancellationToken.None);
Assert.Empty(result);
var presentCommands = new System.Collections.Generic.Dictionary<string, int>();
var result = this._predictor.Query(predictionContext.InputAst, presentCommands, 1, 1, CancellationToken.None);
Assert.Empty(result.Item1);
}

/// <summary>
Expand All @@ -108,9 +112,10 @@ public void GetNullPredictionWithCommandNameParameters(string userInput)
public void VerifyPredictionForCommand()
{
var predictionContext = PredictionContext.Create("Connect-AzAccount");
var result = this._predictor.Query(predictionContext.InputAst, 1, CancellationToken.None);
var presentCommands = new System.Collections.Generic.Dictionary<string, int>();
var result = this._predictor.Query(predictionContext.InputAst, presentCommands, 1, 1, CancellationToken.None);

Assert.Equal("Connect-AzAccount -Credential <PSCredential> -ServicePrincipal -Tenant <>", result.First().Key);
Assert.Equal("Connect-AzAccount -Credential <PSCredential> -ServicePrincipal -Tenant <>", result.Item1.First().Key);
}

/// <summary>
Expand All @@ -120,9 +125,10 @@ public void VerifyPredictionForCommand()
public void VerifyPredictionForCommandAndParameters()
{
var predictionContext = PredictionContext.Create("GET-AZSTORAGEACCOUNTKEY -NAME");
var result = this._predictor.Query(predictionContext.InputAst, 1, CancellationToken.None);
var presentCommands = new System.Collections.Generic.Dictionary<string, int>();
var result = this._predictor.Query(predictionContext.InputAst, presentCommands, 1, 1, CancellationToken.None);

Assert.Equal("Get-AzStorageAccountKey -Name 'ContosoStorage' -ResourceGroupName 'ContosoGroup02'", result.First().Key);
Assert.Equal("Get-AzStorageAccountKey -Name 'ContosoStorage' -ResourceGroupName 'ContosoGroup02'", result.Item1.First().Key);
}
}
}
2 changes: 1 addition & 1 deletion tools/Az.Tools.Predictor/Az.Tools.Predictor/AzPredictor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public List<PredictiveSuggestion> GetSuggestion(PredictionContext context, Cance
{
maskedUserInput = AzPredictor.MaskCommandLine(context.InputAst.FindAll((ast) => ast is CommandAst, true).LastOrDefault() as CommandAst);

suggestions = _service.GetSuggestion(context.InputAst, _settings.SuggestionCount.Value, localCancellationToken);
suggestions = _service.GetSuggestion(context.InputAst, _settings.SuggestionCount.Value, _settings.MaxAllowedCommandDuplicate.Value, localCancellationToken);

localCancellationToken.ThrowIfCancellationRequested();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,17 @@ protected virtual void Dispose(bool disposing)
/// <remarks>
/// Queries the Predictor with the user input if predictions are available, otherwise uses commands
/// </remarks>
public IEnumerable<ValueTuple<string, string, PredictionSource>> GetSuggestion(Ast input, int suggestionCount, CancellationToken cancellationToken)
public IEnumerable<ValueTuple<string, string, PredictionSource>> GetSuggestion(Ast input, int suggestionCount, int maxAllowedCommandDuplicate, CancellationToken cancellationToken)
{
var commandSuggestions = this._commandSuggestions;
var command = this._commandForPrediction;

IList<ValueTuple<string, string, PredictionSource>> results = new List<ValueTuple<string, string, PredictionSource>>();
var presentCommands = new System.Collections.Generic.Dictionary<string, int>();
var resultsFromSuggestionTuple = commandSuggestions?.Item2?.Query(input, presentCommands, suggestionCount, maxAllowedCommandDuplicate, cancellationToken);
var resultsFromSuggestion = resultsFromSuggestionTuple.Item1;
presentCommands = resultsFromSuggestionTuple.Item2.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

var resultsFromSuggestion = commandSuggestions?.Item2?.Query(input, suggestionCount, cancellationToken);

if (resultsFromSuggestion != null)
{
Expand All @@ -159,7 +162,9 @@ public IEnumerable<ValueTuple<string, string, PredictionSource>> GetSuggestion(A
if ((resultsFromSuggestion == null) || (resultsFromSuggestion.Count() < suggestionCount))
{
var commands = this._commands;
var resultsFromCommands = commands?.Query(input, suggestionCount - resultsFromSuggestion.Count(), cancellationToken);
var resultsFromCommandsTuple = commands?.Query(input, presentCommands,suggestionCount - resultsFromSuggestion.Count(), maxAllowedCommandDuplicate, cancellationToken);
var resultsFromCommands = resultsFromCommandsTuple.Item1;
presentCommands = resultsFromCommandsTuple.Item2.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

if (resultsFromCommands != null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"serviceUri": "https://app.aladdin.microsoft.com/api/v1",
"maxAllowedCommandDuplicate": 1,
"serviceUri": "https://app.aladdin.microsoft.com/api/v1",
"suggestionCount": 7
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ public interface IAzPredictorService
/// </summary>
/// <param name="input">User input from PSReadLine</param>
/// <param name="suggestionCount">The number of suggestion to return.</param>
/// <param name="maxAllowedCommandDuplicate">The maximum amount of the same commnds in the list of predictions.</param>
/// <param name="cancellationToken">The cancellation token</param>
/// <returns>The list of suggestions for <paramref name="input"/> and the source that create the suggestion. The maximum number of suggestion is <paramref name="suggestionCount"/></returns>
public IEnumerable<ValueTuple<string, string, PredictionSource>> GetSuggestion(Ast input, int suggestionCount, CancellationToken cancellationToken);
public IEnumerable<ValueTuple<string, string, PredictionSource>> GetSuggestion(Ast input, int suggestionCount, int maxAllowedCommandDuplicate, CancellationToken cancellationToken);

/// <summary>
/// Requests predictions, given a command string.
Expand Down
22 changes: 15 additions & 7 deletions tools/Az.Tools.Predictor/Az.Tools.Predictor/Predictor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ public Predictor(IList<string> modelPredictions, ParameterValuePredictor paramet
/// Given a user input PowerShell AST, returns prediction text.
/// </summary>
/// <param name="input">PowerShell AST input of the user, generated by PSReadLine</param>
/// <param name="presentCommands">Commands already present.</param>
/// <param name="suggestionCount">The number of suggestion to return.</param>
/// <param name="maxAllowedCommandDuplicate">The maximum amount of the same commnds in the list of predictions.</param>
/// <param name="cancellationToken">The cancellation token</param>
/// <returns>The collection of suggestions. The key is the predicted text adjusted based on <paramref name="input"/>. The
/// value is the original text to create the adjusted text. </returns>
public IDictionary<string, string> Query(Ast input, int suggestionCount, CancellationToken cancellationToken)
public Tuple<IDictionary<string, string>, IDictionary<string, int>> Query(Ast input, IDictionary<string, int> presentCommands, int suggestionCount, int maxAllowedCommandDuplicate, CancellationToken cancellationToken)
{
if (suggestionCount <= 0)
{
Expand All @@ -77,6 +79,7 @@ public IDictionary<string, string> Query(Ast input, int suggestionCount, Cancell
}

var results = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
var resultsTemp = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

try
{
Expand All @@ -102,9 +105,7 @@ public IDictionary<string, string> Query(Ast input, int suggestionCount, Cancell
var resultBuilder = new StringBuilder();
var usedParams = new HashSet<int>();
var sourceBuilder = new StringBuilder();
var presentCommands = new System.Collections.Generic.Dictionary<string, int>(); // Added
int maxAllowedCommandDupl = 1;


for (var i = 0; i < _predictions.Count && results.Count < suggestionCount; ++i)
{
if (commandNameQuery(_predictions[i].Command))
Expand Down Expand Up @@ -148,11 +149,15 @@ public IDictionary<string, string> Query(Ast input, int suggestionCount, Cancell
results.Add(prediction.ToString(), sourceBuilder.ToString());
presentCommands.Add(_predictions[i].Command, 1);
}
else if (presentCommands[_predictions[i].Command] < maxAllowedCommandDupl)
else if (presentCommands[_predictions[i].Command] < maxAllowedCommandDuplicate)
{
results.Add(prediction.ToString(), sourceBuilder.ToString());
presentCommands[_predictions[i].Command] += 1;
}
else
{
resultsTemp.Add(prediction.ToString(), sourceBuilder.ToString());
}

if (results.Count == suggestionCount)
{
Expand All @@ -166,8 +171,11 @@ public IDictionary<string, string> Query(Ast input, int suggestionCount, Cancell
catch
{
}

return results;
if ((results.Count < suggestionCount) && (resultsTemp.Count >0))
{
resultsTemp.ToList().GetRange(0, suggestionCount - results.Count).ForEach(x => results.Add(x.Key,x.Value));
}
return new Tuple<IDictionary<string, string>, IDictionary<string, int>>(results, presentCommands);
}

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions tools/Az.Tools.Predictor/Az.Tools.Predictor/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ sealed class Settings
/// The number of suggestions to return to PSReadLine
/// </summary>
public int? SuggestionCount { get; set; }
public int? MaxAllowedCommandDuplicate { get; set; }

private static bool? _isContinueOnTimeout;
/// <summary>
Expand Down Expand Up @@ -121,6 +122,11 @@ private void OverrideSettingsFromProfile()
{
this.SuggestionCount = profileSettings.SuggestionCount;
}

if (profileSettings.MaxAllowedCommandDuplicate.HasValue && (profileSettings.MaxAllowedCommandDuplicate.Value > 0))
{
this.MaxAllowedCommandDuplicate = profileSettings.MaxAllowedCommandDuplicate;
}
}
catch
{
Expand Down