BoxCarsは、LLMS(Openai、Anthropic、GPT4All)、Search、SQL(続編とアクティブレコードサポートの両方)、Rails Active Record、Vector Searchなどのさまざまな概念を使用して、AIコンポジットを備えた新しいシステムを作成できる宝石です。これは、概念(概念を含む)でも拡張することもできます。
この宝石は、人気のPythonライブラリLangchainに触発されました。しかし、私たちはそれにRubyスピンを与え、初心者が始めるためにそれをよりユーザーフレンドリーにしたかったのです。
これらの概念はすべて、BoxCarsという名前のモジュールにあります。
Boxcars.engineを使用します。Boxcars::trainを使用できます。Boxcar.configuration.default_engine )。 AnthropicのClaude API用のエンジンはBoxcars::Anthropic 、GPTという名前の別のエンジンがBoxcars::Gpt4allEngです。現在、当社のシステムは、プロジェクトの管理特権をすでに持っている個人向けに設計されています。システムのプロンプトを操作して悪意のあるアクションを実行することは可能性がありますが、すでに管理アクセスがある場合は、そもそもボックスカーを必要とせずにそのようなアクションを実行できます。
注:私たちは、邪悪な試みが発生するのを特定し、防止するシステムの能力を向上させる方法を積極的に求めています。提案や推奨事項がある場合は、既存の問題を見つけたり、新しい問題を作成したり、フィードバックを提供したりすることで、お気軽に共有してください。
この行をアプリケーションのGemfileに追加します。
gem 'boxcars'そして実行してください:
$ bundle install
または、自分でインストールします:
$ gem install boxcars
すぐにさらに例を追加しますが、ここにあなたが始めるためのカップルがあります。まず、OpenAI、Anthropic、Google SERP(Openai_access_token、Anthropic_api_key、Serpapi_api_key)などのサービスの環境変数を設定する必要があります。これらの変数を環境に設定したくない場合は、APIに直接渡すことができます。
以下の例では、1つのRuby宝石を追加して最初の行に環境をロードしましたが、必要なものに応じて、これは必要ないかもしれません。
require "dotenv/load"
require "boxcars"注:以下の例を試してみたい場合は、このコマンドを実行してから、関心のあるコードセグメントに貼り付けます。
irb -r dotenv/load -r boxcars
# or if you prefer local repository
irb -r dotenv/load -r ./lib/boxcars # run the 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?"プロデュース:
> Entering Calculator#run
what is pi to the fourth power divided by 22.1?
RubyREPL: puts (Math::PI**4)/22.1
Answer: 4.407651178009159
{"status":"ok","answer":"4.407651178009159","explanation":"Answer: 4.407651178009159","code":"puts (Math::PI**4)/22.1"}
< Exiting Calculator#run
4.407651178009159
Openaiは現在最も使用されているエンジンであるため、エンジンを通過しない場合、予想どおりにデフォルトになることに注意してください。したがって、これは上記のスクリプトの同等の短いバージョンです。
# run the calculator
calc = Boxcars :: Calculator . new # just use the default Engine
puts calc . run "what is pi to the fourth power divided by 22.1?" Boxcars::configuration.default_engine = NewDefaultEngineを使用してDefault_Engineを変更できます
これまでに私たちが持っているものはありますが、あなたの新しいアイデアでPRを掲載してください。
# run a Train for a calculator, and search using default Engine
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?"プロデュース:
> Entering Zero Shot#run
What is pi times the square root of the average temperature in Austin TX in January?
Thought: 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.
Question: Average temperature in Austin TX in January
Answer: 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° ...
Observation: 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° ...
Thought: 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.
> Entering Calculator#run
pi * sqrt(64)
RubyREPL: puts(Math::PI * Math.sqrt(64))
Answer: 25.132741228718345
{"status":"ok","answer":"25.132741228718345","explanation":"Answer: 25.132741228718345","code":"puts(Math::PI * Math.sqrt(64))"}
< Exiting Calculator#run
Observation: 25.132741228718345
We have the final answer.
Final Answer: 25.132741228718345
Next Actions:
1. What is the average temperature in Austin TX in July?
2. What is the value of pi to 10 decimal places?
3. What is the square root of the average temperature in Miami FL in January?
< Exiting Zero Shot#run
その他の例については、このJupyterノートを参照してください。
Swagger BoxCarについては、このJupyterノートブックを参照してください。
簡単なベクトルストレージと検索については、このJupyterノートブックを参照してください。
注、私たちが話した人の中には、Ruby Jupyterノートブックを実行できることを知りませんでした。あなたはできる。
これをRailsアプリケーションで使用する場合、またはBoxcars.configuration.logger = your_loggerを構成する場合、ログはログファイルに移動します。
また、このフラグを設定した場合: Boxcars.configuration.log_prompts = true接続されたエンジンに渡された実際のプロンプトは記録されます。これはデフォルトでは非常に言葉がありますが、プロンプトをデバッグしている場合は便利です。
それ以外の場合は、Standard Outに印刷します。
リポジトリをチェックアウトした後、 bin/setupを実行して依存関係をインストールします。次に、 rake specを実行してテストを実行します。また、実験を可能にするインタラクティブなプロンプトのbin/consoleを実行することもできます。
この宝石をローカルマシンにインストールするには、 bundle exec rake install実行します。新しいバージョンをリリースするには、 version.rbのバージョンbundle exec rake releaseを更新してから、バージョンのgitタグを作成し、Git Commitsと作成したタグをプッシュし、 .gemファイルをRubygems.orgにプッシュします。
バグレポートとプルリクエストは、https://github.com/boxcarsai/boxcarsのGithubで大歓迎です。このプロジェクトは、コラボレーションのための安全で居心地の良いスペースであることを目的としており、貢献者は行動規範を遵守することが期待されています。
宝石は、MITライセンスの条件の下でオープンソースとして利用できます。
BoxCarsプロジェクトのコードベース、発行トラッカー、チャットルーム、メーリングリストで対話する全員が、行動規範に従うことが期待されています。