New AI Tools for PowerShell and VS Code

I don't know if you can tell but I'm having a ton of fun lately with AI. I prefer AI coding over manual coding because I can skip all the tedium and just communicate in my first language. Advanced things too, in languages I don't know well like TypeScript.

I remember seeing a YouTube headline about a guy who built a whole VS Code extension and wondering HOW on earth he could pull that off. Initially, I guessed that it could only build POC extensions that don't do much but since then, I've built a couple significant extensions with all the features I wanted.

The first one I made was the Assistants Chat Extension for GitHub Copilot Chat. Ever since I first used GitHub Copilot Chat, I've wanted it to be 1.) more up-to-date and 2.) deeply knowledgable about my module or module dependencies. Now, it is. Check this out:

AI-powered PowerShell coding in VS Code

In the screenshot, you can see a GitHub Copilot chat where an original and an enhanced assistant provide information about dbatools versions. The GitHub Copilot assistant's knowledge is outdated (September 2021), while the custom Assistant has current information up to June 2024. This custom assistant is actually powered by an OpenAI Assistant that was created by another module I built, PSHelp.Copilot.

The VS Code extension was built mostly with Claude.ai. Claude's Opus is fantastic at understanding massive amounts of text and it's also an incredible coder, so long as you go task-by-task. The downside is that you run out of tokens pretty fast and have to wait another 4 hours to use it again, even with a paid subscription. So now I have two subs and just go back and forth. I actually still run out sometimes but use ChatGPT while I wait. I still use OpenAI's API or ChatGPT extensively, often for simple facts or vision. Like, it's better than Claude at making mermaid flowcharts.

flow

I also used AI to help me build PSHelp.Copilot for my modules. PSHelp.Copilot is a module that allows you to talk to well-documented PowerShell modules using natural language. These two projects complement each other surprisingly well, though I didn't initially plan it that way.

A PowerShell Copilot with a nice GUI

The Assistants Chat Extension that I created basically provides a GUI for interacting with the OpenAI Assistant API, including those created by PSHelp.Copilot. What's especially cool is that both tools have context awareness, so the VS Code extension can analyze your current code, while PSHelp.Copilot uses vector stores and embeddings to give you module-specific help.

PSHelp.Copilot simplifies getting help from well-documented modules. By using natural language processing and OpenAI's API, you can create AI assistants for specific PowerShell modules. Just ask questions about the module's commands, and PSHelp.Copilot will provide relevant answers and code examples based on the target module's documentation.

PSHelp.Copilot features

Both the PowerShell module and the extension integrate with OpenAI's API and Azure OpenAI services.

Vector Store Management Uses both local and remote vector stores to store and retrieve module documentation

Embedding Generation Converts PowerShell help text into embeddings, which are some math calculations and the basis of LLMs, from my understanding. The results when using this feature were meh, so I made it optional in Invoke-HelpChat. If you'd like to try it out, use the -AddHint switch. Note that there is a one-time setup.

Custom GPT Creation If you only have access to ChatGPT and not the OpenAI API, the Split-ModuleHelp function helps create module-specific Custom GPTs by splitting module help into multiple files.

To start using PSHelp.Copilot, install the module from the PowerShell Gallery and set your OpenAI API key with $env:OPENAI_API_KEY. Then, create an assistant for a module using New-ModuleAssistant and interact with it using Invoke-HelpChat or the askhelp alias:

1PS> New-ModuleAssistant -Module dbatools
2PS> askhelp how do i encrypt all of my databases at once?

The Assistants Chat Extension allows you to create custom assistants that understand your project's context and generate relevant code snippets. If you're curious, behind the scenes, it's just including portions of your code along with your query.

Assistants Chat Extension features

The Assistants Chat Extension is free but I think you have to have a GitHub Copilot Chat subscription to use it.

Persistent Chat Sessions The extension remembers conversation context across VS Code restarts.

Automatic Sample Assistant Creation If no assistants exist, it offers to create a Beavis and Butthead-themed assistant. I picked B&B to basically demo that it's for sure not GitHub Copilot.

Dynamic Assistant Switching Users can switch between different AI assistants using the /change command.

The extension provides context-aware code suggestions in VS Code, too. If you're wondering how, the magic appears to be just appending the code to your question. It was interesting learning how it works behind the scenes. If you want to try making your own, check out the API.

It's hard writing when all you want to do is code, but I needed to share what I've been working on because I feel like PowerShellers will enjoy it. Hope you do, thanks for reading!