### Install Web UI Dependencies and Start Server Source: https://github.com/sreenathmmenon/llmswap/blob/main/CHANGELOG.md Install the necessary Python packages for the LLMSwap web UI and then start the local development server. The UI will be accessible at http://localhost:5005. ```bash # Install web dependencies pip install llmswap[web] # Start web UI llmswap web # Opens at http://localhost:5005 ``` -------------------------------- ### Development Workflow Examples Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/cli_usage_guide.md Examples for development tasks, such as pre-commit code reviews using 'review' and getting quick language help with 'ask'. ```bash # Pre-commit code review find . -name "*.py" -exec llmswap review {} --focus bugs \; # Quick language help llmswap ask "How to handle async errors in JavaScript?" llmswap ask "Best practices for SQL injection prevention" ``` -------------------------------- ### Run Basic Example Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/README.md Command to navigate to the basic examples directory and run the simple_query.py script. ```bash cd examples/basic python simple_query.py ``` -------------------------------- ### Install Web UI Dependencies Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Install the necessary dependencies for the LLMSwap web UI. This is an optional, one-time setup. ```bash # Install web UI dependencies (one-time, optional) pip install llmswap[web] ``` -------------------------------- ### Learning and Documentation Examples Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/cli_usage_guide.md Examples for learning and documentation, including understanding codebases with 'review' and comparing technologies with 'ask'. ```bash # Understand codebases llmswap review legacy_code.php --focus style llmswap ask "Explain this regex pattern: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" # Technology comparisons llmswap ask "Kubernetes vs Docker Swarm comparison" llmswap ask "When to use REST vs GraphQL?" ``` -------------------------------- ### Run Existing Examples Source: https://github.com/sreenathmmenon/llmswap/blob/main/COMPATIBILITY-RULES.md Commands to execute example scripts from previous versions to verify they still work as expected. ```bash # All examples from previous versions must work python3 examples/basic_usage.py python3 examples/provider_switching.py python3 examples/streaming.py ``` -------------------------------- ### Initialize and Use LLMSwap Workspace Source: https://github.com/sreenathmmenon/llmswap/blob/main/CHANGELOG.md Initialize a new workspace and interact with it using the LLMSwap CLI. This example shows basic workspace setup and chat functionality. ```bash # Initialize workspace cd /path/to/project llmswap workspace init --name "My Project" # Chat with new Claude Sonnet 4.5 (best for coding) llmswap chat --provider anthropic --model claude-sonnet-4-5 # View workspace info llmswap workspace info ``` -------------------------------- ### Initial LLMSwap Setup and Usage Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Demonstrates the first-time setup of LLMSwap, including automatic configuration file creation and basic usage. Ensure API keys are exported before running. ```bash # First run automatically creates ~/.llmswap/config.yaml with defaults llmswap ask "Hello world" # Output: 🔧 Creating config file at ~/.llmswap/config.yaml # ✅ Default configuration created # View all providers and their configuration status llmswap providers # Set up your API keys and start using export ANTHROPIC_API_KEY="your-key-here" llmswap ask "Explain Docker in simple terms" ``` -------------------------------- ### Start Local Web Server Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Start the local web server for the LLMSwap Arena. It will automatically open in your default browser. ```bash # Start local web server (opens at http://localhost:5005) llmswap web ``` -------------------------------- ### Install LLMSwap using uv Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Recommended installation method for LLMSwap using the uv package manager for optimal speed. ```bash # Recommended: Install with uv (fastest) uv tool install llmswap ``` -------------------------------- ### Initialize LLMClient with Auto-Detection Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Instantiate the LLMClient to automatically detect and use available LLM providers. This is the simplest way to get started. ```python from llmswap import LLMClient # Auto-detects available providers client = LLMClient() ``` -------------------------------- ### DevOps Workflow Examples Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/cli_usage_guide.md Examples for DevOps tasks, including server troubleshooting with 'ask' and 'debug', and CI/CD code reviews with 'review'. ```bash # Quick server troubleshooting llmswap ask "Why might a Node.js server show high memory usage?" llmswap debug --error "EADDRINUSE: address already in use :::3000" # Code review in CI/CD llmswap review src/auth.py --focus security --quiet ``` -------------------------------- ### Install and Use LLMSwap CLI Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Install the llmswap package using pip and start interacting with an LLM via the command line. Ensure an API key is set. ```bash # Install pip install llmswap # Set ANY API key (one is enough) export ANTHROPIC_API_KEY="your-key" # or OpenAI, or Gemini... # Start building llmswap chat "Hello!" ``` -------------------------------- ### Install LLMSwap Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/README.md Command to install the LLMSwap library using pip. This is a prerequisite for running any examples. ```bash pip install llmswap ``` -------------------------------- ### llmswap ask Command Examples Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/cli_usage_guide.md Use the 'ask' command for quick, one-line questions. You can specify a provider, disable caching, or use quiet mode. ```bash # Basic usage llmswap ask "What is the difference between Git and GitHub?" llmswap ask "How do I fix a merge conflict?" llmswap ask "Explain Docker containers in simple terms" # With specific provider llmswap ask "Write a Python function to reverse a string" --provider openai llmswap ask "What are the best practices for API design?" --provider anthropic # Disable caching for real-time data llmswap ask "What time is it now?" --no-cache # Quiet mode (no tips) llmswap ask "Explain recursion" --quiet ``` -------------------------------- ### Start LLMSwap Web UI Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Launch the local web server for the LLMSwap Arena, which opens in your browser at http://localhost:5005. ```bash # 🆕 Web UI - Compare models side-by-side llmswap web # Opens browser at http://localhost:5005 ``` -------------------------------- ### GitHub Release Notes Example Source: https://github.com/sreenathmmenon/llmswap/blob/main/COMPATIBILITY-RULES.md An example of release notes for a GitHub release, highlighting a critical compatibility fix and instructing users to upgrade. ```markdown # GitHub Release Notes ## v5.4.1 - Critical Compatibility Fix We accidentally broke X in v5.4.0. This is now fixed. Please upgrade immediately: pip install --upgrade llmswap ``` -------------------------------- ### Predefined Sample Prompts Source: https://github.com/sreenathmmenon/llmswap/blob/main/llmswap/web/templates/index.html Provides example prompts for common tasks like API design review and launch plan creation. These can be used to quickly test the application's capabilities. ```javascript const samples = { code: "Review this API design for reliability, security, and developer experience. Give concrete improvements and a concise final recommendation.", brief: "Create a launch plan for a Python package release. Include positioning, docs updates, verification, and risk checks." }; ``` -------------------------------- ### Start LLMSwap Web UI Server with Python API Source: https://github.com/sreenathmmenon/llmswap/blob/main/CHANGELOG.md Programmatically start the LLMSwap web UI server using its Python API. You can specify the port and debug mode. Alternatively, you can get the Flask app instance for custom deployment. ```python from llmswap.web import start_server # Start server (blocking) start_server(port=5005, debug=False) # Or get Flask app for custom deployment from llmswap.web import create_app app = create_app() ``` -------------------------------- ### Start Web Server on Custom Port Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Launch the LLMSwap web UI on a custom port if the default port 5005 is already in use. ```bash # Custom port (if 5005 is already in use) llmswap web --port 8080 ``` -------------------------------- ### Launch LLMSwap Web UI Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Installs the web interface for LLMSwap and launches it in the browser. This allows for visual comparison of different LLM models. ```bash # 🆕 Compare models visually (optional) pip install llmswap[web] llmswap web # Opens browser - compare GPT-5.2 vs Claude vs Gemini ``` -------------------------------- ### Chat with GPT-5.2 using LLMClient Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Example of initializing LLMClient for GPT-5.2 and sending a chat prompt. GPT-5.2 is recommended for professional tasks, coding, reasoning, science, and math. ```python from llmswap import LLMClient client = LLMClient(provider="openai", model="gpt-5.2") response = client.chat("Design an algorithm for real-time fraud detection...") print(response.content) ``` -------------------------------- ### Install LLMSwap via Homebrew Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Recommended installation method for macOS and Linux users. This command adds the LLMSwap tap and installs the package, making it immediately available for use. ```bash # Add our tap and install brew tap llmswap/tap brew install llmswap ``` ```bash # Ready to use immediately! llmswap --help ``` -------------------------------- ### Install LLMSwap using Homebrew Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Installation method for LLMSwap using Homebrew package manager. ```bash # or Homebrew brew tap llmswap/tap && brew install llmswap ``` -------------------------------- ### llmswap debug Command Examples Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/cli_usage_guide.md Use the 'debug' command to get AI assistance with errors. Provide error messages for analysis. ```bash # Analyze error messages llmswap debug --error "IndexError: list index out of range" llmswap debug --error "TypeError: 'NoneType' object is not callable" llmswap debug --error "SyntaxError: invalid syntax" # Complex error analysis llmswap debug --error "ConnectionError: HTTPSConnectionPool(host='api.example.com', port=443)" ``` -------------------------------- ### LLM-MCP CLI for Database Queries Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Connects to an MCP server for SQLite database access and shows example queries. ```bash # Database queries llmswap-mcp --command npx -y @modelcontextprotocol/server-sqlite ./mydb.sqlite > "Show me all users in the database" > "What are the top 10 products by sales?" ``` -------------------------------- ### LLM-MCP CLI for GitHub Integration Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Connects to an MCP server for GitHub integration and provides example commands. ```bash # GitHub integration llmswap-mcp --command npx -y @modelcontextprotocol/server-github --owner anthropics --repo anthropic-sdk-python > "Show me recent issues" > "What pull requests are open?" ``` -------------------------------- ### Access Command-Specific Help Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/cli_usage_guide.md Get detailed help for specific LLMSwap commands like 'ask' by appending `--help`. ```bash llmswap ask --help ``` -------------------------------- ### Generate Pinecone Vector Database Setup with LLMSwap Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Create a Python script to set up a Pinecone vector database for semantic search applications. ```bash # Vector database setup llmswap generate "Pinecone vector database setup for semantic search" --language python ``` -------------------------------- ### Shell Integration: Scripting Example Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/cli_usage_guide.md An example of using llmswap commands within a bash script for automated tasks like daily code reviews. ```bash #!/bin/bash # Daily code review script for file in $(find src/ -name "*.py" -mtime -1); do echo "Reviewing: $file" llmswap review "$file" --focus security --quiet done ``` -------------------------------- ### Start LLMSwap Web Server Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Starts the LLMSwap web interface on a specified port and host. The --no-browser flag prevents automatic browser opening. ```bash llmswap web --port 3000 --host 0.0.0.0 --no-browser ``` -------------------------------- ### llmswap chat Command Examples Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/cli_usage_guide.md Initiate an interactive conversation session with the AI. You can specify a provider for the chat. ```bash # Start interactive session llmswap chat # With specific provider llmswap chat --provider gemini # Available commands in chat: # - help: Show available commands # - quit: Exit chat session # - provider: Show current provider ``` -------------------------------- ### Chat with Gemini 3 Pro Preview using LLMClient Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Example of initializing LLMClient for Gemini 3 Pro Preview and sending a chat prompt. This model excels at multimodal understanding, large document analysis, and batch processing. ```python from llmswap import LLMClient client = LLMClient(provider="gemini", model="gemini-3-pro-preview") response = client.chat("Analyze this video and extract key insights...") print(response.content) ``` -------------------------------- ### Run LLM-MCP for Development (GitHub) Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Use llmswap-mcp to interact with a GitHub repository. This command starts a server that can answer questions about issues and commits in a specified organization and repository. ```bash llmswap-mcp --command npx -y @modelcontextprotocol/server-github --owner myorg --repo myapp > "What issues are labeled as bugs?" > "Summarize recent commits" ``` -------------------------------- ### Chat with Grok 4.3 using LLMClient Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Example of initializing LLMClient for Grok 4.3 and sending a chat prompt. Grok 4.3 is best for agentic tool use, reasoning, and providing low-hallucination answers. ```python from llmswap import LLMClient client = LLMClient(provider="xai", model="grok-4.3") response = client.chat("Help me understand this nuanced ethical dilemma...") print(response.content) ``` -------------------------------- ### llmswap review Command Examples Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/cli_usage_guide.md Utilize the 'review' command for AI-powered code analysis. Specify the file, language, and focus area for review. ```bash # Review any file llmswap review app.py llmswap review script.js --language javascript llmswap review main.go --language go # Focus on specific areas llmswap review app.py --focus security llmswap review api.py --focus performance llmswap review utils.js --focus bugs llmswap review styles.css --focus style # Supported languages: python, javascript, typescript, java, cpp, c, go, rust, ruby, php ``` -------------------------------- ### AI Tutoring Platform with LLMSwap Python SDK Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Build an AI tutoring platform using LLMSwap, enabling personalized learning experiences. This example shows how to dynamically switch providers (e.g., watsonx for STEM, Ollama for general subjects) and use context-aware caching for different grade levels. ```python client = LLMClient(provider="ollama") # Free for schools! def ai_tutor(student_question, subject): # Use watsonx for STEM, Ollama for general subjects if subject in ["math", "science"]: client.set_provider("watsonx") response = client.query( f"Explain {student_question} for a {subject} student", cache_context={"grade_level": student.grade} ) return response.content # Zero cost with Ollama, enterprise-grade with watsonx ``` -------------------------------- ### Multi-Modal Customer Support with LLMSwap Python SDK Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Develop multi-modal customer support solutions using the LLMSwap Python SDK. This example sets up the client for use in a Shopify-scale merchant assistance scenario. ```python from llmswap import LLMClient ``` -------------------------------- ### Troubleshoot Module Not Found Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/README.md Error message and solution for a missing 'llmswap' module. This indicates the library has not been installed. ```text ModuleNotFoundError: No module named 'llmswap' → Install LLMSwap: `pip install llmswap` ``` -------------------------------- ### Python SDK Usage for Analysis Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Example of using the LLMSwap Python SDK to analyze data. This snippet assumes the LLMClient has been initialized. ```python from llmswap import LLMClient client = LLMClient() # Import into any codebase response = client.query("Analyze this data") ``` -------------------------------- ### Get AI Spend Optimization Recommendations Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Utilize the CLI to receive AI spend optimization recommendations. This can include suggestions for switching providers, enabling caching, or using local models. ```bash # Get AI spend optimization recommendations llmswap costs # Suggests: Switch to Gemini, enable caching, use Ollama for dev ``` -------------------------------- ### Content Generation at Scale with LLMSwap Python SDK Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Generate descriptions for a large number of items efficiently using the LLMSwap Python SDK. This example demonstrates switching to a cheaper provider (Gemini) and utilizing caching to reduce costs significantly. ```python from llmswap import LLMClient # Start with OpenAI, switch to Gemini for 96% cost savings client = LLMClient(provider="gemini", cache_enabled=True) def generate_descriptions(items): for item in items: # Cached responses save 90% on similar content description = client.query( f"Create engaging description for {item['title']}", cache_context={"category": item['category']} ) yield description.content # Cost: $0.0005 per description vs $0.015 with OpenAI ``` -------------------------------- ### Chat with AI Mentor in Workspace Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Start an interactive chat session within your initialized workspace. The AI mentor will have access to your project's context, track learnings, and document decisions. ```bash # Start chatting - AI has full project context! llmswap chat --mentor guru ``` -------------------------------- ### Start LLMSwap Chat with Mentor Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Initiates a chat session with a personalized AI mentor. The mentor will have access to your project's context, past learnings, and documented decisions. This command allows you to leverage LLMSwap's project memory features. ```bash llmswap chat --mentor guru --alias "Guruji" ``` -------------------------------- ### Initialize LLMSwap Workspace Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Initializes a new workspace for your project, creating necessary configuration files for context, learnings, and decisions. Use this command when starting a new project or integrating LLMSwap. ```bash cd ~/my-flask-app llmswap workspace init ``` -------------------------------- ### Initialize and Use Sarvam-105B with LLMClient Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Integrate with the Sarvam-105B model for Indian language chat, reasoning, and multilingual applications. The llmswap library must be installed. ```python from llmswap import LLMClient client = LLMClient(provider="sarvam", model="sarvam-105b") response = client.chat("Explain this in Hindi and English...") print(response.content) ``` -------------------------------- ### Initialize State and DOM References Source: https://github.com/sreenathmmenon/llmswap/blob/main/llmswap/web/templates/index.html Sets up the initial state for the application and gets references to various DOM elements used for UI manipulation. This includes model data, selection state, and UI components like tabs, lists, and buttons. ```javascript const state = { modelsByProvider: {}, flatModels: [], selectedProvider: "all", selectedModels: new Set(), results: [], view: "ranked" }; const providerTabs = document.getElementById("providerTabs"); const modelList = document.getElementById("modelList"); const modelSearch = document.getElementById("modelSearch"); const selectedCount = document.getElementById("selectedCount"); const selectedRail = document.getElementById("selectedRail"); const sidebarSelected = document.getElementById("sidebarSelected"); const promptEl = document.getElementById("prompt"); const compareBtn = document.getElementById("compareBtn"); const resultsEl = document.getElementById("results"); const loadingEl = document.getElementById("loading"); const answerBoard = document.getElementById("answerBoard"); const answerBoardBody = document.getElementById("answerBoardBody"); ``` -------------------------------- ### Start and Manage Conversational Sessions Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Initiate, conduct, and end a chat session to maintain context across multiple turns. Ensure provider-level cleanup. ```python client.start_chat_session() response = client.chat("Tell me about Python") # Context maintained response = client.chat("What are its best features?") # Remembers previous client.end_chat_session() # Clean provider-level cleanup ``` -------------------------------- ### CLI Examples for Using Specific LLM Models Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md These bash commands show how to use the LLMSwap CLI to interact with different LLM providers and models. You can specify the provider and model, or set a default model for a provider. ```bash # Use any OpenAI model llmswap chat --provider openai --model gpt-5.2 llmswap chat --provider openai --model gpt-5.2-pro # Use any Anthropic model llmswap chat --provider anthropic --model claude-sonnet-4-20250514 llmswap chat --provider anthropic --model claude-opus-4-1-20250805 # Use any Gemini model llmswap chat --provider gemini --model gemini-3-pro-preview llmswap chat --provider gemini --model gemini-2.5-pro # Set as default so you don't have to type it every time llmswap config set provider.models.openai gpt-5.2 llmswap config set provider.models.anthropic claude-sonnet-4-20250514 ``` -------------------------------- ### Simple Dockerfile for LLMswap Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md A basic Dockerfile to build a Python 3.11 image, install llmswap, and copy your application code. Environment variables for API keys and MCP URL should be set at runtime. ```dockerfile FROM python:3.11-slim # Install llmswap RUN pip install llmswap # Set working directory WORKDIR /app # Copy your application COPY . . # Environment variables set at runtime ENV ANTHROPIC_API_KEY="" ENV MCP_SERVER_URL="" # Run your application CMD ["python", "your_app.py"] ``` -------------------------------- ### LLMSwap MCP CLI Usage Source: https://github.com/sreenathmmenon/llmswap/blob/main/CHANGELOG.md Example of using the `llmswap-mcp` command for natural language interaction with MCP servers. This demonstrates the new CLI for the Model Context Protocol. ```bash llmswap-mcp ``` -------------------------------- ### Initialize and Use Cohere Command A+ with LLMClient Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Use this snippet to interact with the Cohere Command A+ model for enterprise multilingual, agentic, and retrieval workflows. Ensure you have the llmswap library installed. ```python from llmswap import LLMClient client = LLMClient(provider="cohere", model="command-a-plus-05-2026") response = client.chat("Summarize this customer feedback and identify actions...") print(response.content) ``` -------------------------------- ### Set API Keys for LLM Providers Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Before using LLMSwap, set the appropriate API key as an environment variable for the LLM provider you intend to use. One key is sufficient to get started. ```bash export ANTHROPIC_API_KEY="sk-..." # For Claude export OPENAI_API_KEY="sk-..." # For GPT-4 export GEMINI_API_KEY="..." # For Google Gemini export WATSONX_API_KEY="..." # For IBM watsonx export WATSONX_PROJECT_ID="..." # watsonx project export GROQ_API_KEY="gsk_..." # For Groq ultra-fast inference export COHERE_API_KEY="co_..." # For Cohere Command models export PERPLEXITY_API_KEY="pplx-..." # For Perplexity web search ``` -------------------------------- ### Set up API Key for LLMSwap Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Before using LLMSwap with specific AI providers, set your API key as an environment variable. This example shows how to set keys for Anthropic (Claude) and OpenAI (GPT-4). ```bash export ANTHROPIC_API_KEY="your-key-here" # For Claude ``` ```bash # or export OPENAI_API_KEY="your-key-here" # For GPT-4 ``` ```bash # or any other provider ``` -------------------------------- ### Initialize Workspace Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Initialize a new workspace in the current project directory. Optionally specify a name for the workspace. ```bash # Initialize workspace in current project llmswap workspace init llmswap workspace init --name "My Flask App" ``` -------------------------------- ### Initializing a Project Workspace Source: https://github.com/sreenathmmenon/llmswap/blob/main/CHANGELOG.md Use the CLI to initialize a new workspace for the current project. This command sets up the necessary directory structure and configuration for workspace management. ```bash llmswap workspace init ``` -------------------------------- ### Set API Keys and Basic Usage Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/cli_usage_guide.md Configure your API key for a chosen provider and perform basic 'ask' or 'chat' operations. ```bash # Set up API key (choose one) export ANTHROPIC_API_KEY="your-key" export OPENAI_API_KEY="your-key" export GEMINI_API_KEY="your-key" # Basic usage llmswap ask "What is Python?" llmswap chat ``` -------------------------------- ### Bad Commit Message Example Source: https://github.com/sreenathmmenon/llmswap/blob/main/COMPATIBILITY-RULES.md An example of a vague Git commit message that does not provide enough information about the changes or their impact on compatibility. ```bash # BAD: Unclear about impact git commit -m "Update providers" # ❌ What changed? Does it break anything? ``` -------------------------------- ### Access General Help Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/cli_usage_guide.md Use the `--help` flag for general LLMSwap command-line assistance. ```bash llmswap --help ``` -------------------------------- ### Manage Multiple Freelance Projects with Workspaces Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Demonstrates how a freelancer can use LLMSwap workspaces to manage context switching between multiple client projects. Each workspace maintains independent project context, learnings, and decisions. ```bash # Morning: Client A's React project cd ~/client-a-dashboard llmswap chat # AI loads: React patterns you learned, components built, state management decisions # Afternoon: Client B's Python API cd ~/client-b-api llmswap chat # AI switches context: Python best practices, API design decisions, database schema # List all projects llmswap workspace list # See: 5 workspaces, each with independent context and learnings # Each workspace has separate: # - Learning journal (React patterns vs Python patterns) # - Decision log (frontend vs backend decisions) # - Project context (different tech stacks) ``` -------------------------------- ### Get Expert Opinions on Technical Decisions Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Asks llmswap for advice on technical decisions, specifying a mentor persona to get a perspective aligned with that role's expertise. ```bash # Get different perspectives on technical decisions llmswap ask "Should I use MongoDB or PostgreSQL?" --mentor guru ``` ```bash llmswap ask "Should I use MongoDB or PostgreSQL?" --mentor developer ``` -------------------------------- ### Generate Full-Stack SaaS Starter with LLMSwap Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Generate a Next.js 14 application with Clerk authentication, Stripe payments, Prisma ORM, and a PostgreSQL schema for a SaaS platform. ```bash # Full-Stack SaaS Starter (0 to production in 5 minutes) llmswap generate "Next.js 14 app with Clerk auth, Stripe payments, Prisma ORM, and PostgreSQL schema for SaaS platform" --save saas_mvp.js ``` -------------------------------- ### Ask One-Line Questions Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Get quick answers to specific questions using the AI assistant. ```bash # Ask one-line questions llmswap ask "How to optimize PostgreSQL queries?" ``` -------------------------------- ### Basic LLMClient Usage Source: https://github.com/sreenathmmenon/llmswap/blob/main/COMPATIBILITY-RULES.md Demonstrates the basic instantiation and querying of the LLMClient. This code must remain functional in all future versions. ```python from llmswap import LLMClient client = LLMClient(provider="anthropic") response = client.query("Hello") print(response) ``` -------------------------------- ### Querying with Full Project Context Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Send a query to the LLMClient after it has loaded workspace context. The AI will have access to project details, past learnings, and architecture decisions. ```python # Query with full project context response = client.query("How should I structure my API?") # AI has access to: project context, past learnings, architecture decisions ``` -------------------------------- ### Prevent Auto-Opening Browser Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Start the LLMSwap web UI without automatically opening the default browser. ```bash # Don't auto-open browser llmswap web --no-browser ``` -------------------------------- ### Eklavya Mentor Integration with Workspace Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Initialize the EklavyaMentor with a specific persona and alias, then generate a teaching system prompt that includes workspace context for tailored AI mentorship. ```python from llmswap import LLMClient from llmswap.eklavya.mentor import EklavyaMentor # Initialize client and mentor client = LLMClient(provider="anthropic") mentor = EklavyaMentor(persona="guru", alias="Guruji") # Generate teaching system prompt with workspace context teaching_prompt = mentor.generate_system_prompt() ``` -------------------------------- ### Good Commit Message for Compatibility Source: https://github.com/sreenathmmenon/llmswap/blob/main/COMPATIBILITY-RULES.md An example of a clear and informative Git commit message that details the impact of changes on compatibility and features. ```bash # GOOD: Clear about compatibility git commit -m "Add streaming support for all 10 providers - Works universally with Anthropic, OpenAI, Gemini, etc. - Backward compatible (query() still works) - New optional method: stream_query() - All existing code continues working" ``` -------------------------------- ### Listing All Workspaces Source: https://github.com/sreenathmmenon/llmswap/blob/main/CHANGELOG.md View a list of all initialized workspaces across the system. This command is useful for managing multiple projects with LLMSwap. ```bash llmswap workspace list ``` -------------------------------- ### Access Review Command Help Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/cli_usage_guide.md View options and usage for the 'review' command by using the `--help` flag. ```bash llmswap review --help ``` -------------------------------- ### Testing Features Across All Providers Source: https://github.com/sreenathmmenon/llmswap/blob/main/COMPATIBILITY-RULES.md A pytest example demonstrating how to parameterize tests to ensure a feature works correctly with all supported providers. ```python @pytest.mark.parametrize("provider", [ "anthropic", "openai", "gemini", "groq", "cohere", "perplexity", "watsonx", "xai", "ollama", "sarvam" ]) def test_feature(provider): client = LLMClient(provider=provider) # Test feature works for this provider ``` -------------------------------- ### Switch LLM Providers Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/README.md Shows how to switch between different LLM providers after initializing the client. Requires configuration for both 'anthropic' and 'openai'. ```python from llmswap import LLMClient # Start with Anthropic client = LLMClient(provider="anthropic") response1 = client.query("Hello!") # Switch to OpenAI client.set_provider("openai") response2 = client.query("Hello!") ``` -------------------------------- ### Initialize LLMClient and Query Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Initialize the LLMClient to interact with configured AI providers and make a query. The client auto-detects configurations from the environment or config files. ```python from llmswap import LLMClient # Works with any provider you have configured client = LLMClient() # Auto-detects from environment/config response = client.query("Explain quantum computing in 50 words") print(response.content) ``` -------------------------------- ### Using Mentor for Teaching-Focused Responses Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Utilize the generated teaching prompt with the LLMClient's query method to receive responses tailored to a specific teaching persona. Learnings are automatically saved. ```python # Use mentor for teaching-focused responses response = client.query( "Explain Python decorators", system_prompt=teaching_prompt ) print(response.content) # Guru-style teaching response ``` -------------------------------- ### Conversational Chat with Provider Switching Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Starts a conversational chat session with options for age and mentor customization, allowing mid-conversation provider switching. ```bash llmswap chat --age 25 --mentor tutor # In chat: /switch anthropic # Switch mid-conversation # In chat: /provider # See current provider # Commands: /help, /switch, /clear, /stats, /quit ``` -------------------------------- ### Get Age-Appropriate AI Explanations Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Requests explanations for concepts tailored to specific age groups or audiences, making complex topics more accessible. ```bash llmswap ask "What is Docker?" --age 10 llmswap ask "What is blockchain?" --audience "business owner" ``` -------------------------------- ### Get Display Name for Model ID Source: https://github.com/sreenathmmenon/llmswap/blob/main/llmswap/web/templates/index.html Retrieves the display name for a given model ID from the state. Returns the ID if the model is not found. ```javascript function displayName(id) { const model = state.flatModels.find(item => item.id === id); return model?.name || id; } ``` -------------------------------- ### Graceful Deprecation of Functionality Source: https://github.com/sreenathmmenon/llmswap/blob/main/COMPATIBILITY-RULES.md Demonstrates how to deprecate existing functionality by providing warnings and guiding users to new methods instead of outright removal. ```python # GOOD: Deprecate gracefully with warnings def stream(self, prompt): warnings.warn("stream() is deprecated, use stream_query()", DeprecationWarning) return self.stream_query(prompt) # ✅ Still works, guides to new method ``` -------------------------------- ### Initialize and Use Groq GPT-OSS 120B with LLMClient Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md This code initializes the LLMClient to use the Groq GPT-OSS 120B model, ideal for high-throughput inference on open-weight models. Requires the llmswap library. ```python from llmswap import LLMClient client = LLMClient(provider="groq", model="openai/gpt-oss-120b") response = client.chat("Generate a latency-sensitive API handler...") print(response.content) ``` -------------------------------- ### Initialize a New Workspace for Learning Flask Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Initialize a new LLMSwap workspace for learning Flask. This command sets up a dedicated context for AI-assisted learning, saving conversations and learnings automatically. ```bash cd ~/my-first-flask-app llmswap workspace init --name "Learning Flask" # Day 1: Learn about routing llmswap chat --mentor professor "How do Flask routes work?" # AI explains. Learning auto-saved to learnings.md # Day 2: Same workspace, AI remembers! llmswap chat "Can I use decorators for authentication?" # AI response: "Building on what you learned about routes yesterday..." # No need to re-explain basics! # View your learning journey llmswap workspace journal # See: Day 1 - Routes, Day 2 - Authentication, etc. ``` -------------------------------- ### Python Script for Gemini 3 Multimodal Source: https://github.com/sreenathmmenon/llmswap/blob/main/CHANGELOG.md This Python script showcases the capabilities of the Gemini 3 multimodal model. It is a detailed example with 280 lines of code. ```python gemini_3_multimodal.py ``` -------------------------------- ### LLM-MCP CLI for Filesystem Access Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Connects to an MCP server for filesystem access and demonstrates natural language queries. ```bash # Filesystem access llmswap-mcp --command npx -y @modelcontextprotocol/server-filesystem ~/Documents # Then ask naturally: > "What files are in this directory?" > "Read the contents of report.pdf" > "Find all files modified in the last week" ``` -------------------------------- ### Stream LLM Responses Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/README.md Illustrates how to receive streaming responses from an LLM. This is useful for interactive applications where immediate feedback is desired. Requires 'anthropic' provider setup. ```python from llmswap import LLMClient client = LLMClient(provider="anthropic") for chunk in client.stream("Write a story"): print(chunk, end="", flush=True) ``` -------------------------------- ### Python SDK for Using Any Supported LLM Model Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md This Python code demonstrates how to initialize the LLMClient with specific models from different providers. It highlights the flexibility to use newly released models immediately. ```python from llmswap import LLMClient # Use whatever model your provider offers client = LLMClient(provider="openai", model="gpt-5") client = LLMClient(provider="anthropic", model="claude-opus-4") client = LLMClient(provider="gemini", model="gemini-2-5-pro") # Model just released? Use it right now client = LLMClient(provider="openai", model="gpt-6") # works! ``` -------------------------------- ### Kubernetes ConfigMap for MCP Configuration Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md A Kubernetes ConfigMap to store configuration data for MCP servers. This example defines two MCP servers with their transport protocols and URLs. ```yaml apiVersion: v1 kind: ConfigMap metadata: name: mcp-config data: mcp-servers.json: | { "internal-api": { "transport": "sse", "url": "https://mcp.company.com/events" }, "crm-system": { "transport": "http", "url": "https://crm-api.company.com/mcp" } } ``` -------------------------------- ### Compare Provider Costs Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Use the CLI to compare the costs of different LLM providers for a given token count. This helps in choosing the most cost-effective provider. ```bash # Compare provider costs before choosing llmswap compare --input-tokens 1000 --output-tokens 500 # Output: Gemini $0.0005 | OpenAI $0.014 | Claude $0.011 ``` -------------------------------- ### LLMSwap CLI for Code Generation and Assistance Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Demonstrates various LLMSwap CLI commands for code generation, debugging, and cost analysis. These commands offer alternatives to tools like GitHub Copilot. ```bash llmswap generate "sort files by size" # GitHub Copilot alternative llmswap generate "Python function to read JSON" # Multi-language code generation llmswap ask "Debug this error" # Terminal AI assistant llmswap costs # Cost optimization insights ``` -------------------------------- ### Retrieve Secrets from HashiCorp Vault Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Fetch API keys from HashiCorp Vault using AppRole authentication and use them to initialize the LLMClient. This example reads the 'anthropic_key' from the 'llm-keys' path. ```python import hvac from llmswap import LLMClient vault_client = hvac.Client(url='https://vault.company.com') vault_client.auth.approle.login(role_id=..., secret_id=...) secret = vault_client.secrets.kv.v2.read_secret_version(path='llm-keys') api_key = secret['data']['data']['anthropic_key'] client = LLMClient(provider="anthropic", api_key=api_key) ``` -------------------------------- ### Retrieve Secrets from Azure Key Vault Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Fetch API keys from Azure Key Vault using DefaultAzureCredential and use them to initialize the LLMClient. This example retrieves the 'anthropic-api-key' secret. ```python from azure.identity import DefaultAzureCredential from azure.keyvault.secrets import SecretClient from llmswap import LLMClient credential = DefaultAzureCredential() vault_client = SecretClient( vault_url="https://your-vault.vault.azure.net", credential=credential ) api_key = vault_client.get_secret("anthropic-api-key").value client = LLMClient(provider="anthropic", api_key=api_key) ``` -------------------------------- ### Retrieve Secrets from AWS Secrets Manager Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Fetch API keys from AWS Secrets Manager and use them to initialize the LLMClient. This example assumes secrets are stored as a JSON string. ```python import boto3 import json from llmswap import LLMClient def get_secret(secret_name): client = boto3.client('secretsmanager') response = client.get_secret_value(SecretId=secret_name) return json.loads(response['SecretString']) secrets = get_secret('llm-api-keys') client = LLMClient(provider="anthropic", api_key=secrets['anthropic_key']) ``` -------------------------------- ### Python SDK for LLMClient with MCP Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Demonstrates adding an MCP server to an LLMClient and making natural language queries. ```python from llmswap import LLMClient # Add MCP server to your client client = LLMClient(provider="anthropic") client.add_mcp_server("filesystem", command=["npx", "-y", "@modelcontextprotocol/server-filesystem", "/tmp"]) # Chat naturally - AI uses MCP tools automatically response = client.chat("List all log files in /tmp", use_mcp=True) print(response.content) # List available tools tools = client.list_mcp_tools() for tool in tools: print(f"- {tool['name']}: {tool['description']}") ``` -------------------------------- ### Run LLM-MCP for Research (Brave Search) Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Use llmswap-mcp to perform research using Brave Search. This command starts a server that can find papers and information on various topics. ```bash llmswap-mcp --command npx -y @modelcontextprotocol/server-brave-search > "Find recent papers on transformer architectures" > "What are the latest developments in quantum computing?" ``` -------------------------------- ### Explain Model Context Protocol (MCP) as a Developer Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Asks llmswap to explain the Model Context Protocol (MCP) from a developer's perspective, focusing on implementation details and code examples. ```bash # As a Developer: Implementation focus llmswap ask "Explain Model Context Protocol (MCP)" --audience developer ``` -------------------------------- ### Kubernetes Secret for LLM API Keys Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md A Kubernetes Secret manifest to store sensitive information like API keys. This example shows how to store Anthropic and OpenAI API keys. ```yaml apiVersion: v1 kind: Secret metadata: name: llm-secrets type: Opaque data: anthropic-key: openai-key: ``` -------------------------------- ### Define and Use a Tool with LLMClient Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Demonstrates how to define a custom tool with parameters and use it with the LLMClient. The tool can then be passed to the chat method to enable the LLM to access external functionalities. ```python from llmswap import LLMClient, Tool # Define tool to access YOUR weather API weather = Tool( name="get_weather", description="Get real-time weather data", parameters={"city": {"type": "string"}}, required=["city"] ) # Works with ANY provider - Anthropic, OpenAI, Gemini, Groq, xAI client = LLMClient(provider="anthropic") response = client.chat("What's the weather in Tokyo?", tools=[weather]) # LLM calls YOUR function → you return data → LLM gives natural response ``` -------------------------------- ### Parameter Compatibility Source: https://github.com/sreenathmmenon/llmswap/blob/main/COMPATIBILITY-RULES.md Shows how to handle parameters, emphasizing that existing parameters must be preserved and new ones can be added optionally. ```python # GOOD: Add new parameters, keep old ones LLMClient(provider="anthropic") # ✅ Still works LLMClient(provider="anthropic", new_param=True) # ✅ Optional new feature ``` -------------------------------- ### Generate Python Code Source: https://github.com/sreenathmmenon/llmswap/blob/main/CHANGELOG.md Specify the desired programming language using the --language flag to generate code snippets. This example generates a Python function to read a JSON file. ```bash llmswap generate "Python function to read JSON file" --language python ``` -------------------------------- ### Track Learning Journey Across Technologies with Workspaces Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Illustrates how a developer learning full-stack can use LLMSwap workspaces to track progress across frontend, backend, and DevOps. Each workspace maintains a separate learning journal and project context. ```bash # Frontend project cd ~/react-app llmswap workspace init --name "React Learning" llmswap chat --mentor tutor # Learn: Hooks, State, Components # All auto-tracked in learnings.md # Backend project cd ~/python-api llmswap workspace init --name "Python API" llmswap chat --mentor tutor # Learn: FastAPI, SQLAlchemy, Testing # Separate learning journal # View all learning across projects llmswap workspace list # See progress in each area # Each workspace shows: # - Total queries # - Learnings count # - Last accessed ``` -------------------------------- ### Run LLM-MCP for Data Analysis Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Use llmswap-mcp to query a local SQLite database for data analysis. This command starts a server that can understand natural language questions about the provided database. ```bash llmswap-mcp --command npx -y @modelcontextprotocol/server-sqlite ./sales.db > "What were our top 5 products last quarter?" > "Show me revenue trends by region" ``` -------------------------------- ### CLI Cost Comparison Tool Source: https://github.com/sreenathmmenon/llmswap/blob/main/CHANGELOG.md Command-line interface tool for comparing provider costs. Use the `--input-tokens` and `--output-tokens` flags to specify token counts for comparison. ```bash llmswap compare --input-tokens X --output-tokens Y ``` -------------------------------- ### Initialize Workspace and Add Project Context for Legacy Project Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Initialize an LLMSwap workspace for a legacy project and add project context. This helps new team members quickly understand the project's architecture and decisions. ```bash cd ~/legacy-ecommerce-app llmswap workspace init # Edit context.md with project overview llmswap workspace context # Add: Tech stack, key components, known issues # Ask questions - AI has full context llmswap ask "Why did we choose MongoDB over PostgreSQL?" --mentor guru # AI suggests checking decisions.md # If documented: "According to your decision log from 2023-05..." # If not: AI helps document it now llmswap workspace decisions # See all past architectural decisions in one place ``` -------------------------------- ### Basic LLM Query Source: https://github.com/sreenathmmenon/llmswap/blob/main/examples/README.md Demonstrates a simple LLM query using the LLMClient. Ensure the 'anthropic' provider is configured with an API key. ```python from llmswap import LLMClient client = LLMClient(provider="anthropic") response = client.query("What is LLMSwap?") print(response) ``` -------------------------------- ### Initialize LLMSwap Workspace Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Command to create a new LLMSwap workspace in the current directory. This workspace will store project context and AI learnings. ```bash # Create your first workspace cd ~/my-project llmswap workspace init ``` -------------------------------- ### Route to Cheapest LLM Provider with Fallback Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Optimize for cost by routing requests to the cheapest LLM provider first, with a fallback to a premium provider if the cheaper one fails. ```python # Route to cheapest provider first, fallback to premium try: response = LLMClient(provider="groq").chat(query) # Fast & cheap except: response = LLMClient(provider="anthropic").chat(query) # Premium fallback ``` -------------------------------- ### Provider Fallback Chain for LLM Requests Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md Implement a fallback chain for LLM providers to ensure requests are processed even if primary providers fail. This example tries Groq, then Anthropic, then OpenAI. ```python from llmswap import LLMClient providers = ["groq", "anthropic", "openai"] # Priority order for provider in providers: try: client = LLMClient(provider=provider) response = client.chat(query) break except Exception as e: logger.warning(f"{provider} failed: {e}") continue ``` -------------------------------- ### Prometheus Metrics for LLM Client Source: https://github.com/sreenathmmenon/llmswap/blob/main/README.md This Python snippet demonstrates how to instrument LLMClient calls with Prometheus metrics. It defines counters for requests and errors, and a histogram for latency, then starts an HTTP server for metrics. ```python from prometheus_client import Counter, Histogram, start_http_server from llmswap import LLMClient # Metrics llm_requests = Counter('llm_requests_total', 'Total LLM requests', ['provider']) llm_latency = Histogram('llm_request_duration_seconds', 'LLM request latency', ['provider']) llm_errors = Counter('llm_errors_total', 'Total LLM errors', ['provider', 'error_type']) # Start metrics endpoint start_http_server(9090) # Instrument your calls client = LLMClient(provider="anthropic") with llm_latency.labels(provider="anthropic").time(): try: response = client.chat("query") llm_requests.labels(provider="anthropic").inc() except Exception as e: llm_errors.labels(provider="anthropic", error_type=type(e).__name__).inc() raise ```