boxcars 0.4.0 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d131a1f5eb1cb3c6f3cece9c2fcf3246ea81376386b4e7ea23a0d14ee739301
4
- data.tar.gz: 2d0295a8b37da8ab8b7320d9b01c763cd333c5b8f2f20dfe452a54101cd3fd38
3
+ metadata.gz: c3331a78e13cbbd90ee2b5c37d09ee6721ca9f5812654c045649f4555198ace1
4
+ data.tar.gz: 727f2acecdfb28ba6ef6e313f946182ee8569758e62f37d68e32dbf075a62cba
5
5
  SHA512:
6
- metadata.gz: 62ee3e7bf7bf6ba12d07db731195427dd726cc1ecd97ae88998a642d78c48b9e0cfc6c317676f9b37b1007496da6565dba021d513ec26528349c00b41dd0c854
7
- data.tar.gz: 7dd1ae996ad38c616aa62f69c126a5101e4723bbacec3a25e06cf245a9792cc72edc7806d629163fea7f78d61269125ad6f136da47895bca485f928c198a21ef
6
+ metadata.gz: 95adc97ef8b02af5c6ddd9ae5d6463e39df4935290ee902075a2211b02f4968d18d6faf367678a64507b899b88ba9505392ccf166483c3cfbbe211e07aafe8c6
7
+ data.tar.gz: d2d6e03b64404313dc8fa5d9ad671a5be19575cdf0b45e4c4d8b9e05b48a649eb6d8de9d371bab39c508630743c1fd97275d2ae25e324f32d28ac94510c42dd8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,46 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.4.1](https://github.com/BoxcarsAI/boxcars/tree/v0.4.1) (2023-07-25)
4
+
5
+ [Full Changelog](https://github.com/BoxcarsAI/boxcars/compare/v0.4.0...v0.4.1)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Do not use the engine\_prefix to start the LLM prompt for the XML Train [\#106](https://github.com/BoxcarsAI/boxcars/pull/106) ([francis](https://github.com/francis))
10
+ - Adding 16k context [\#105](https://github.com/BoxcarsAI/boxcars/pull/105) ([eltoob](https://github.com/eltoob))
11
+
12
+ ## [v0.4.0](https://github.com/BoxcarsAI/boxcars/tree/v0.4.0) (2023-07-19)
13
+
14
+ [Full Changelog](https://github.com/BoxcarsAI/boxcars/compare/v0.3.5...v0.4.0)
15
+
16
+ **Closed issues:**
17
+
18
+ - Add Anthropic Engine [\#103](https://github.com/BoxcarsAI/boxcars/issues/103)
19
+
20
+ **Merged pull requests:**
21
+
22
+ - Add Anthropic Engine - closes \#103 [\#104](https://github.com/BoxcarsAI/boxcars/pull/104) ([francis](https://github.com/francis))
23
+
24
+ ## [v0.3.5](https://github.com/BoxcarsAI/boxcars/tree/v0.3.5) (2023-07-13)
25
+
26
+ [Full Changelog](https://github.com/BoxcarsAI/boxcars/compare/v0.3.4...v0.3.5)
27
+
28
+ ## [v0.3.4](https://github.com/BoxcarsAI/boxcars/tree/v0.3.4) (2023-07-11)
29
+
30
+ [Full Changelog](https://github.com/BoxcarsAI/boxcars/compare/v0.3.3...v0.3.4)
31
+
32
+ ## [v0.3.3](https://github.com/BoxcarsAI/boxcars/tree/v0.3.3) (2023-07-10)
33
+
34
+ [Full Changelog](https://github.com/BoxcarsAI/boxcars/compare/v0.3.2...v0.3.3)
35
+
36
+ ## [v0.3.2](https://github.com/BoxcarsAI/boxcars/tree/v0.3.2) (2023-07-10)
37
+
38
+ [Full Changelog](https://github.com/BoxcarsAI/boxcars/compare/v0.3.1...v0.3.2)
39
+
40
+ **Merged pull requests:**
41
+
42
+ - add XML Train and XML Zero Shot [\#102](https://github.com/BoxcarsAI/boxcars/pull/102) ([francis](https://github.com/francis))
43
+
3
44
  ## [v0.3.1](https://github.com/BoxcarsAI/boxcars/tree/v0.3.1) (2023-07-01)
4
45
 
5
46
  [Full Changelog](https://github.com/BoxcarsAI/boxcars/compare/v0.2.16...v0.3.1)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- boxcars (0.4.0)
4
+ boxcars (0.4.2)
5
5
  anthropic (~> 0.1)
6
6
  google_search_results (~> 2.2)
7
7
  gpt4all (~> 0.0.4)
data/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  <a href="https://github.com/BoxcarsAI/boxcars/blob/main/LICENSE.txt"><img src="https://img.shields.io/badge/license-MIT-informational" alt="License"></a>
11
11
  </p>
12
12
 
13
- Boxcars 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 an Active Record support), Rails Active Record, Vector Search and more. This can even be extended with your concepts as well (including your concepts).
13
+ Boxcars 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).
14
14
 
15
15
  This 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.
16
16
 
@@ -48,7 +48,7 @@ Or install it yourself as:
48
48
 
49
49
  We 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 OpenAI and Google SERP (OPENAI_ACCESS_TOKEN, SERPAPI_API_KEY). If you prefer not to set these variables in your environment, you can pass them directly into the API.
50
50
 
51
- In the examples below, we added one rubygem to load the environment at the first line, but depending on what you want, you might not need this.
51
+ In 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.
52
52
  ```ruby
53
53
  require "dotenv/load"
54
54
  require "boxcars"
@@ -68,12 +68,12 @@ irb -r dotenv/load -r ./lib/boxcars
68
68
  # run the calculator
69
69
  engine = Boxcars::Openai.new(max_tokens: 256)
70
70
  calc = Boxcars::Calculator.new(engine: engine)
71
- puts calc.run "what is pi to the forth power divided by 22.1?"
71
+ puts calc.run "what is pi to the fourth power divided by 22.1?"
72
72
  ```
73
73
  Produces:
74
74
  ```text
75
75
  > Entering Calculator#run
76
- what is pi to the forth power divided by 22.1?
76
+ what is pi to the fourth power divided by 22.1?
77
77
  RubyREPL: puts (Math::PI**4)/22.1
78
78
  Answer: 4.407651178009159
79
79
 
@@ -82,20 +82,20 @@ Answer: 4.407651178009159
82
82
  4.407651178009159
83
83
  ```
84
84
 
85
- Note 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 equialent shorter version of the above script:
85
+ Note 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:
86
86
  ```ruby
87
87
  # run the calculator
88
88
  calc = Boxcars::Calculator.new # just use the default Engine
89
- puts calc.run "what is pi to the forth power divided by 22.1?"
89
+ puts calc.run "what is pi to the fourth power divided by 22.1?"
90
90
  ```
91
91
  You can change the default_engine with `Boxcars::configuration.default_engine = NewDefaultEngine`
92
92
  ### Boxcars currently implemented
93
93
 
94
94
  Here is what we have so far, but please put up a PR with your new ideas.
95
- - GoogleSearch: uses the SERP API to do seaches
95
+ - GoogleSearch: uses the SERP API to do searches
96
96
  - WikipediaSearch: uses the Wikipedia API to do searches
97
97
  - Calculator: uses an Engine to generate ruby code to do math
98
- - SQL: given an ActiveRecord connection, it will generate and run sql statments from a prompt.
98
+ - SQL: given an ActiveRecord connection, it will generate and run sql statements from a prompt.
99
99
  - ActiveRecord: given an ActiveRecord connection, it will generate and run ActiveRecord statements from a prompt.
100
100
  - 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.
101
101
 
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Boxcars is a framework for running a series of tools to get an answer to a question.
4
+ module Boxcars
5
+ # For Boxcars that use an engine to do their work.
6
+ class XMLEngineBoxcar < EngineBoxcar
7
+ # An XML Engine Boxcar is a container for a single tool to run.
8
+
9
+ # Parse out the action and input from the engine output.
10
+ # @param engine_output [String] The output from the engine.
11
+ # @return [Array<String>] The action and input.
12
+ def get_answer(engine_output)
13
+ xn_get_answer(XNode.from_xml(engine_output))
14
+ end
15
+
16
+ # get answer an XNode
17
+ # @param xnode [XNode] The XNode to use.
18
+ # @return [Array<String, String>] The action and input.
19
+ def xn_get_answer(xnode)
20
+ reply = xnode.xtext("//reply")
21
+
22
+ if reply.present?
23
+ Result.new(status: :ok, answer: reply, explanation: reply)
24
+ else
25
+ # we have an unexpected output from the engine
26
+ Result.new(status: :error, answer: nil,
27
+ explanation: "You gave me an improperly formatted answer or didn't use tags. I was expecting a reply.")
28
+ end
29
+ end
30
+ end
31
+ end
@@ -211,6 +211,7 @@ end
211
211
  require "boxcars/observation"
212
212
  require "boxcars/result"
213
213
  require "boxcars/boxcar/engine_boxcar"
214
+ require "boxcars/boxcar/xml_engine_boxcar"
214
215
  require "boxcars/boxcar/calculator"
215
216
  require "boxcars/boxcar/ruby_calculator"
216
217
  require "boxcars/boxcar/google_search"
@@ -9,9 +9,9 @@ module Boxcars
9
9
 
10
10
  # The default parameters to use when asking the engine.
11
11
  DEFAULT_PARAMS = {
12
- model: "gpt-3.5-turbo",
12
+ model: "gpt-3.5-turbo-16k",
13
13
  temperature: 0.2,
14
- max_tokens: 512
14
+ max_tokens: 2048
15
15
  }.freeze
16
16
 
17
17
  # the default name of the engine
@@ -44,7 +44,7 @@ module Boxcars
44
44
  end
45
45
 
46
46
  def conversation_model?(model)
47
- ["gpt-3.5-turbo", "gpt-4"].include?(model)
47
+ ["gpt-3.5-turbo", "gpt-4", "gpt-3.5-turbo-16k"].include?(model)
48
48
  end
49
49
 
50
50
  # Get an answer from the engine.
@@ -16,7 +16,7 @@ module Boxcars
16
16
  # @param prompt [Boxcars::Prompt] The prompt to use. Defaults to the built-in prompt.
17
17
  # @param kwargs [Hash] Additional arguments to pass to the train. wants_next_actions: true
18
18
  def initialize(boxcars:, engine: nil, name: 'Zero Shot XML', description: 'Zero Shot Train wiht XML', prompt: nil, **kwargs)
19
- @engine_prefix = '<thought>'
19
+ @engine_prefix = ''
20
20
  @wants_next_actions = kwargs.fetch(:wants_next_actions, false)
21
21
  prompt ||= my_prompt
22
22
  super(engine: engine, boxcars: boxcars, prompt: prompt, name: name, description: description, **kwargs)
@@ -33,18 +33,18 @@ module Boxcars
33
33
  " <action>the action to take, from this action list above</action>\n",
34
34
  " <action_input>input to the action</action_input>\n",
35
35
  " <observation>the result of the action</observation>\n",
36
- " ... (this Thought/Action/Action Input/Observation sequence can repeat N times)\n",
36
+ " ... (this thought/action/action_input/observation sequence repeats until you know the final answer) ...\n",
37
37
  " <thought>I know the final answer</thought>\n",
38
38
  " <final_answer>the final answer to the original input question</final_answer>\n",
39
39
  "-- FORMAT END -\n",
40
40
  "Your answer should always have begin and end tags for each element.\n",
41
- "Also make sure to specify a question for the action_input.\n",
42
- "Finally, if you can deduct the answer from the question or observation, you can ",
41
+ "Also make sure to specify arguments for the action_input.\n",
42
+ "Finally, if you can deduct the answer from the question or observations, you can ",
43
43
  "jump to final_answer and give me the answer.\n",
44
44
  "</training>"),
45
45
  hist, # insert thoughts here from previous runs
46
46
  user("<question>%<input>s</question>"),
47
- assi("<thought>%<agent_scratchpad>s")
47
+ assi("%<agent_scratchpad>s")
48
48
  ].freeze
49
49
 
50
50
  # The prompt to use for the train.
data/lib/boxcars/train.rb CHANGED
@@ -45,7 +45,7 @@ module Boxcars
45
45
  # @param intermediate_steps [Array] The intermediate steps to build the scratchpad from.
46
46
  # @return [String] The scratchpad.
47
47
  def construct_scratchpad(intermediate_steps)
48
- thoughts = ""
48
+ thoughts = engine_prefix.to_s
49
49
  intermediate_steps.each do |action, observation|
50
50
  thoughts += action.is_a?(String) ? action : " #{action.log}"
51
51
  thoughts += "\n#{observation_text(observation)}\n#{engine_prefix}"
@@ -189,8 +189,8 @@ module Boxcars
189
189
  return boxcar_result unless using_xml
190
190
 
191
191
  if boxcar_result.is_a?(Result)
192
- boxcar_result.answer = boxcar_result.answer.encode(xml: :text)
193
- else
192
+ boxcar_result.answer = boxcar_result.answer.encode(xml: :text) if boxcar_result.answer.is_a?(String)
193
+ elsif boxcar_result.is_a?(String)
194
194
  boxcar_result = boxcar_result.encode(xml: :text)
195
195
  end
196
196
  boxcar_result
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Boxcars
4
4
  # The current version of the gem.
5
- VERSION = "0.4.0"
5
+ VERSION = "0.4.2"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxcars
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francis Sullivan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-07-19 00:00:00.000000000 Z
12
+ date: 2023-08-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: anthropic
@@ -145,6 +145,7 @@ files:
145
145
  - lib/boxcars/boxcar/url_text.rb
146
146
  - lib/boxcars/boxcar/vector_answer.rb
147
147
  - lib/boxcars/boxcar/wikipedia_search.rb
148
+ - lib/boxcars/boxcar/xml_engine_boxcar.rb
148
149
  - lib/boxcars/conversation.rb
149
150
  - lib/boxcars/conversation_prompt.rb
150
151
  - lib/boxcars/engine.rb