Ai Coding Tools

How to Build a Personal AI Coding Assistant in Under 2 Hours

By BTW Team3 min read

How to Build a Personal AI Coding Assistant in Under 2 Hours

If you’re a solo founder or indie hacker, you know how precious time is. Imagine having a coding assistant that can help you debug, generate code snippets, or even write documentation. The good news is that you can build a personal AI coding assistant in under 2 hours. Here's how to do it practically, without the fluff.

Prerequisites: What You Need to Get Started

Before diving in, make sure you have the following tools and accounts set up:

  1. A code editor: VS Code is a great choice (free).
  2. An OpenAI API key: Sign up at OpenAI and get your API key (pricing starts at $0.0004 per token).
  3. Node.js installed: This will help you run your scripts locally (free).
  4. Git: For version control (free).

Step 1: Set Up Your Development Environment (30 minutes)

  1. Install VS Code: Download and install from here.

  2. Install Node.js: Go to Node.js and download the LTS version.

  3. Create a new project folder: Open your terminal and run:

    mkdir ai-coding-assistant
    cd ai-coding-assistant
    npm init -y
    
  4. Install Axios: This will help you make API calls.

    npm install axios
    

Step 2: Write the Core Functionality (30 minutes)

Now, let’s write a simple script that interacts with the OpenAI API:

  1. Create a new file named assistant.js and add the following code:

    const axios = require('axios');
    
    const API_KEY = 'YOUR_OPENAI_API_KEY';
    const endpoint = 'https://api.openai.com/v1/chat/completions';
    
    async function getResponse(prompt) {
        const response = await axios.post(endpoint, {
            messages: [{ role: 'user', content: prompt }],
            model: 'gpt-3.5-turbo',
        }, {
            headers: {
                'Authorization': `Bearer ${API_KEY}`,
                'Content-Type': 'application/json',
            },
        });
        return response.data.choices[0].message.content;
    }
    
    (async () => {
        const userPrompt = "Write a function to reverse a string.";
        const assistantResponse = await getResponse(userPrompt);
        console.log(assistantResponse);
    })();
    
  2. Replace YOUR_OPENAI_API_KEY with your actual API key.

  3. Run your script:

    node assistant.js
    

You should see a response with a function to reverse a string.

Step 3: Enhance Functionality (30 minutes)

Now that you have the basic functionality, let’s enhance it:

  1. Add more commands: Modify your script to accept user input from the command line.
  2. Implement error handling: Make sure to handle API errors gracefully.
  3. Store previous queries: You can use a simple JSON file to log requests and responses.

Here’s a quick enhancement to accept user input:

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

rl.question('What coding help do you need? ', async (userPrompt) => {
    const assistantResponse = await getResponse(userPrompt);
    console.log(assistantResponse);
    rl.close();
});

Troubleshooting: What Could Go Wrong

  1. API Key Issues: Ensure your API key is correct and has the necessary permissions.
  2. Network Errors: Check your internet connection if you receive network-related errors.
  3. Rate Limiting: If you exceed usage limits, you’ll get errors. Monitor your usage in the OpenAI dashboard.

What's Next: Expanding Your AI Assistant

Once you have the basic assistant running, consider expanding its features:

  • Integrate with GitHub to pull issues and provide coding help based on open issues.
  • Add a GUI using Electron for a more user-friendly experience.
  • Experiment with other AI models like Claude or LLaMA for different outputs.

Conclusion: Start Here

Building a personal AI coding assistant is not just feasible; it's practical and can significantly boost your productivity. Start with the basic setup above, and iterate on it to suit your needs. In our experience, this setup works great for quick coding help but may struggle with complex queries or deep domain-specific questions.

What We Actually Use

We primarily use OpenAI's API for our coding assistant, as it provides quick and relevant responses. If you're looking for alternatives, consider Cohere or Anthropic, but be aware that they may have different capabilities and pricing structures.

Follow Our Building Journey

Weekly podcast episodes on tools we're testing, products we're shipping, and lessons from building in public.

Subscribe

Never miss an episode

Subscribe to Built This Week for weekly insights on AI tools, product building, and startup lessons from Ryz Labs.

Subscribe
Ai Coding Tools

Bolt.new vs Cursor: Which AI Coding Tool is Better for Professionals?

Bolt.new vs Cursor: Which AI Coding Tool is Better for Professionals? As a professional developer, you’re likely feeling the pressure to code faster and more efficiently. Enter AI

Jul 17, 20263 min read
Ai Coding Tools

How to Build Your First Full-Stack App Using AI Coding Tools in 60 Minutes

How to Build Your First FullStack App Using AI Coding Tools in 60 Minutes Building your first fullstack app can feel like a daunting task, especially if you’re new to coding or ove

Jul 17, 20264 min read
Ai Coding Tools

How to Use AI Tools to Write Your First 50 Lines of Code in 30 Minutes

How to Use AI Tools to Write Your First 50 Lines of Code in 30 Minutes If you're new to coding, the thought of writing your first lines of code can feel daunting. However, with the

Jul 17, 20264 min read
Ai Coding Tools

Why GitHub Copilot is Overrated: Exploring Limitations in 2026

Why GitHub Copilot is Overrated: Exploring Limitations in 2026 As a solo founder or indie hacker, you’ve probably heard the buzz around GitHub Copilot. This AIpowered coding assist

Jul 17, 20265 min read
Ai Coding Tools

Comparison: GitHub Copilot vs Codeium for Solo Developers

Comparison: GitHub Copilot vs Codeium for Solo Developers As a solo developer, finding the right AI coding tool can feel like searching for a needle in a haystack. You want somethi

Jul 17, 20263 min read
Ai Coding Tools

Why GitHub Copilot is Overrated: A Critique from an Expert Developer

Why GitHub Copilot is Overrated: A Critique from an Expert Developer As developers, we often chase efficiency and productivity. Enter GitHub Copilot, which promised to be the magic

Jul 17, 20264 min read