Boxcars是一種GEM,它使您可以使用LLMS(OpenAI,Anthropic,GPT4All),Search,SQL(具有續集和主動記錄支持),Rails Active Record,vector搜索等各種概念來創建具有AI合併性的新系統。甚至可以通過您的概念(包括您的概念)來擴展這一點。
這顆寶石的靈感來自受歡迎的Python圖書館Langchain。但是,我們想給它一個紅寶石旋轉,並使初學者更加用戶友好。
所有這些概念都在一個名為boxcars的模塊中:
Boxcars.engine 。Boxcars::train 。Boxcar.configuration.default_engine )。我們為人類的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)等服務設置環境變量。
在下面的示例中,我們添加了一個Ruby Gem在第一行加載環境,但是根據您想要的內容,您可能不需要。
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
這是我們到目前為止所擁有的,但是請與您的新想法相處。
# 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將記錄交給連接發動機的實際提示。默認情況下,這是因為它非常W rawty,但是如果您要調試提示,則很方便。
否則,我們打印到標準。
檢查回購後,運行bin/setup以安裝依賴關係。然後,運行rake spec以運行測試。您還可以運行bin/console以獲得交互提示,該提示可以讓您進行實驗。
要將此GEM安裝到本地計算機上,請運行bundle exec rake install 。要發布新版本,請在version.rb中更新版本編號,然後運行bundle exec rake release ,該版本將為版本創建一個git標籤,推送git consits和創建標籤,然後將.gem文件推到rubygems.org。
歡迎在https://github.com/boxcarsai/boxcars上的GitHub上的錯誤報告和拉動請求。該項目旨在是一個安全,熱情的協作空間,預計貢獻者將遵守行為準則。
根據MIT許可證的條款,該寶石可作為開源。
在BoxCars項目的代碼庫,問題跟踪器,聊天室和郵件列表中,每個人都會遵循《行為準則》。