The AI CLI application allows users to interact with OpenAI's models through the command line. This tool supports flexible configuration via command-line arguments, a .env file, and default settings.
This project addresses the integration challenge associated with AI by making AI functional and accessible. It focuses on breaking down complex problems into simple, manageable methods that can be easily integrated into various workflows.
The project decomposes problems into individual tasks and applies AI to each task sequentially. It employs a series of prompts to analyze and process claims, incidents, articles, and conversations. Each prompt acts as an AI function designed to solve specific problems, making AI less mysterious and more practical.
- Configurable maximum tokens per chunk
- Customizable log file path
- Selectable AI model
- Flexible patterns folder location
- Supports API key configuration via
.envfile or command-line arguments
The prompt patterns in /patterns include content adapted from the fabric project by Daniel Miessler and contributors. The applicable third-party attribution and MIT license notice are included in /THIRD_PARTY_NOTICES.txt.
- .NET Core SDK
- OpenAI API Key
The application uses the following default settings:
- Max Tokens Per Chunk: 50000
- Log File Path:
logs/default.log - Model Name:
gpt-4 - Patterns Folder:
patterns
The .env file can be used to override the default settings. The application will look for the .env file in the same directory as the executable. Here is an example of a .env file with all default settings:
# Default settings for the AI application
# Max tokens per chunk
MAX_TOKENS_PER_CHUNK=50000
# Log file path (relative to the executable directory)
LOG_FILE_PATH=logs/default.log
# Model name for the AI
MODEL_NAME=gpt-4
# Patterns folder (relative or absolute path)
PATTERNS_FOLDER=patterns
# OpenAI API key (this needs to be set with your actual API key)
OPENAI_API_KEY=your_openai_api_key_hereCommand-line arguments can be used to override both the default settings and the .env file settings. The following arguments are supported:
- -maxTokens: Sets the maximum tokens per chunk.
- -logFilePath: Sets the log file path.
- -modelName: Sets the AI model name.
- -patternsFolder: Sets the patterns folder.
- -apiKey: Sets the OpenAI API key.
- -userPrompt: Sets the user prompt.
- -patterns: Sets the patterns to be used, separated by commas.
- Default Settings: The application first loads the default settings.
- .env File: If present, the
.envfile settings override the default settings. - Command-Line Arguments: Finally, command-line arguments override both the default settings and the
.envfile settings.
AI -maxTokens 10000 -logFilePath custom_logs/logfile.log -modelName gpt-4 -patternsFolder /path/to/patterns -apiKey sk-xxxxx -userPrompt "Hello, AI!" -patterns pattern1,pattern2The following PowerShell script configures the environment so that AI can be recognized as a command in both PowerShell and CMD:
# Define the path to the AI.exe application
$scriptPath = $MyInvocation.MyCommand.Path
$aiExeDirectory = Split-Path -Parent $scriptPath
$aiExePath = Join-Path -Path $aiExeDirectory -ChildPath "AI.exe"
# Check if AI.exe exists in the expected location
if (-Not (Test-Path $aiExePath)) {
Write-Error "AI.exe not found in the same directory as this script."
exit 1
}
# Add the directory to the user's PATH environment variable if not already present
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if (-Not ($userPath.Split(';') -contains $aiExeDirectory)) {
[Environment]::SetEnvironmentVariable("Path", "$userPath;$aiExeDirectory", "User")
$env:Path = "$userPath;$aiExeDirectory" # Update current session's PATH
}
# Create a PowerShell profile if it doesn't exist
$profilePath = "$PROFILE"
if (-Not (Test-Path $profilePath)) {
New-Item -ItemType File -Path $profilePath -Force
}
# Add an alias for AI.exe to the PowerShell profile
$aliasCommand = "Set-Alias -Name AI -Value `"$aiExePath`""
if (-Not (Get-Content $profilePath | Select-String -SimpleMatch "Set-Alias -Name AI")) {
Add-Content -Path $profilePath -Value $aliasCommand
}
# Create a batch file for cmd.exe to alias AI.exe
$cmdAliasScript = @"
@echo off
doskey ai=`"$aiExePath`" $*
"@
$cmdAliasPath = "$HOME\i_alias.cmd"
Set-Content -Path $cmdAliasPath -Value $cmdAliasScript
# Ensure the batch file runs at user login
$userLoginScript = [System.IO.Path]::Combine([System.Environment]::GetFolderPath("UserProfile"), "AppData", "Roaming", "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "login.cmd")
if (Test-Path $userLoginScript) {
if (-Not (Get-Content $userLoginScript | Select-String -SimpleMatch "@call `"$cmdAliasPath`"")) {
Add-Content -Path $userLoginScript -Value "@call `"$cmdAliasPath`""
}
} else {
# Create a new login script if it doesn't exist
Set-Content -Path $userLoginScript -Value "@call `"$cmdAliasPath`""
}
Write-Output "AI has been configured to run from any command window or PowerShell session."
Write-Output "Please restart your command window or PowerShell session to apply the changes."The AI CLI application provides a flexible and powerful way to interact with OpenAI's models via the command line. By utilizing the .env file and command-line arguments, users can easily configure the application to meet their specific needs.