Skip to content

voytas75/AIPyTeam

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Python Team with RAG

AIPyTeam

ko-fi

PowerShell Gallery Codacy Badge

Table of Contents

Overview

This PowerShell script simulates a team of AI Agents working together on a Python 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 Python 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 Python 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 Python 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

  • Team Simulation: Emulates a team of specialists including Requirements Analyst, System Architect, Python Developer, QA Engineer, Documentation Specialist, and Project Manager.
  • Sequential Processing: Each specialist processes the input and passes the result to the next specialist in the workflow.
  • Live Streaming: Option to stream output live.
  • Logging: Logs actions and responses of each specialist.
  • Documentation Generation: Automatically generates comprehensive documentation for the project.
  • Code Analysis: Integrates with PSScriptAnalyzer for code quality checks.
  • Feedback Integration: Collects and integrates feedback from team members to improve the response.
  • State Management: Manages global state across different stages of the project.
  • Error Handling: Robust error handling mechanisms to capture and log errors.
  • Version Control: Saves and updates code versions with detailed logs.
  • Interactive Menu: Provides an interactive menu for suggesting new features, analyzing code, generating documentation, and more.

User Guide

Installation

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

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

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

    "Your project description here" | AIPyTeam.ps1

Configuration

  • Parameters:
    • userInput: Defines the project outline as a string (can also be piped).
    • Stream: Controls whether the output should be streamed live (default: $true).
    • NOPM: Disables the Project Manager functions.
    • NODocumentator: Disables the Documentator functions.
    • NOLog: Disables the logging functions.
    • LogFolder: Specifies the folder where logs should be stored.
    • DeploymentChat: Specifies the deployment chat environment variable for Azure OpenAI (default: retrieved from environment variable PSAOAI_API_AZURE_OPENAI_CC_DEPLOYMENT - PSAOAI).
    • MaxTokens: Specifies the maximum number of tokens to generate in the response. This parameter controls the length of the generated output. The default value is set within the script, but it can be overridden by the user if needed.
    • LLMProvider: Specifies the LLM provider to use (e.g., ollama, LMStudio, AzureOpenAI). Default is "AzureOpenAI".
    • NOTips: Disables tips.
    • VerbosePrompt: Show Prompts.
    • LoadProjectStatus: Loads the project status from a specified path. Part of the 'LoadStatus' parameter set.
    • LLMProvider: Specifies the LLM provider to use (e.g., ollama, LMStudio, AzureOpenAI). Default is "AzureOpenAI".
    • NORAG: Disables the RAG (Retrieve and Generate) functionality.

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. AIPyTeam 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:

    [System.Environment]::SetEnvironmentVariable('PSAOAI_API_AZURE_OPENAI_ENDPOINT','https://<your-endpoint>.openai.azure.com','user')
    [System.Environment]::SetEnvironmentVariable('PSAOAI_API_AZURE_OPENAI_APIVERSION','2024-05-01-preview','user')
    [System.Environment]::SetEnvironmentVariable('PSAOAI_API_AZURE_OPENAI_CC_DEPLOYMENT','your-deployment-name','user')

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:

[System.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:

[System.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:

    [System.Environment]::SetEnvironmentVariable('OPENAI_API_KEY','lm-studio','user')
    [System.Environment]::SetEnvironmentVariable('OPENAI_API_BASE','http://localhost:1234/v1','user')
  2. RAG Configuration:

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

    Example:

    [System.Environment]::SetEnvironmentVariable('AZURE_BING_API_KEY','your-azure-bing-api-key','user')
    [System.Environment]::SetEnvironmentVariable('AZURE_BING_ENDPOINT','https://api.bing.microsoft.com/','user')

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." | AIPyTeam.ps1

    or

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

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

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

    "Monitor disk usage and display a pie chart of used vs free space." | AIPyTeam.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." | AIPyTeam -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." | AIPyTeam.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." | AIPyTeam.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." | AIPyTeam -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." | AIPyTeam -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." | AIPyTeam.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." | AIPyTeam.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." | AIPyTeam.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." | AIPyTeam -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." | AIPyTeam -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.

Developer Notes

Code Structure

  • Main Script: AIPyTeam.ps1
  • Classes: ProjectTeam
  • Functions: Various utility functions for processing input, logging, and analysis.

Key Functions and Logic

  • ProjectTeam Class: Represents a team member with specific expertise.
    • ProcessInput: Processes the input and generates a response.
    • Feedback: Provides feedback on the input.
    • AddLogEntry: Adds an entry to the log.
    • Notify: Sends a notification.
    • SummarizeMemory: Summarizes the team member's memory.
  • Utility Functions:
    • SendFeedbackRequest: Sends a feedback request to a team member.
    • Export-AndWritePowerShellCodeBlocks: Exports and writes Python code blocks to a file.

Installation Instructions

Installation

Dependencies and Prerequisites

  • PowerShell Version: Ensure you are using PowerShell 5.1 or later.
  • Modules:
    • PSAOAI
    • PowerHTML

Use Cases and Expected Outputs

  1. Monitor RAM Usage:

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

    Expected Output: Discussion flow with Python code to monitor RAM usage with color block.

  2. Monitor CPU Usage:

    "Monitor CPU usage and display dynamic graph." | AIPyTeam.ps1

    Expected Output: Discussion flow with Python code to show a dynamic graph showing CPU usage.

Troubleshooting Tips and Common Issues

  • Module Not Found: Ensure the required modules are installed using Install-Module.
  • Permission Issues: Run PowerShell as an administrator.
  • Script Errors: Check the log files in the specified log folder for detailed error messages.

FAQ

  1. How do I install the required modules?

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

    AIPyTeam.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?

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

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

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