From Web Development to AI Development: How Web Developers Can Build Powerful AI Applications

Chetan MittalChetan Mittal
8 min read

If you're a web developer working with Ruby on Rails and JavaScript, you're actually closer to becoming an AI developer than you might think! While AI might seem like a whole new world with its unique terminology and concepts, your existing coding skills give you a tremendous head start.

Think of adding AI to your toolkit as an extension of your web development expertise, not a complete career change. This guide will show you how to leverage what you already know about building web applications to create AI-powered features and applications. You'll see that many AI concepts have familiar parallels in the web development world you already understand.

Understanding Core AI Concepts in Web Developer Terms

Models: Think of Them as Smart Functions

An AI model is like a super-powerful function that can handle complex inputs and generate creative outputs. Just as your Rails app has functions that process user requests, an AI model processes inputs (text, images, or data) and generates outputs based on what it's learned.

For example, when you type a message to Claude or Llama, the model processes your text and generates a response. The difference is that while your typical Rails function follows explicit rules you've coded, AI models can handle ambiguity and generate novel content.

Weights: The Model's Memory

If you're familiar with databases in web development, weights in AI serve a similar purpose - they store information. But instead of structured data in tables, weights are numerical values (typically floating-point numbers) spread throughout the neural network.

These weights determine how information flows through the model. When you download a Llama model file, most of what you're getting is these weights - they represent everything the model has "learned" during training.

Think of weights as the collective memory of the model that it uses to generate responses. The larger the model (more parameters/weights), the more information it can potentially store.

Inference: Running the Model

Inference is simply using a trained model to generate outputs. This is what happens when you deploy an AI model in production and start using it.

It's similar to how your Rails application handles user requests in production - you're using the completed system to process new inputs and generate appropriate responses.

For example, when you ask Claude a question, the service is running inference - taking your input, processing it through the model, and returning the generated text.

Training: Teaching the Model

Training is how AI models learn. During training, the model is exposed to massive amounts of data, and its weights are adjusted to minimize errors in its predictions.

Unlike manually coding a web application, training a model is largely automated through mathematical optimization. The model learns patterns from data rather than being explicitly programmed with rules.

For example, language models like Claude and Llama learned by reading vast amounts of text from the internet, books, and other sources - adjusting their weights to better predict text patterns.

Setting Up Your AI Development Environment

Just as you have a development environment for Rails with specific gems and tools, AI development requires its own setup. Here's how to prepare a suitable environment on a standard development machine (16GB RAM, 512GB SSD):

# Update your system
sudo apt update && sudo apt upgrade -y

# Install Python and pip
sudo apt install python3 python3-pip python3-venv -y

# Create a virtual environment
mkdir ai-project
cd ai-project
python3 -m venv env
source env/bin/activate

# Install essential AI libraries
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
pip install transformers datasets scikit-learn pandas matplotlib flask

Creating Your First AI Application with Rails

Let's build a Rails application that integrates with AI capabilities. There are two main approaches:

1. Using API-Based Models (Like Claude)

API-based models like Claude run on remote servers, making them easy to integrate but less customizable:

# Gemfile
gem 'httparty'
gem 'dotenv-rails'

# app/services/claude_service.rb
class ClaudeService
  include HTTParty
  base_uri 'https://api.anthropic.com'

  def self.generate_response(prompt)
    response = post('/v1/complete',
      headers: {
        'Content-Type': 'application/json',
        'X-API-Key': ENV['CLAUDE_API_KEY']
      },
      body: {
        prompt: prompt,
        model: "claude-3-sonnet-20240229",
        max_tokens_to_sample: 1000
      }.to_json
    )

    JSON.parse(response.body)['completion'] if response.success?
  end
end

2. Using Open-Source Models (Like Llama)

Open-source models like Llama can be run locally, giving you more control and customization options:

# app/services/llama_service.rb
require 'open3'

class LlamaService
  def self.generate_response(prompt, max_tokens = 512)
    llama_path = ENV['LLAMA_PATH'] || "#{Rails.root}/lib/llama.cpp/main"
    model_path = ENV['LLAMA_MODEL'] || "#{Rails.root}/lib/llama.cpp/models/llama-2-7b-chat.Q4_K_M.gguf"

    cmd = "#{llama_path} -m #{model_path} -n #{max_tokens} --repeat_penalty 1.1 -p \"#{prompt}\""

    stdout, stderr, status = Open3.capture3(cmd)

    if status.success?
      # Parse the output to extract just the generated text
      response = stdout.split(prompt).last.strip
      return response
    else
      Rails.logger.error("Llama error: #{stderr}")
      return "Error generating response"
    end
  end
end

Choosing the Right AI Model: Claude vs. Llama

When building AI applications, you'll need to choose which model to use. Let's compare two popular options that represent different approaches:

Claude: The Cloud-Based Powerhouse

Claude is like a SaaS solution for AI - you access its power through an API:

  • Easy integration: Just make API calls from your Rails app

  • No hardware requirements: Runs on Anthropic's powerful servers

  • High quality responses: Strong reasoning and writing capabilities

  • Pay as you go: Costs based on usage (tokens processed)

  • Maintenance-free: No need to manage model updates or infrastructure

