voytas75 / AIPSTeam

PowerShell script simulates a team of AI Agents working together on a user provided PowerShell project. It utilizes Retrieval-Augmented Generation (RAG). The project leverages Azure OpenAI, Ollama, and LM Studio.
7 stars 2 forks source link
agents azure llm lmstudio ollama

AI PowerShell Team with RAG

AIPSTeam

ko-fi

PowerShell Gallery Codacy Badge

Table of Contents

Overview

This PowerShell script simulates a team of AI Agents working together on a PowerShell project. Each Agent has a unique role and contributes to the project in a sequential manner. The script processes user input, performs various tasks, and generates outputs such as code, documentation, and analysis reports. The application utilizes Retrieval-Augmented Generation (RAG) to enhance its capabilities and can leverage Azure OpenAI, Ollama, or LM Studio to generate the output.

For more information on the AI models and services used in this script, please refer to the following links:

[!IMPORTANT] You need AZURE OpenAI subscription, Ollama or LMStudio to use this script.

The quality of the project generated by the AI PowerShell Team depends significantly on the model used and the context window available. The model's ability to understand and process the input accurately is crucial for generating high-quality outputs. Ensure that the model and context window settings are optimized for the best performance and results.

Retrieval-Augmented Generation (RAG)

RAG combines retrieval and generation processes to produce accurate and contextually relevant outputs. The framework operates as follows:

  1. Retrieval: The system retrieves pertinent information from extensive data sources.
  2. Generation: A generative model uses the retrieved information to produce coherent and appropriate responses.

By integrating these two phases, RAG ensures the AI specialists deliver precise and informed outputs based on a comprehensive knowledge base.

Data Source for RAG

The AI PowerShell Team utilizes the Bing Web Search API as the primary data source for its Retrieval-Augmented Generation (RAG) capabilities. This API enables the system to retrieve relevant information from billions of web documents, ensuring that the generated outputs are accurate and contextually relevant.

For more information on the Bing Web Search API, please refer to the following link:

By leveraging the Bing Web Search API, the AI PowerShell Team can provide enhanced search details, safe and location-aware search results, and a variety of instant answers, including images, videos, news, and more. This integration significantly improves the quality and relevance of the outputs generated by the AI Agents.

Features

User Guide

Installation

  1. Install Required Modules: Ensure you have the required PowerShell modules installed:

    Install-Module -Name PSAOAI
    Install-Module -Name PSScriptAnalyzer
    Install-Module -Name powerHTML
  2. Install the Script: Install script from Powershell Gallery.

    Install-Script AIPSTeam
  3. Run the Script: Execute the script using PowerShell:

    "Your project description here" | AIPSTeam.ps1

Configuration

Environment Variables

To configure the script to use external providers, you need to set the following environment variables:

  1. Azure OpenAI:

    • PSAOAI_API_AZURE_OPENAI_KEY: Your Azure OpenAI API key.
    • PSAOAI_API_AZURE_OPENAI_ENDPOINT: Your Azure OpenAI endpoint.
    • PSAOAI_API_AZURE_OPENAI_APIVERSION: The version of the Azure OpenAI API you want to use.
    • PSAOAI_API_AZURE_OPENAI_CC_DEPLOYMENT: Your Azure OpenAI Chat Completion deployment name.
    • PSAOAI_BANNER: Disable PSAOAI banner. AIPSTeam sets to "0".

    When you start the script, you will be prompted to provide these environment variables if they are not already set. Alternatively, you can set them earlier to avoid prompts during execution. Additionally, ensure that you have the latest version of the PSAOAI module installed to avoid compatibility issues. You can check for updates and install the latest version using the following command:

    Install-Module -Name PSAOAI

    Example:

[!IMPORTANT] The PSAOAI_API_AZURE_OPENAI_KEY environment variable cannot be provided manually because the PSAOAI module encrypts it for security purposes. Ensure that the key is set and managed through the PSAOAI module's secure mechanisms.

  1. Ollama:
    • OLLAMA_ENDPOINT: Ollama API Endpoint.
    • OLLAMA_MODEL: Ollama model.

The OLLAMA_ENDPOINT environment variable is set to a default value of http://localhost:11434/ by the script. If you need to use a different endpoint, you must manually change the value of this environment variable. You can do this by using the following command:

[Environment]::SetEnvironmentVariable('OLLAMA_ENDPOINT','your-ollama-api-endpoint-uri','user')

[!IMPORTANT] For the Ollama provider, you do not need to manually define the OLLAMA_MODEL environment variable. The script will automatically check the status of Ollama and interactively prompt you to start and choose the model to use if it is not already running. This ensures a seamless setup process and reduces the need for manual.

Example:

   [Environment]::SetEnvironmentVariable('OLLAMA_MODEL','ollama model, example: phi3:latest','user')
  1. LM Studio:

    • OPENAI_API_KEY: Your LM Studio API key, default is 'lm-studio'.
    • OPENAI_API_BASE: The LLM model to use with LM Studio, default is 'http://localhost:1234/v1'.

    Example:

  2. RAG Configuration:

    • AZURE_BING_API_KEY: Your Azure Bing Web Search API key.
    • AZURE_BING_ENDPOINT: Your Azure Bing Web Search endpoint. ()

    Example:

Bing Search API documentation

Ensure these environment variables are set before running the script to enable the respective functionalities.

