Welcome to the world of Boxcars, a Ruby gem designed to simplify the process of AI composability. Boxcars allows you to harness the power of various AI concepts such as LLMs, SQL, and searches in a user-friendly way. In this article, we’ll explore how to get started with Boxcars, its key concepts, and troubleshooting tips to help you navigate any challenges.
What is Boxcars?
Boxcars empowers developers to build AI-driven applications by integrating various modular components. Think of Boxcars as a large shopping mall where each store offers different items (Boxcars), and depending on your needs (like a customer), you can choose which stores to visit for what you’re looking for. This setup allows you to mix and match functionalities to create cohesive systems.
Key Concepts
- Boxcar: Encapsulates individual functionalities like search, math, or API calls.
- Train: A structure to break down complex problems into manageable tasks accomplished by individual Boxcars.
- Prompt: Provides the instructions for the Engine to generate corresponding results.
- Engine: The engine drives the output from the Prompt, with defaults set to OpenAI unless overridden.
- VectorStore: A storage solution for querying vectors efficiently.
Installation: How to Get Started
To install Boxcars, take the following steps:
- Add Boxcars to your application’s Gemfile:
gem 'boxcars'
$ bundle install
$ gem install boxcars
How to Use Boxcars
Before you can start leveraging the power of Boxcars, you must set up your environment variables for services like OpenAI. Here’s a quick setup:
require 'dotenv/load'
require 'boxcars'
Now, let’s see how to use a direct Boxcar, such as a calculator:
engine = Boxcars::Openai.new(max_tokens: 256)
calc = Boxcars::Calculator.new(engine: engine)
puts calc.run('what is pi to the fourth power divided by 22.1?')
This will calculate the expression using the OpenAI engine. Boxcars intelligently defaults to OpenAI if no specific engine is provided.
Running a Train
To run multiple Boxcars together in a chain, you can use a Train. Imagine a train where each Boxcar has its function, working together to solve a bigger problem:
boxcars = [Boxcars::Calculator.new, Boxcars::GoogleSearch.new]
train = Boxcars.train.new(boxcars: boxcars)
train.run('What is pi times the square root of the average temperature in Austin TX in January?')
This method breaks down the question and retrieves information from different sources before producing the final answer.
Troubleshooting Tips
If you encounter any issues while working with Boxcars, try the following:
- Ensure all necessary environment variables are correctly set. You can check these with:
puts ENV['OPENAI_ACCESS_TOKEN']
Boxcars.configuration.log_prompts = true
Conclusion
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.
Now that you’re equipped with knowledge about Boxcars, you can explore the endless possibilities it brings. Happy coding!