Llama: The Self-Hosted Solution

Llama is like self-hosting your own application - more control but more responsibility:

  • Run it locally: Complete control over the model on your own hardware

  • Free to use: No per-request costs after initial setup

  • Privacy-focused: Data never leaves your server

  • Customizable: Can be fine-tuned on your specific data

  • Hardware dependent: Performance limited by your available resources

  • Size options: Different variants (7B to 70B parameters) for different needs

Making the Right Choice for Your Project

Here's a simplified comparison to help you decide:

ConsiderLlama (Self-hosted)Claude (API)
Budget concernsBetter for high volume (one-time hardware cost)Better for low volume (pay per use)
Data privacyComplete control of your dataData sent to third-party servers
Technical resourcesRequires DevOps knowledgeSimple REST API integration
Performance needsLimited by your hardware (16GB RAM = smaller models)Enterprise-grade performance
CustomizationCan modify and fine-tune the modelUse as-is with parameter adjustments

Essential AI Resources: Hugging Face vs. Together AI

As you build AI applications, you'll encounter two major platforms that serve different needs in your development journey:

Hugging Face: The GitHub of AI

Think of Hugging Face as the GitHub for AI development:

  • Model marketplace: Browse and download thousands of open-source AI models

  • Ready-to-use code: Find implementation examples and libraries

  • Community-driven: Active forums and collaborative development

  • Learning resource: Tutorials and courses to build your AI skills

  • Free access: Most resources available at no cost

For Rails developers, Hugging Face is where you'll find Llama model variants and code samples to help with implementation.

Together AI: The AI-as-a-Service Platform

Together AI is more like a cloud service provider for AI capabilities:

  • API-first approach: Simple endpoints to access powerful AI models

  • Infrastructure management: Run models too large for your hardware

  • Production focus: Enterprise-grade reliability and scaling

  • Advanced features: Fine-tuning services and deployment options

  • Usage-based pricing: Pay for what you use

If your Rails app needs AI capabilities beyond what your local machine can handle, Together AI provides a streamlined way to access that power.

Let's Build Something Real: An AI-Powered Blog Assistant

Let's put theory into practice with a real-world example: adding an AI-powered title suggestion feature to your Rails blog application.

This feature will analyze a user's previous post categories and generate relevant, SEO-friendly title suggestions - something your users will love!

Here's how to implement it:

# app/controllers/posts_controller.rb
def new
  @post = Post.new
  @title_suggestions = generate_title_suggestions if params[:generate_suggestions]
end

private

def generate_title_suggestions
  # Get topics from user's recent posts
  topics = current_user.recent_posts.pluck(:category).uniq.join(", ")

  # Create a clear prompt for the AI
  prompt = "Generate 5 engaging blog title ideas about #{topics}. Make them SEO-friendly and compelling."

  # Use either Claude or Llama service based on your setup
  response = ClaudeService.generate_response(prompt)
  # Alternative: response = LlamaService.generate_response(prompt)

  # Clean up the response to get just the titles
  response.split("\n").map { |line| line.gsub(/^\d+\.\s+/, '') }
end

With just these few lines of code, you've added an AI-powered feature to your Rails application that would have been impossible just a few years ago!

Your Next Steps: From Rails Developer to AI Developer

You don't need to abandon your Rails expertise to embrace AI development - in fact, your web development background gives you a major advantage! Here's your practical roadmap:

Week 1-2: Get Your Feet Wet

  • Set up a simple Claude API integration in your existing Rails app

  • Add one AI-powered feature (like the title generator we built above)

  • Learn the basic terminology (models, weights, inference)

Week 3-4: Deepen Your Understanding

  • Try installing and running a small Llama model locally

  • Experiment with different prompts and parameters

  • Connect your AI capabilities to your app's database

Month 2: Build Something Meaningful

  • Create a complete AI-powered feature that solves a real user problem

  • Learn about fine-tuning to customize models for your specific needs

  • Start learning Python basics alongside your Rails development

Remember - your Rails development skills are incredibly valuable in the AI world! The same principles of clean code, good user experience, and solid architecture apply to AI applications too. You're not starting from scratch - you're adding new tools to your already impressive toolkit.

Resources Handpicked for Rails Developers

I've selected these resources specifically for web developers looking to enter AI development:

  • Hugging Face - Your one-stop shop for models and code examples

  • Fast.ai - AI courses designed for programmers, not mathematicians

  • Ruby-LLM gem - Built specifically for Ruby developers working with AI

  • AI for Web Developers - Tutorials focused on web integration

The future of web development includes AI capabilities - and with your Rails and JavaScript background, you're perfectly positioned to be at the forefront of this exciting transition!

0
Subscribe to my newsletter

Read articles from Chetan Mittal directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Chetan Mittal
Chetan Mittal

I stumbled upon Ruby on Rails beta version in 2005 and has been using it since then. I have also trained multiple Rails developers all over the globe. Currently, providing consulting and advising companies on how to upgrade, secure, optimize, monitor, modernize, and scale their Rails apps.