Usage

  1. Basic Usage:

    "Monitor RAM usage and show a single color block based on the load." | AIPSTeam.ps1

    or

    AIPSTeam -userInput "Monitor RAM usage and show a single color block based on the load."
  2. Disable Live Streaming:

    "Monitor RAM usage" | AIPSTeam.ps1 -Stream $false
  3. Specify Log Folder:

    "Monitor RAM usage" | AIPSTeam.ps1 -LogFolder "C:\Logs"
  4. Monitor Disk Usage:

    "Monitor disk usage and display a pie chart of used vs free space." | AIPSTeam.ps1 -Stream $false

    Description: This example monitors the disk usage and displays a pie chart showing the used versus free space. The -Stream $false parameter disables live streaming of the output.

  5. Generate System Report:

    "Script for reporting CPU, RAM, and disk usage." | AIPSTeam -LogFolder "C:\SystemReports"

    Description: This example generates a comprehensive system report that includes details about CPU, RAM, and disk usage. The report is saved in the specified log folder C:\SystemReports.

  6. Check Network Latency:

    "Check network latency and display a line graph of latency over time." | AIPSTeam.ps1 -NOPM

    Description: This example checks the network latency and displays a line graph showing the latency over time. The -NOPM parameter disables the Project Manager functions.

  7. Analyze Event Logs:

    "Analyze Windows Event Logs and summarize critical errors." | AIPSTeam.ps1 -NODocumentator

    Description: This example analyzes the Windows Event Logs and provides a summary of critical errors. The -NODocumentator parameter disables the Documentator functions.

  8. Backup Important Files:

    "Backup important files from Documents to an external drive." | AIPSTeam -NOLog

    Description: This example backs up important files from the Documents folder to an external drive. The -NOLog parameter disables the logging functions.

  9. Monitor GPU Usage:

    "Monitor GPU usage and display a bar chart of GPU load." | AIPSTeam -Stream $true

    Description: This example monitors the GPU usage and displays a bar chart showing the GPU load. The -Stream $true parameter enables live streaming of the output.

  10. Check System Uptime:

      "Check system uptime and display the total uptime in days." | AIPSTeam.ps1 -NOLog -NOPM

    Description: This example checks the system uptime and displays the total uptime in days. The -NOLog parameter disables the logging functions, and the -NOPM parameter disables the Project Manager functions.

  11. Generate Security Audit Report:

      "Generate a security audit report for the system." | AIPSTeam.ps1 -LogFolder "C:\SecurityReports" -NODocumentator

    Description: This example generates a security audit report for the system. The report is saved in the specified log folder C:\SecurityReports. The -NODocumentator parameter disables the Documentator functions.

  12. Monitor Network Bandwidth:

      "Monitor network bandwidth usage and display a real-time graph." | AIPSTeam.ps1 -Stream $true -NOLog

    Description: This example monitors the network bandwidth usage and displays a real-time graph. The -Stream $true parameter enables live streaming of the output, and the -NOLog parameter disables the logging functions.

  13. Check Disk Health:

      "Check disk health and display a summary of SMART attributes." | AIPSTeam -NOPM -NODocumentator

    Description: This example checks the disk health and displays a summary of SMART attributes. The -NOPM parameter disables the Project Manager functions, and the -NODocumentator parameter disables the Documentator functions.

  14. Generate Text Summary Using LLM Provider:

      "Recent software activities on Windows 11." | AIPSTeam -LLMProvider "ollama" -Stream $false

    Description: This example generates a text summary of recent project activities using the specified LLM provider, in this case, "ollama". The -Stream $false parameter disables live streaming of the output.

  15. Run Script Without User Input Check:

    "Cleaning folders where is file 'clean.it'" | AIPSTeam.ps1 -NOUserInputCheck

    Description: This example runs the script without performing any user input checks. The -NOUserInputCheck parameter disables the input validation functions.

  16. Run Script with Disabled Interaction:

    "Generate a daily system health report." | AIPSTeam.ps1 -NOInteraction

    Description: This example runs the script without requiring any user interaction throughout the session. The -NOInteraction parameter ensures that the script will not prompt the user for any input or display any menus.

  17. Work on User's Code:

    AIPSTeam.ps1 -TheCodePath "C:\UserScripts\script.ps1"

    Description: This example works on the user's provided PowerShell script located at C:\UserScripts\script.ps1. The -TheCodePath parameter specifies the path to the user code that the AI team will enhance. If interactive mode is not disabled, the user can provide additional instructions during the session, such as "adding additional logging functionality".

Developer Notes

Code Structure

Key Functions and Logic

Installation Instructions

Installation

Dependencies and Prerequisites

Troubleshooting Tips and Common Issues

FAQ

  1. How do I install the required modules?

    Install-Module -Name PSAOAI
    Install-Module -Name PSScriptAnalyzer
    Install-Module -Name powerHTML
  2. How do I disable live streaming?

    AIPSTeam.ps1 -Stream $false
  3. Where are the log files stored?

    Log files are stored in the specified log folder or the default folder in MyDocuments.

  4. How do I load a saved project status?

    AIPSTeam.ps1 -LoadProjectStatus "path\to\your\Project.xml"
  5. How do I disable the Project Manager functions?

    AIPSTeam.ps1 -NOPM
  6. How do I specify a custom LLM model for ollama?

    $env:OLLAMA_MODEL = "your_custom_model"
    AIPSTeam.ps1 -LLMProvider "ollama"