Introduction to Boxcars
Boxcars is an innovative gem designed to help developers create new systems with AI composability. It does so by leveraging a variety of concepts such as Language Model Models (LLMs) including OpenAI and Anthropic, search functionalities, SQL with Sequel and Active Record support, the Rails Active Record, and Vector Search, among others. This flexibility allows users to extend the gem by incorporating their own custom concepts as well.
Boxcars was inspired by the popular Python library Langchain, but adds a unique Ruby touch to make it more accessible for beginners.
Core Concepts
Boxcar
A Boxcar in the Boxcars module is essentially an encapsulation that performs tasks such as search queries, mathematical computations, SQL queries, Active Record queries, or API calls. Each Boxcar can operate using an Engine to fulfill its purpose. If no Engine is specified, a default Engine (Boxcars.engine
) is used.
Train
A Train is a mechanism that takes a list of Boxcars and an optional Engine to solve a problem by breaking it down into smaller tasks for each Boxcar to address. The results from each Boxcar are combined to reach a final solution. Currently, ZeroShot is the only Train implementation available, with more examples in development.
Prompt
Prompts are used by Engines to generate text results. While Boxcars come with built-in prompts, users have the flexibility to modify them as needed.
Engine
Engines generate text from a Prompt and OpenAI's LLM text generator is the default, which can be overridden. Boxcars has engines like Boxcars::Anthropic
for Anthropic's Claude API, and Boxcars::Gpt4allEng
for GPT.
VectorStore
This is a storage area for storing and querying vectors essential for advanced AI operations.
Security and Development Considerations
Boxcars is intended for users who already have administrative access to their projects. There is potential vulnerability if prompts are manipulated for malicious activities, though typically administrative access would already allow such actions without Boxcars. The project team actively seeks to enhance system security by preventing these actions through community feedback and collaboration.
Installation and Usage
To install Boxcars, add the following line to your Gemfile:
gem 'boxcars'
Execute the installation with:
$ bundle install
Alternatively, you can install it directly with:
$ gem install boxcars
Basic Usage
Setting up environment variables for third-party services like OpenAI, Anthropic, and Google SERP is required for basic usage. An example Ruby script initializes a Boxcar and utilizes OpenAI's engine to perform calculations:
require "dotenv/load"
require "boxcars"
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?"
The output reveals the calculation process and result. If no engine is passed, the default OpenAI engine is used automatically.
Available Boxcars
Boxcars comes with several predefined functionalities:
- GoogleSearch: uses the SERP API for searches
- WikipediaSearch: utilizes the Wikipedia API
- Calculator: creates Ruby code for calculations
- SQL: generates and executes SQL statements
- ActiveRecord: creates and executes ActiveRecord queries
- Swagger: interacts with a Swagger Open API file for service operations
Building More Complex Projects
For more complex operations, a Train can run multiple Boxcars tasks in sequence:
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 combines multiple inputs and outputs to achieve an overarching goal.
Development and Contributions
Developers are encouraged to check out the repository, run tests, and experiment using interactive prompts. To contribute, one can report bugs or submit pull requests on GitHub. Boxcars is governed by a code of conduct to ensure a respectful, collaborative environment.
Licensing
Boxcars is available under the MIT License. This makes it open source and allows for wide usage and contributions.
The Boxcars project offers immense potential for developers looking to leverage AI and Ruby in new, innovative ways while providing an easy entry point for beginners. With continued development, the possibilities are only set to increase.