Skip to content
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

Add an AI chat experience to Windows Terminal, powered by the user's Azure OpenAI resource #16285

Merged
merged 22 commits into from
Nov 16, 2023

Conversation

PankajBhojwani
Copy link
Contributor

@PankajBhojwani PankajBhojwani commented Nov 9, 2023

Summary of the Pull Request

Adds an AI chatbot to Windows Terminal. Currently we do not ship with our own LLM, the user needs to provide their own Azure OpenAI subscription to be able to use this feature.

  • A new settings page has been added where the user can input their Azure OpenAI endpoint and key
  • A new palette has been added to the dropdown, called Terminal Chat
  • From Terminal Chat, the user can make queries to the provided endpoint for assistance with shell commands
  • We let the endpoint know about the user's current shell so that (hopefully) the commands received are relevant to the user's context
  • Received commands can be clicked from within the palette to be input into the user's active shell
  • The system prompt, alongside Azure OpenAI's in-built safeguards, should prevent strange/inappropriate replies from the LLM

Validation Steps Performed

image

References and Relevant Issues

#15000

PR Checklist

  • Closes #xxx
  • Tests added/passed
  • Documentation updated
    • If checked, please file a pull request on our docs repo and link it here: #xxx
  • Schema updated (if necessary)

This comment has been minimized.

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

31/56 and I've obviously only done the easy ones

src/cascadia/TerminalApp/App.cpp Outdated Show resolved Hide resolved
src/renderer/atlas/AtlasEngine.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsEditor/init.cpp Show resolved Hide resolved
src/cascadia/TerminalSettingsEditor/MainPage.xaml Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.h Outdated Show resolved Hide resolved
src/cascadia/QueryExtension/pch.h Outdated Show resolved Hide resolved
src/cascadia/QueryExtension/init.cpp Show resolved Hide resolved
src/cascadia/QueryExtension/ExtensionPalette.cpp Outdated Show resolved Hide resolved

This comment has been minimized.

@nguyen-dows
Copy link
Contributor

@check-spelling-bot Report

🔴 Please review

See the 📂 files view or the 📜action log for details.

Unrecognized words (6)

CVS desploy endpt gpt hyperlinked openai

Previously acknowledged words that are now absent
To accept ✔️ these unrecognized words as correct and remove the previously acknowledged and now absent words, run the following commands
Pattern suggestions ✂️ (1)
Warnings (1)
✏️ Contributor please read this

We definitely got to fix that "desploy", I think everything else that the spell-bot detected is fine though.

@@ -393,6 +393,7 @@
"addMark",
"adjustFontSize",
"adjustOpacity",
"AIChat",
Copy link
Member

Choose a reason for hiding this comment

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

nts: make this openTerminalChat

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@DHowett
Copy link
Member

DHowett commented Nov 16, 2023

Notes:

  • Issues:
    • We hardcoded the colors so light mode doesn't work
    • The only assets we have are dark mode, and xaml doesn't support the theme-light qualifier. I had to switch to SVGs for the menu and settings.
    • Our resource string structure, with strings split into two or more pieces, does not work well for localization.

I forced us into dark mode to fix 1.
I removed all Audit and Fuzzing configurations for this project from the SLN.
I removed all AnyCPU configurations from the SLN.
The tracelogging was emitting different payloads (EndpointSet / EndpointStored)
The tracelogging didn't know endpoints were set because it didn't request the endpoint from the app...
We no longer crash inserting an answer into the settings UI

Padding="16,8,16,8"
CornerRadius="8">
<StackPanel.Background>
<SolidColorBrush Color="#005EB7" />
Copy link
Member

Choose a reason for hiding this comment

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

In the future, we need to use existing xaml color ramp items. Otherwise, we lose theme support.

