Skip to content

JackInSightsV2/PowerWut-PowerShell-LLM-Module

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PowerWut PowerShell Module

PowerWut is a PowerShell module designed to interact with OpenAI’s models to analyze your PowerShell command history and answer custom queries. It securely manages your API key using the Windows Credential Vault and provides several helper functions for model management, secret storage, and intelligent AI querying.


Overview

The PowerWut module simplifies the process of querying OpenAI models from PowerShell. It performs the following tasks:

  • Module Installation & Import: Checks for and installs the Microsoft.PowerShell.SecretManagement and Microsoft.PowerShell.SecretStore modules if necessary.
  • Secret Storage: Securely stores and retrieves your OpenAI API key using the Windows Credential Vault.
  • Model Management: Lists available OpenAI models and allows you to switch between them.
  • Command History Analysis: Captures recent PowerShell commands as context to aid in error analysis and troubleshooting.
  • Query Execution: Sends the command history or custom queries to OpenAI’s API and returns the AI’s response.

Features

  • Automated Dependency Management: Automatically installs required secret management modules if not already present.
  • Secure API Key Storage: Uses Windows Credential Vault to safely store your OpenAI API key.
  • Dynamic AI Model Selection: Allows listing and switching between available AI models.
  • Contextual Analysis: Aggregates your recent command history to provide context to the AI model.
  • Verbose Mode: Offers detailed debugging output including API request payloads and responses.
  • Help System: Includes a built-in help function that explains usage, parameters, and examples.

Requirements

  • PowerShell 5.1 or later (or PowerShell Core)
  • Internet Access to reach the OpenAI API endpoints
  • OpenAI API Key – Obtain one from OpenAI's API Keys Page

Installation & Deployment

  1. Download the Module:

    • Save the provided PowerShell module as PowerWut.psm1.
  2. Import the Module:

    • Open a PowerShell terminal and import the module:
      Import-Module .\PowerWut.psm1
    • Alternatively, you can add the module's folder to your $env:PSModulePath for easier future access.
  3. Module Dependencies:

    • The module automatically checks for, installs (if needed), and imports the following modules:
      • Microsoft.PowerShell.SecretManagement
      • Microsoft.PowerShell.SecretStore
    • It also registers a secret vault named WutKeyVault for secure API key storage.
  4. Persisting the Module:

    • To load PowerWut automatically in future sessions, consider adding the import command to your PowerShell profile.

Usage

Setting Up Your API Key

Before running any AI queries, set your OpenAI API key:

  • Interactive Setup:

    • On first use, if no API key is found, the module will prompt:
      No API Key found. Please enter your OpenAI API Key.
      
    • Enter your key when prompted.
  • Manually Set the API Key:

    • Use the provided function:
      Set-OpenAIAPIKey -ApiKey "your_openai_api_key"

Listing & Changing AI Models

  • List Available Models:

    • Run:
      wut -m
    • This displays the current model and lists available AI models (after applying filtering rules).
  • Change the Current Model:

    • Use the -sm parameter:
      wut -sm "gpt-4-turbo"
    • The module sets the new model as the current model for subsequent queries.

Sending Queries to OpenAI

  • Analyze Recent Command History:

    • Run a query without specifying a custom query:
      wut
    • This sends the last 10 commands (default) as context to the AI model.
  • Custom Query with Command History:

    • Include both command history and a custom query:
      wut -c 20 -q "Explain the last 20 commands"
    • The -c parameter adjusts how many recent commands to include.
  • Direct Query Without History:

    • To send a direct query without context, use a context length of zero:
      wut -q "What is Azure?" -c 0
  • Verbose Mode:

    • Add -v to see detailed API request and response information:
      wut -q "What is PowerShell?" -v

Getting Help

  • Display the built-in help message by running:
    wut -?

About

PowerShell Module to Introduce AI responses to the shell.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published