Skip to content

Add Azure PowerShell suggestions - #1

Open
aayc wants to merge 9 commits into
fishfrom
aps_predict
Open

aayc wants to merge 9 commits into
fishfrom
aps_predict

Conversation

@aayc

@aayc aayc commented Jun 10, 2020

Copy link
Copy Markdown
Owner

Summary

Add request calls to a prediction service endpoint that return suggestions for Azure PowerShell commands. These suggestions are offered in addition to history suggestions when user is typing in console.

To provide this functionality, minimal changes are made to existing logic, and a new file AzSuggestion.cs is added to handle the requests, processing and logging.

PR Checklist

  • [ X] PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Make sure you've added one or more new tests
  • User-facing changes
    • [X ] Not Applicable
    • OR
    • Documentation needed at PowerShell-Docs
      • Doc Issue filed:

@skdeng skdeng left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't finished looking through AzSuggestion.cs file, will finish later


namespace Microsoft.PowerShell
{
public partial class PSConsoleReadLine

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Is there a reason why the name of the class is the not the same as the name of the file?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be the convention for much of PSReadLine, e.g. History.cs is also part of the PSConsoleReadLine class (so is Completion.cs, etc.)

Comment thread PSReadLine/AzSuggestion.cs Outdated
Comment thread PSReadLine/AzSuggestion.cs Outdated
Comment on lines +14 to +20
const char commandSplitTokens = '|';
const string serviceUri = "http://localhost:3000/prediction"; // TODO use real service URI
HttpClient client = new HttpClient();
List<string> suggestions = new List<string>();
List<string> commands = new List<string>();
HashSet<string> commandSet = new HashSet<string>();
List<Dictionary<string, string>> logs = new List<Dictionary<string, string>>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use var instead of explicit types when the variable type is unambiguous

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated code in methods for this; I think these top level declarations must be explicitly typed

Comment thread PSReadLine/AzSuggestion.cs Outdated
Comment thread PSReadLine/AzSuggestion.cs Outdated
Comment thread PSReadLine/AzSuggestion.cs Outdated
Comment thread PSReadLine/AzSuggestion.cs Outdated
// If no history available, use start token
if (i < 0)
{
previousLines.Add("start_of_snippet");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if _history is empty, two "start_of_snippet" will be added. is this the intended behavior?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the lookup model in the service is expecting n = 2 lines of history and start_of_snippet is the token for "no history"

@mirdaki mirdaki left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good. Mostly just nits from me.

Comment thread PSReadLine/ReadLine.cs Outdated
{ "CorrelationId", "00000000-0000-0000-0000-000000000000" },
{ "SessionId", "00000000-0000-0000-0000-000000000000" },
{ "SubscriptionId", "00000000-0000-0000-0000-000000000000" },
{ "VersionNumber", "1.0" }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there meaningful values for these we can use? If not, aside from the version number, they are not required to be sent.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this is a work in progress! Trying to locate the telemetry package that can provide these.

commands = JsonConvert.DeserializeObject<List<string>>(reply);
commandSet = new HashSet<string>(commands.Select(x => x.ToLower()));
waitForCommands = false;
RequestPredictions();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any situation where you would want the commands, but not need to also request the predictions? It might make sense to break them down more.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since commands are only fetched once on session startup (and fetching the commands as a concept is essentially a stopgap until a better model is created), I think they are pretty well entangled.

Aaron Chan added 2 commits June 12, 2020 09:32
Add telemetry tracking

Use parameter bagging for order independent prediction, move query structure to new file, add telemetry client and logging capabilities
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants