{"id":13592580,"url":"https://github.com/BoxcarsAI/boxcars","last_synced_at":"2025-04-08T23:33:31.958Z","repository":{"id":65914143,"uuid":"599811829","full_name":"BoxcarsAI/boxcars","owner":"BoxcarsAI","description":"Building applications with composability using Boxcars with LLM's. Inspired by LangChain.","archived":false,"fork":false,"pushed_at":"2024-05-16T21:52:20.000Z","size":25960,"stargazers_count":416,"open_issues_count":12,"forks_count":38,"subscribers_count":13,"default_branch":"main","last_synced_at":"2024-05-19T14:32:46.950Z","etag":null,"topics":["activerecord","langchain","openai","ruby","sql"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BoxcarsAI.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-09T23:38:50.000Z","updated_at":"2024-05-28T22:53:56.062Z","dependencies_parsed_at":"2023-12-13T23:33:11.852Z","dependency_job_id":"50ab6e11-7fcf-4c2f-8d63-d940291e3871","html_url":"https://github.com/BoxcarsAI/boxcars","commit_stats":{"total_commits":93,"total_committers":5,"mean_commits":18.6,"dds":"0.10752688172043012","last_synced_commit":"653494e1ed1f8a6205f787d6294ad5f32864e0fc"},"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoxcarsAI%2Fboxcars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoxcarsAI%2Fboxcars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoxcarsAI%2Fboxcars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoxcarsAI%2Fboxcars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BoxcarsAI","download_url":"https://codeload.github.com/BoxcarsAI/boxcars/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223346864,"owners_count":17130519,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","langchain","openai","ruby","sql"],"created_at":"2024-08-01T16:01:10.978Z","updated_at":"2024-11-06T13:31:49.088Z","avatar_url":"https://github.com/BoxcarsAI.png","language":"Ruby","funding_links":[],"categories":["Ports to other languages","Ruby","其他语言移植版本","Open Source"],"sub_categories":["Frameworks"],"readme":"\u003ch2 align=\"center\"\u003eBoxcars\u003c/h2\u003e\n\n\u003ch4 align=\"center\"\u003e\n  \u003ca href=\"https://www.boxcars.ai\"\u003eWebsite\u003c/a\u003e |\n  \u003ca href=\"https://www.boxcars.ai/blog\"\u003eBlog\u003c/a\u003e |\n  \u003ca href=\"https://github.com/BoxcarsAI/boxcars/wiki\"\u003eDocumentation\u003c/a\u003e\n\u003c/h4\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/BoxcarsAI/boxcars/blob/main/LICENSE.txt\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-informational\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nBoxcars is a gem that enables you to create new systems with AI composability, using various concepts such as LLMs (OpenAI, Anthropic, Gpt4all), Search, SQL (with both Sequel and Active Record support), Rails Active Record, Vector Search and more. This can even be extended with your concepts as well (including your concepts).\n\nThis gem was inspired by the popular Python library Langchain. However, we wanted to give it a Ruby spin and make it more user-friendly for beginners to get started.\n\n## Concepts\nAll of these concepts are in a module named Boxcars:\n\n- Boxcar - an encapsulation that performs something of interest (such as search, math, SQL, an Active Record Query, or an API call to a service). A Boxcar can use an Engine (described below) to do its work, and if not specified but needed, the default Engine is used `Boxcars.engine`.\n- Train - Given a list of Boxcars and optionally an Engine, a Train breaks down a problem into pieces for individual Boxcars to solve. The individual results are then combined until a final answer is found. ZeroShot is the only current implementation of Train (but we are adding more soon), and you can either construct it directly or use `Boxcars::train` when you want to build a Train.\n- Prompt - used by an Engine to generate text results. Our Boxcars have built-in prompts, but you have the flexibility to change or augment them if you so desire.\n- Engine - an entity that generates text from a Prompt. OpenAI's LLM text generator is the default Engine if no other is specified, and you can override the default engine if so desired (`Boxcar.configuration.default_engine`). We have an Engine for Anthropic's Claude API named `Boxcars::Anthropic`, and another Engine for GPT named `Boxcars::Gpt4allEng`.\n- VectorStore - a place to store and query vectors.\n\n## Security\nCurrently, our system is designed for individuals who already possess administrative privileges for their project. It is likely possible to manipulate the system's prompts to carry out malicious actions, but if you already have administrative access, you can perform such actions without requiring boxcars in the first place.\n\n*Note:* We are actively seeking ways to improve our system's ability to identify and prevent any nefarious attempts from occurring. If you have any suggestions or recommendations, please feel free to share them with us by either finding an existing issue or creating a new one and providing us with your feedback.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'boxcars'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install boxcars\n\n## Usage\n\nWe will be adding more examples soon, but here are a couple to get you started. First, you'll need to set up your environment variables for services like OpenAI, Anthropic, and Google SERP (OPENAI_ACCESS_TOKEN, ANTHROPIC_API_KEY,SERPAPI_API_KEY) etc. If you prefer not to set these variables in your environment, you can pass them directly into the API.\n\nIn the examples below, we added one Ruby gem to load the environment at the first line, but depending on what you want, you might not need this.\n```ruby\nrequire \"dotenv/load\"\nrequire \"boxcars\"\n```\n\nNote: if you want to try out the examples below, run this command and then paste in the code segments of interest:\n```bash\nirb -r dotenv/load -r boxcars\n\n# or if you prefer local repository\nirb -r dotenv/load -r ./lib/boxcars\n```\n\n### Direct Boxcar Use\n\n```ruby\n# run the calculator\nengine = Boxcars::Openai.new(max_tokens: 256)\ncalc = Boxcars::Calculator.new(engine: engine)\nputs calc.run \"what is pi to the fourth power divided by 22.1?\"\n```\nProduces:\n```text\n\u003e Entering Calculator#run\nwhat is pi to the fourth power divided by 22.1?\nRubyREPL: puts (Math::PI**4)/22.1\nAnswer: 4.407651178009159\n\n{\"status\":\"ok\",\"answer\":\"4.407651178009159\",\"explanation\":\"Answer: 4.407651178009159\",\"code\":\"puts (Math::PI**4)/22.1\"}\n\u003c Exiting Calculator#run\n4.407651178009159\n```\n\nNote that since Openai is currently the most used Engine, if you do not pass in an engine, it will default as expected. So, this is the equivalent shorter version of the above script:\n```ruby\n# run the calculator\ncalc = Boxcars::Calculator.new # just use the default Engine\nputs calc.run \"what is pi to the fourth power divided by 22.1?\"\n```\nYou can change the default_engine with `Boxcars::configuration.default_engine = NewDefaultEngine`\n### Boxcars currently implemented\n\nHere is what we have so far, but please put up a PR with your new ideas.\n- GoogleSearch: uses the SERP API to do searches\n- WikipediaSearch: uses the Wikipedia API to do searches\n- Calculator: uses an Engine to generate ruby code to do math\n- SQL: given an ActiveRecord connection, it will generate and run sql statements from a prompt.\n- ActiveRecord: given an ActiveRecord connection, it will generate and run ActiveRecord statements from a prompt.\n- Swagger: give a Swagger Open API file (YAML or JSON), answer questions about or run against the referenced service. See [here](https://github.com/BoxcarsAI/boxcars/blob/main/notebooks/swagger_examples.ipynb) for examples.\n\n### Run a list of Boxcars\n```ruby\n# run a Train for a calculator, and search using default Engine\nboxcars = [Boxcars::Calculator.new, Boxcars::GoogleSearch.new]\ntrain = Boxcars.train.new(boxcars: boxcars)\ntrain.run \"What is pi times the square root of the average temperature in Austin TX in January?\"\n```\nProduces:\n```text\n\u003e Entering Zero Shot#run\nWhat is pi times the square root of the average temperature in Austin TX in January?\nThought: We need to find the average temperature in Austin TX in January and then multiply it by pi and the square root of the average temperature. We can use a search engine to find the average temperature in Austin TX in January and a calculator to perform the multiplication.\nQuestion: Average temperature in Austin TX in January\nAnswer: January Weather in Austin Texas, United States. Daily high temperatures increase by 2°F, from 62°F to 64°F, rarely falling below 45°F or exceeding 76° ...\nObservation: January Weather in Austin Texas, United States. Daily high temperatures increase by 2°F, from 62°F to 64°F, rarely falling below 45°F or exceeding 76° ...\nThought: We have found the average temperature in Austin TX in January, which is 64°F. Now we can use a calculator to perform the multiplication.\n\u003e Entering Calculator#run\npi * sqrt(64)\nRubyREPL: puts(Math::PI * Math.sqrt(64))\nAnswer: 25.132741228718345\n\n{\"status\":\"ok\",\"answer\":\"25.132741228718345\",\"explanation\":\"Answer: 25.132741228718345\",\"code\":\"puts(Math::PI * Math.sqrt(64))\"}\n\u003c Exiting Calculator#run\nObservation: 25.132741228718345\nWe have the final answer.\n\nFinal Answer: 25.132741228718345\n\nNext Actions:\n1. What is the average temperature in Austin TX in July?\n2. What is the value of pi to 10 decimal places?\n3. What is the square root of the average temperature in Miami FL in January?\n\u003c Exiting Zero Shot#run\n```\n### More Examples\nSee [this](https://github.com/BoxcarsAI/boxcars/blob/main/notebooks/boxcars_examples.ipynb) Jupyter Notebook for more examples.\n\nFor the Swagger boxcar, see [this](https://github.com/BoxcarsAI/boxcars/blob/main/notebooks/swagger_examples.ipynb) Jupyter Notebook.\n\nFor simple vector storage and search, see [this](https://github.com/BoxcarsAI/boxcars/blob/main/notebooks/vector_search_examples.ipynb) Jupyter Notebook.\n\nNote, some folks that we talked to didn't know that you could run Ruby Jupyter notebooks. [You can](https://github.com/SciRuby/iruby).\n\n### Logging\nIf you use this in a Rails application, or configure `Boxcars.configuration.logger = your_logger`, logging will go to your log file.\n\nAlso, if you set this flag: `Boxcars.configuration.log_prompts = true`\nThe actual prompts handed to the connected Engine will be logged. This is off by default because it is very wordy, but handy if you are debugging prompts.\n\nOtherwise, we print to standard out.\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/BoxcarsAI/boxcars. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/BoxcarsAI/boxcars/blob/main/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Boxcars project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/BoxcarsAI/boxcars/blob/main/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBoxcarsAI%2Fboxcars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBoxcarsAI%2Fboxcars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBoxcarsAI%2Fboxcars/lists"}