Close Menu
    Trending
    • Instagram Head Adam Mosseri Experiences Google Phishing Scam
    • 09045080282 – شماره خاله تهران شماره خاله شیراز شماره خاله
    • TikTok Layoffs Hit E-Commerce Division in US, TikTok Shop
    • Use PyTorch to Easily Access Your GPU
    • OpenAI vs whereintheworld. To determine the best model to use on… | by Kyle Higginson | May, 2025
    • Does Amazon Owe You a Refund? Here’s What to Know.
    • Building AI Applications in Ruby
    • Learn Data Science Like a Pro: File Handling — #Day6 | by Ritesh Gupta | May, 2025
    Finance StarGate
    • Home
    • Artificial Intelligence
    • AI Technology
    • Data Science
    • Machine Learning
    • Finance
    • Passive Income
    Finance StarGate
    Home»Artificial Intelligence»Building AI Applications in Ruby
    Artificial Intelligence

    Building AI Applications in Ruby

    FinanceStarGateBy FinanceStarGateMay 21, 2025No Comments15 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    📗 That is the sequence on creating net purposes with generative AI integration. Half 1 targeted on explaining the AI stack and why the applying layer is the very best place within the stack to be. Examine it out here.

    Desk of Contents

    Introduction

    It’s not typically that you just hear the Ruby language talked about when discussing AI.

    Python, after all, is the king on this world, and for good purpose. The group has coalesced across the language. Most mannequin coaching is finished in PyTorch or TensorFlow as of late. Scikit-learn and Keras are additionally very talked-about. RAG frameworks corresponding to LangChain and LlamaIndex cater primarily to Python.

    Nonetheless, in the case of constructing net purposes with AI integration, I imagine Ruby is the higher language.

    Because the co-founder of an agency devoted to constructing MVPs with generative AI integration, I continuously hear potential purchasers complaining about two issues:

    • Purposes take too lengthy to construct
    • Builders are quoting insane costs to construct customized net apps

    These complaints have a typical supply: complexity. Trendy net apps have much more complexity in them than within the good ol’ days. However why is that this? Are the advantages introduced by complexity price the fee?

    I assumed spas have been alleged to be enjoyable?

    One huge piece of the puzzle is the latest rise of single-page purposes (SPAs). The preferred stack used immediately in constructing trendy SPAs is MERN (MongoDB, Specific.js, React.js, Node.js). The stack is well-liked for a couple of causes:

    • It’s a JavaScript-only stack, throughout each front-end and back-end. Having to solely code in just one language is fairly good!
    • SPAs can provide dynamic designs and a “easy” consumer expertise. Easy right here signifies that when some piece of knowledge modifications, solely part of the positioning is up to date, versus having to reload the entire web page. In fact, for those who don’t have a contemporary smartphone, SPAs gained’t really feel so easy, as they are typically fairly heavy. All that JavaScript begins to pull down the efficiency.
    • There’s a massive ecosystem of libraries and builders with expertise on this stack. That is fairly round logic: is the stack well-liked due to the ecosystem, or is there an ecosystem due to the recognition? Both means, this level stands.
      React was created by Meta.
    • Plenty of cash and energy has been thrown on the library, serving to to shine and promote the product.

    Sadly, there are some downsides of working within the MERN stack, probably the most vital being the sheer complexity.

    Conventional net improvement was performed utilizing the Mannequin-View-Controller (MVC) paradigm. In MVC, the entire logic managing a consumer’s session is dealt with within the backend, on the server. One thing like fetching a consumer’s knowledge was performed by way of perform calls and SQL statements within the backend. The backend then serves absolutely constructed HTML and CSS to the browser, which simply has to show it. Therefore the title “server”.

    In a SPA, this logic is dealt with on the consumer’s browser, within the frontend. SPAs should deal with UI state, utility state, and typically even server state all within the browser. API calls should be made to the backend to fetch consumer knowledge. There may be nonetheless fairly a little bit of logic on the backend, primarily exposing knowledge and performance by APIs.

    As an instance the distinction, let me use the analogy of a business kitchen. The client would be the frontend and the kitchen would be the backend.

    MVCs vs. SPAs. Picture generated by ChatGPT.

    Conventional MVC apps are like eating at a full-service restaurant. Sure, there’s quite a lot of complexity (and yelling, if The Bear is to be believed) within the backend. However the frontend expertise is straightforward and satisfying: all the client has to do is decide up a fork and eat their meals.

    SPAs are like consuming at a buffet-style eating restaurant. There may be nonetheless fairly a little bit of complexity within the kitchen. However now the client additionally has to determine what meals to seize, find out how to mix them, find out how to organize them on the plate, the place to place the plate when completed, and so on.

    Andrej Karpathy had a tweet lately discussing his frustration with trying to construct net apps in 2025. It may be overwhelming for these new to the area.

    The truth of constructing net apps in 2025 is that it is a bit like assembling IKEA furnishings. There isn’t any “full-stack” product with batteries included, it’s important to piece collectively and configure many particular person providers:

    – frontend / backend (e.g. React, Subsequent.js, APIs)
    – internet hosting…

    — Andrej Karpathy (@karpathy) March 27, 2025

    With a purpose to construct MVPs with AI integration quickly, our company has determined to forgo the SPA and as an alternative go together with the standard MVC strategy. Specifically, now we have discovered Ruby on Rails (typically denoted as Rails) to be the framework finest suited to rapidly growing and deploying high quality apps with AI integration. Ruby on Rails was developed by David Heinemeier Hansson in 2004 and has lengthy been often known as an amazing net framework, however I might argue it has lately made leaps in its capacity to include AI into apps, as we are going to see.

    Django is the preferred Python net framework, and likewise has a extra conventional sample of improvement. Sadly, in our testing we discovered Django was merely not as full-featured or “batteries included” as Rails is. As a easy instance, Django has no built-in background job system. Almost all of our apps incorporate background jobs, so to not embody this was disappointing. We additionally favor how Rails emphasizes simplicity, with Rails 8 encouraging builders to easily self-host their apps as an alternative of going by a supplier like Heroku. Additionally they lately launched a stack of instruments meant to switch exterior services like Redis.

    “However what concerning the easy consumer expertise?” you may ask. The reality is that trendy Rails contains a number of methods of crafting SPA-like experiences with out the entire heavy JavaScript. The first device is Hotwire, which bundles instruments like Turbo and Stimulus. Turbo allows you to dynamically change items of HTML in your webpage with out writing customized JavaScript. For the occasions the place you do want to incorporate customized JavaScript, Stimulus is a minimal JavaScript framework that allows you to do exactly that. Even if you wish to use React, you are able to do so with the react-rails gem. So you may have your cake, and eat it too!

    SPAs should not the one purpose for the rise in complexity, nonetheless. One other has to do with the appearance of the microservices structure.

    Microservices are for Macrocompanies

    As soon as once more, we discover ourselves evaluating the straightforward previous with the complexity of immediately.

    Up to now, software program was primarily developed as monoliths. A monolithic utility signifies that all of the completely different elements of your app — such because the consumer interface, enterprise logic, and knowledge dealing with — are developed, examined, and deployed as one single unit. The code is all usually housed in a single repo.

    Working with a monolith is straightforward and satisfying. Working a improvement setup for testing functions is simple. You’re working with a single database schema containing your whole tables, making queries and joins easy. Deployment is straightforward, because you simply have one container to have a look at and modify.

    Nonetheless, as soon as your organization scales to the dimensions of a Google or Amazon, actual issues start to emerge. With a whole lot or hundreds of builders contributing concurrently to a single codebase, coordinating modifications and managing merge conflicts turns into more and more tough. Deployments additionally develop into extra advanced and dangerous, since even minor modifications can blow up all the utility!

    To handle these points, massive firms started to coalesce across the microservices structure. This can be a model of programming the place you design your codebase as a set of small, autonomous providers. Every service owns its personal codebase, knowledge storage, and deployment pipelines. As a easy instance, as an alternative of stuffing your whole logic concerning an OpenAI shopper into your essential app, you may transfer that logic into its personal service. To name that service, you’ll then usually make REST calls, versus perform calls. This ups the complexity, however resolves the merge battle and deployment points, since every workforce within the group will get to work on their very own island of code.

    One other profit to utilizing microservices is that they permit for a polyglot tech stack. Because of this every workforce can code up their service utilizing no matter language they like. If one workforce prefers JavaScript whereas one other likes Python, that is no difficulty. After we first started our company, this concept of a polyglot stack pushed us to make use of a microservices structure. Not as a result of we had a big workforce, however as a result of we every wished to make use of the “finest” language for every performance. This meant:

    • Utilizing Ruby on Rails for net improvement. It’s been battle-tested on this space for many years.
    • Utilizing Python for the AI integration, maybe deployed with one thing like FastAPI. Critical AI work requires Python, I used to be led to imagine.

    Two completely different languages, every targeted on its space of specialty. What might go unsuitable?

    Sadly, we discovered the method of improvement irritating. Simply establishing our dev atmosphere was time-consuming. Having to wrangle Docker compose recordsdata and handle inter-service communication made us want we might return to the sweetness and ease of the monolith. Having to make a REST name and arrange the suitable routing in FastAPI as an alternative of creating a easy perform name sucked.

    “Certainly we will’t develop AI apps in pure Ruby,” I assumed. After which I gave it a attempt.

    And I’m glad I did.

    I discovered the method of growing an MVP with AI integration in Ruby very satisfying. We have been capable of dash the place earlier than we have been jogging. I beloved the emphasis on magnificence, simplicity, and developer happiness within the Ruby group. And I discovered the state of the AI ecosystem in Ruby to be surprisingly mature and getting higher every single day.

    If you’re a Python programmer and are scared off by studying a brand new language like I used to be, let me consolation you by discussing the similarities between the Ruby and Python languages.

    Ruby and Python: Two Sides of the Similar Coin

    I think about Python and Ruby to be like cousins. Each languages incorporate:

    • Excessive-level Interpretation: This implies they summary away quite a lot of the complexity of low-level programming particulars, corresponding to reminiscence administration.
    • Dynamic Typing: Neither language requires you to specify if a variable is an int, float, string, and so on. The kinds are checked at runtime.
    • Object-Oriented Programming: Each languages are object-oriented. Each help lessons, inheritance, polymorphism, and so on. Ruby is extra “pure”, within the sense that actually all the things is an object, whereas in Python a couple of issues (corresponding to if and for statements) should not objects.
    • Readable and Concise Syntax: Each are thought-about simple to be taught. Both is nice for a first-time learner.
    • Large Ecosystem of Packages: Packages to do all kinds of cool issues can be found in each languages. In Python they’re known as libraries, and in Ruby they’re known as gems.

    The first distinction between the 2 languages lies of their philosophy and design rules. Python’s core philosophy might be described as:

    There needs to be one — and ideally just one — apparent strategy to do one thing.

    In concept, this could emphasize simplicity, readability, and readability. Ruby’s philosophy might be described as:

    There’s at all times a couple of strategy to do one thing. Maximize developer happiness.

    This was a shock to me once I converted from Python. Take a look at this straightforward instance emphasizing this philosophical distinction:

    # A combat over philosophy: iterating over an array
    # Pythonic means
    for i in vary(1, 6):
        print(i)
    
    # Ruby means, choice 1
    (1..5).every do |i|
      places i
    finish
    
    # Ruby means, choice 2
    for i in 1..5
      places i
    finish
    
    # Ruby means, choice 3
    5.occasions do |i|
      places i + 1
    finish
    
    # Ruby means, choice 4
    (1..5).every  places i 
    

    One other distinction between the 2 is syntax model. Python primarily makes use of indentation to indicate code blocks, whereas Ruby makes use of do…finish or {…} blocks. Most embody indentation inside Ruby blocks, however that is fully non-compulsory. Examples of those syntactic variations might be seen within the code proven above.

    There are quite a lot of different little variations to be taught. For instance, in Python string interpolation is finished utilizing f-strings: f"Hey, {title}!", whereas in Ruby they’re performed utilizing hashtags: "Hey, #{title}!". Inside a couple of months, I feel any competent Python programmer can switch their proficiency over to Ruby.

    Latest AI-based Gems

    Regardless of not being within the dialog when discussing AI, Ruby has had some latest developments on the earth of gems. I’ll spotlight among the most spectacular latest releases that now we have been utilizing in our company to construct AI apps:

    RubyLLM (link) — Any GitHub repo that will get greater than 2k stars inside a couple of weeks of launch deserves a point out, and RubyLLM is unquestionably worthy. I’ve used many clunky implementations of LLM suppliers from libraries like LangChain and LlamaIndex, so utilizing RubyLLM was like a breath of contemporary air. As a easy instance, let’s check out a tutorial demonstrating multi-turn conversations:

    require 'ruby_llm'
    
    # Create a mannequin and provides it directions
    chat = RubyLLM.chat
    chat.with_instructions "You're a pleasant Ruby skilled who loves to assist novices."
    
    # Multi-turn dialog
    chat.ask "Hello! What does attr_reader do in Ruby?"
    # => "Ruby creates a getter technique for every image...
    
    # Stream responses in actual time
    chat.ask "May you give me a brief instance?" do |chunk|
      print chunk.content material
    finish
    # => "Positive!  
    #     ```ruby
    #     class Individual
    #       attr...

    Merely wonderful. Multi-turn conversations are dealt with routinely for you. Streaming is a breeze. Examine this to an analogous implementation in LangChain:

    from langchain_openai import ChatOpenAI
    from langchain_core.schema import SystemMessage, HumanMessage, AIMessage
    from langchain_core.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
    
    SYSTEM_PROMPT = "You're a pleasant Ruby skilled who loves to assist novices."
    chat = ChatOpenAI(streaming=True, callbacks=[StreamingStdOutCallbackHandler()])
    
    historical past = [SystemMessage(content=SYSTEM_PROMPT)]
    
    def ask(user_text: str) -> None:
        """Stream the reply token-by-token and preserve the context in reminiscence."""
        historical past.append(HumanMessage(content material=user_text))
        # .stream yields message chunks as they arrive
        for chunk in chat.stream(historical past):
            print(chunk.content material, finish="", flush=True)
        print()                                          # newline after the reply
        # the ultimate chunk has the total message content material
        historical past.append(AIMessage(content material=chunk.content material))
    
    ask("Hello! What does attr_reader do in Ruby?")
    ask("Nice - might you present a brief instance with attr_accessor?")

    Yikes. And it’s essential to notice that it is a grug implementation. Need to understand how LangChain actually expects you to handle reminiscence? Examine out these links, however seize a bucket first; you might get sick.

    Neighbors (link) — This is a superb library to make use of for nearest-neighbors search in a Rails utility. Very helpful in a RAG setup. It integrates with Postgres, SQLite, MySQL, MariaDB, and extra. It was written by Andrew Kane, the identical man who wrote the pgvector extension that permits Postgres to behave as a vector database.

    Async (link) — This gem had its first official launch again in December 2024, and it has been making waves within the Ruby group. Async is a fiber-based framework for Ruby that runs non-blocking I/O duties concurrently whereas letting you write easy, sequential code. Fibers are like mini-threads that every have their very own mini name stack. Whereas not strictly a gem for AI, it has helped us create options like net scrapers that run blazingly quick throughout hundreds of pages. We now have additionally used it to deal with streaming of chunks from LLMs.

    Torch.rb (link) — If you’re considering coaching deep studying fashions, then absolutely you’ve heard of PyTorch. Nicely, PyTorch is constructed on LibTorch, which basically has quite a lot of C/C++ code beneath the hood to carry out ML operations rapidly. Andrew Kane took LibTorch and made a Ruby adapter over it to create Torch.rb, basically a Ruby model of PyTorch. Andrew Kane has been a hero within the Ruby AI world, authoring dozens of ML gems for Ruby.

    Abstract

    In brief: constructing an internet utility with AI integration rapidly and cheaply requires a monolithic structure. A monolith calls for a monolingual utility, which is important in case your finish objective is high quality apps delivered with pace. Your essential choices are both Python or Ruby. When you go together with Python, you’ll in all probability use Django in your net framework. When you go together with Ruby, you’ll be utilizing Ruby on Rails. At our company, we discovered Django’s lack of options disappointing. Rails has impressed us with its characteristic set and emphasis on simplicity. We have been thrilled to seek out virtually no points on the AI aspect.

    In fact, there are occasions the place you’ll not need to use Ruby. If you’re conducting analysis in AI or coaching machine studying fashions from scratch, then you’ll possible need to stick to Python. Analysis virtually by no means entails constructing Web Applications. At most you’ll construct a easy interface or dashboard in a pocket book, however nothing production-ready. You’ll possible need the newest PyTorch updates to make sure your coaching runs rapidly. It’s possible you’ll even dive into low-level C/C++ programming to squeeze as a lot efficiency as you may out of your {hardware}. Possibly you’ll even attempt your hand at Mojo.

    But when your objective is to combine the newest LLMs — both open or closed supply — into net purposes, then we imagine Ruby to be the far superior choice. Give it a shot yourselves!

    Partially three of this sequence, I’ll dive right into a enjoyable experiment: simply how easy can we make an internet utility with AI integration? Keep tuned.

    🔥 When you’d like a customized net utility with generative AI integration, go to losangelesaiapps.com





    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleLearn Data Science Like a Pro: File Handling — #Day6 | by Ritesh Gupta | May, 2025
    Next Article Does Amazon Owe You a Refund? Here’s What to Know.
    FinanceStarGate

    Related Posts

    Artificial Intelligence

    Use PyTorch to Easily Access Your GPU

    May 21, 2025
    Artificial Intelligence

    What the Most Detailed Peer-Reviewed Study on AI in the Classroom Taught Us

    May 21, 2025
    Artificial Intelligence

    I Teach Data Viz with a Bag of Rocks

    May 20, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    Polars: The Fast and Efficient DataFrame Library for Python | by Shradhdha Bhalodia | Mar, 2025

    March 6, 2025

    Elon Musk Is Committing to Five More Years as Tesla CEO

    May 21, 2025

    Your Data Career Starts Here: DICS Institute in Laxmi Nagar | by Yash | May, 2025

    May 17, 2025

    How to Detect Prompt Injection. Prompt injection tricks AI into… | by Kavitha chauhan | Apr, 2025

    April 18, 2025

    3 Tips to Choose a Trustworthy Business Partner Every Time

    March 27, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Data Science
    • Finance
    • Machine Learning
    • Passive Income
    Most Popular

    From Code to Creativity: Building Multimodal AI Apps with Gemini and Imagen | by Hiralkotwani | May, 2025

    May 15, 2025

    Building a Stock Trading Model Using Artificial Neural Networks (ANN) with Backtrader with the help of ChatGPT | by Cosmin | Mar, 2025

    March 13, 2025

    Sentence Transformers, Bi-Encoders And Cross-Encoders | by Shaza Elmorshidy | Mar, 2025

    March 10, 2025
    Our Picks

    AI Optimizes Headlines for Maximum Clicks & Shares By Daniel Reitberg – Daniel David Reitberg

    February 26, 2025

    AI-Powered Resume & Job Fit Analysis Using Gemini | by Neda | Apr, 2025

    April 15, 2025

    Jddjdkdk

    March 19, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Data Science
    • Finance
    • Machine Learning
    • Passive Income
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2025 Financestargate.com All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.