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项目的代码库,问题跟踪器,聊天室和邮件列表中,每个人都会遵循《行为准则》。