src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
src/cascadia/QueryExtension/ExtensionPalette.cpp Outdated Show resolved Hide resolved
{
_AIEndpoint = endpoint;
_AIKey = key;
_httpClient = winrt::Windows::Web::Http::HttpClient{};
Copy link
Member

Choose a reason for hiding this comment

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

probably don't need to recreate this every time these change, but I'm OK with it for now

{
result = RS_(L"UnknownErrorMessage");

TraceLoggingWrite(
Copy link
Member

Choose a reason for hiding this comment

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

too many copies of error handling code. streamline.

src/cascadia/QueryExtension/ExtensionPalette.cpp Outdated Show resolved Hide resolved
Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

fixed stuff

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Nov 16, 2023
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

🤏👃, :shipit:

Let's get these tracked somewhere. There's lots

<SubSystem>Console</SubSystem>
<!-- sets a bunch of Windows Universal properties -->
<OpenConsoleUniversalApp>true</OpenConsoleUniversalApp>
<PgoTarget>false</PgoTarget>
Copy link
Member

Choose a reason for hiding this comment

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

👀

Copy link
Member

Choose a reason for hiding this comment

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

Eh, it's mostly web request bound.

Comment on lines +156 to +167
<data name="AIContentDisclaimerPartOne.Text" xml:space="preserve">
<value>AI can make mistakes —</value>
<comment>Part one of the disclaimer presented to the user within the chat UI element.</comment>
</data>
<data name="AIContentDisclaimerHyperlink" xml:space="preserve">
<value>send feedback</value>
<comment>The portion of the disclaimer presented to the user as a hyperlink within the chat UI element.</comment>
</data>
<data name="AIContentDisclaimerPartTwo.Text" xml:space="preserve">
<value>to help us improve.</value>
<comment>Part two of the disclaimer presented to the user within the chat UI element.</comment>
</data>
Copy link
Member

Choose a reason for hiding this comment

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

I'd bet that localization eats it on this - breaking the sentence across resources is surely gonna blow up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given that we only want the relevant parts of the sentence to be hyperlinked, I'm not entirely sure how we can solve this without breaking it up in the resource file... will file a work item to investigate if/how this messes with localization

"0.4001 0 0.2209 0.17909 0.4 0.40003 0.4h3.2003zm-3.2003 1.6001h1.6001c0.221 "
"0 0.4001-0.1791 0.4001-0.4s-0.1791-0.4-0.4001-0.4h-1.6001c-0.22094 0-0.40003 "
"0.1791-0.40003 0.4s0.17909 0.4 0.40003 0.4z"
};
Copy link
Member

Choose a reason for hiding this comment

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

horrifying

Copy link
Member

Choose a reason for hiding this comment

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

that's on me, sorry XD

}

AIChatFlyout.Click({ this, &TerminalPage::_AIChatButtonOnClick });
newTabFlyout.Items().Append(AIChatFlyout);
Copy link
Member

Choose a reason for hiding this comment

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

do we append this item always?

I suppose the feature isn't behind velocity, it's in a separate branch. So this will always be in the menu for branches where it's checked in.

Honestly, don't love that, but 🤷

Copy link
Member

Choose a reason for hiding this comment

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

We can make Velocitizing it one of the go live requirements

@@ -880,7 +949,7 @@ namespace winrt::TerminalApp::implementation
});
// Necessary for fly-out sub items to get focus on a tab before collapsing. Related to #15049
newTabFlyout.Closing([this](auto&&, auto&&) {
if (!_commandPaletteIs(Visibility::Visible))
if (!_commandPaletteIs(Visibility::Visible) && (ExtensionPresenter().Visibility() != Visibility::Visible))
Copy link
Member

Choose a reason for hiding this comment

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

added the extension presenter here, but we totally still forgot the sxnui

void ExtensionPalette::_backdropPointerPressed(const Windows::Foundation::IInspectable& /*sender*/,
const Windows::UI::Xaml::Input::PointerRoutedEventArgs& e)
{
e.Handled(true);
Copy link
Member

Choose a reason for hiding this comment

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

This was for light-dismiss yea? can we just toss it entirely now?

Copy link
Contributor Author

@PankajBhojwani PankajBhojwani Nov 27, 2023

Choose a reason for hiding this comment

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

This is to prevent the palette from dismissing when the user clicks within it, we only want light dismiss if they click out of it. So we still need this here

Comment on lines +547 to +556
else if (key == VirtualKey::C && ctrlDown)
{
_queryBox().CopySelectionToClipboard();
e.Handled(true);
}
else if (key == VirtualKey::V && ctrlDown)
{
_queryBox().PasteFromClipboard();
e.Handled(true);
}
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this... just work?

or is this for when the focus isn't in the text box and you want to copy/paste into the text box. okay I think I get it

Copy link
Member

Choose a reason for hiding this comment

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

Nope, NOPE. NOPE. TermControl's Preview Key Handler gets ^V before anyone else. Remember, it is awful.

Width="64"
Height="64"
Margin="0,0,0,20"
Source="ms-appx:///ProfileIcons/terminalChatLogo.png" />
Copy link
Member

Choose a reason for hiding this comment

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

does this one work with light & dark theme?

oh wait no this is the thing that has to be in dark mode isn't it

</TextBlock>
</Grid>
</Grid>
</UserControl>
Copy link
Member

Choose a reason for hiding this comment

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

yep this is XAML

@DHowett DHowett merged commit 32cfa5a into feature/llm Nov 16, 2023
15 of 17 checks passed
@DHowett DHowett deleted the dev/pabhoj/terminal_chat branch November 16, 2023 23:00
@DHowett DHowett restored the dev/pabhoj/terminal_chat branch November 16, 2023 23:01
@DHowett
Copy link
Member

DHowett commented Nov 16, 2023

Kept the branch so Pankaj can see my changes

pull bot pushed a commit to rbleattler/terminal that referenced this pull request Nov 18, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Nov 27, 2023
DHowett pushed a commit that referenced this pull request Dec 15, 2023
- [x] Remove the ESC handler that clears the query message
- [x] Streamline error handling code
- [x] Fix `this` and `&` in several lambdas
- [x] Fix getting the [active commandline
properly](#16285 (comment))
- [x] Use XAML color ramp resource names instead of hardcoded colors
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.

4 participants