boxcars 0.2.3 → 0.2.4

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: ea9c5df0584f588d618c22fc44f8bba2638c0946ba32cea8487429ad6df694f5
4
- data.tar.gz: a7cd6609da5d63c1b41763fc7c6e8b4e1c8df41992fd133d0bf359b28d50dd0c
3
+ metadata.gz: 6a9d94c026cf616e590d293d4ef2b0c655ddc6e3ae40115b36ebbfbbee1cb9a4
4
+ data.tar.gz: 549a877fdf1b329f402f3a159420bc6599677bcd40f2776c8bea57fade099b14
5
5
  SHA512:
6
- metadata.gz: aac8bd34e6ddca629d26ff0cb892e46de30e1f20db188b56477422e5526e03c80a22e1b06ab7d8263e8db067db6ec1966f34450ab63e98cea3e857aa7eb27286
7
- data.tar.gz: 10ce3be58a020a5de80c27fdf46cbd7811afc45ac28e0712479b113eb6a34ca6a2f7043711659bb4b0a152e0981ded5a8f76fe0704f1a89751b3c8ec0a843ea8
6
+ metadata.gz: '082a569848bf46276dadf9e2461e1bded9e107a2ba344fed06382c98548aa78b5012c63cdeeb27f394783b25bb6dea6d6bd10382d1f0113b8de548a366ca2b4e'
7
+ data.tar.gz: 25452562685c57ba7ded3de67a4c27f7d15e9373f5370f061d75d9d4f32e4e1836e9ea6947bfef19d7a32fe6c130d4f816fe5d9529ea1db5f38f7b0bb2837ccb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- boxcars (0.2.3)
4
+ boxcars (0.2.4)
5
5
  google_search_results (~> 2.2)
6
6
  ruby-openai (~> 3.0)
7
7
 
data/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  <a href="https://github.com/BoxcarsAI/boxcars/blob/main/LICENSE.txt"><img src="https://img.shields.io/badge/license-MIT-informational" alt="License"></a>
12
12
  </p>
13
13
 
14
- Boxcars is a gem that enables you to create new systems with AI composability, using various concepts such as OpenAI, Search, SQL, Rails Active Record and more. This can even be extended with your concepts as well.(including your concepts).
14
+ Boxcars is a gem that enables you to create new systems with AI composability, using various concepts such as OpenAI, Search, SQL, Rails Active Record and more. This can even be extended with your concepts as well (including your concepts).
15
15
 
16
16
  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.
17
17
 
@@ -23,6 +23,11 @@ All of these concepts are in a module named Boxcars:
23
23
  - Prompt - used by an Engine to generate text results. Most of the Boxcars have built-in prompts, so you only need to worry about these if you are extending the system.
24
24
  - Engine - an entity that generates text from a Prompt. OpenAI's LLM text generator is the default Engine if no other is specified.
25
25
 
26
+ ## Security
27
+ Currently, 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.
28
+
29
+ *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.
30
+
26
31
  ## Installation
27
32
 
28
33
  Add this line to your application's Gemfile:
@@ -66,10 +71,10 @@ Produces:
66
71
  ```text
67
72
  > Entering Calculator#run
68
73
  what is pi to the forth power divided by 22.1?
69
- RubyREPL: puts(Math::PI**4 / 22.1)
74
+ RubyREPL: puts (Math::PI**4)/22.1
70
75
  Answer: 4.407651178009159
71
76
 
72
- 4.407651178009159
77
+ {"status":"ok","answer":"4.407651178009159","explanation":"Answer: 4.407651178009159","code":"puts (Math::PI**4)/22.1"}
73
78
  < Exiting Calculator#run
74
79
  4.407651178009159
75
80
  ```
@@ -94,27 +99,34 @@ Here is what we have so far, but please put up a PR with your new ideas.
94
99
  # run a Train for a calculator, and search using default Engine
95
100
  boxcars = [Boxcars::Calculator.new, Boxcars::Serp.new]
96
101
  train = Boxcars.train.new(boxcars: boxcars)
97
- puts train.run "What is pi times the square root of the average temperature in Austin TX in January?"
102
+ train.run "What is pi times the square root of the average temperature in Austin TX in January?"
98
103
  ```
99
104
  Produces:
100
105
  ```text
101
106
  > Entering Zero Shot#run
102
107
  What is pi times the square root of the average temperature in Austin TX in January?
108
+ Thought: We need to find the average temperature in Austin TX in January and then multiply it by pi and the square root of that value. We can use a search engine to find the average temperature and a calculator to perform the multiplication.
103
109
  Question: Average temperature in Austin TX in January
104
110
  Answer: increase from 62°F to 64°F
105
- #Observation: increase from 62°F to 64°F
111
+ Observation: increase from 62°F to 64°F
112
+ Thought: The average temperature in Austin TX in January is around 63°F.
106
113
  > Entering Calculator#run
107
- 64°F x pi
108
- RubyREPL: puts (64 * Math::PI).round(2)
109
- Answer: 201.06
114
+ pi * sqrt(63)
115
+ RubyREPL: puts(Math::PI * Math.sqrt(63))
116
+ Answer: 24.935618646198247
110
117
 
111
- 201.06
118
+ {"status":"ok","answer":"24.935618646198247","explanation":"Answer: 24.935618646198247","code":"puts(Math::PI * Math.sqrt(63))"}
112
119
  < Exiting Calculator#run
113
- #Observation: 201.06
114
- I now know the final answer
115
- Final Answer: 201.06
120
+ Observation: 24.935618646198247
121
+ The result of pi times the square root of the average temperature in Austin TX in January is approximately 24.94.
122
+
123
+ Final Answer: 24.94
124
+
125
+ Next Actions:
126
+ 1. What is the average temperature in Austin TX in July?
127
+ 2. What is the formula for calculating the area of a circle?
128
+ 3. What is the value of pi to 10 decimal places?
116
129
  < Exiting Zero Shot#run
117
- 201.06
118
130
  ```
119
131
  ### More Examples
120
132
  See [this](https://github.com/BoxcarsAI/boxcars/blob/main/notebooks/boxcars_examples.ipynb) Jupyter Notebook for more examples.
@@ -76,7 +76,7 @@ module Boxcars
76
76
  ::ActiveRecord::Base.transaction do
77
77
  begin
78
78
  result = yield
79
- rescue ::NameError, ::Error => e
79
+ rescue SecurityError, ::NameError, ::Error => e
80
80
  Boxcars.error("Error while running code: #{e.message[0..60]} ...", :red)
81
81
  runtime_exception = e
82
82
  end
@@ -93,13 +93,22 @@ module Boxcars
93
93
  bad_words = %w[commit drop_constraint drop_constraint! drop_extension drop_extension! drop_foreign_key drop_foreign_key! \
94
94
  drop_index drop_index! drop_join_table drop_join_table! drop_materialized_view drop_materialized_view! \
95
95
  drop_partition drop_partition! drop_schema drop_schema! drop_table drop_table! drop_trigger drop_trigger! \
96
- drop_view drop_view! eval execute reset revoke rollback truncate].freeze
96
+ drop_view drop_view! eval instance_eval send system execute reset revoke rollback truncate \
97
+ encrypted_password].freeze
97
98
  without_strings = code.gsub(/('([^'\\]*(\\.[^'\\]*)*)'|"([^"\\]*(\\.[^"\\]*)*"))/, 'XX')
98
- word_list = without_strings.split(/[.,()]/)
99
+
100
+ if without_strings.include?("`")
101
+ Boxcars.info "code included possibly destructive backticks #{code}", :red
102
+ return false
103
+ end
104
+
105
+ word_list = without_strings.split(/[.,() :]/)
106
+
107
+ puts word_list.inspect
99
108
 
100
109
  bad_words.each do |w|
101
110
  if word_list.include?(w)
102
- Boxcars.info "code included destructive instruction: #{w} #{code}", :red
111
+ Boxcars.info "code included possibly destructive instruction: '#{w}' in #{code}", :red
103
112
  return false
104
113
  end
105
114
  end
@@ -176,7 +185,7 @@ module Boxcars
176
185
  have_approval = false
177
186
  begin
178
187
  have_approval = approved?(changes_code, code)
179
- rescue NameError, ::Error => e
188
+ rescue NameError, Error => e
180
189
  return Result.new(status: :error, explanation: error_message(e, "ARChanges"), changes_code: changes_code)
181
190
  end
182
191
 
@@ -185,7 +194,9 @@ module Boxcars
185
194
  begin
186
195
  output = clean_up_output(run_active_record_code(code))
187
196
  Result.new(status: :ok, answer: output, explanation: "Answer: #{output.to_json}", code: code)
188
- rescue NameError, ::Error => e
197
+ rescue SecurityError => e
198
+ raise e
199
+ rescue ::StandardError => e
189
200
  Result.new(status: :error, answer: nil, explanation: error_message(e, "ARCode"), code: code)
190
201
  end
191
202
  end
@@ -100,7 +100,7 @@ module Boxcars
100
100
  end
101
101
  Boxcars.error answer.to_json, :red
102
102
  { output_key => "Error: #{answer}" }
103
- rescue Boxcars::ConfigurationError => e
103
+ rescue Boxcars::ConfigurationError, Boxcars::SecurityError => e
104
104
  raise e
105
105
  rescue Boxcars::Error => e
106
106
  Boxcars.error e.message, :red
@@ -49,8 +49,8 @@ module Boxcars
49
49
  [:answer_box, :snippet_highlighted_words, 0],
50
50
  %i[sports_results game_spotlight],
51
51
  %i[knowledge_graph description],
52
- [:organic_results, 0, :snippet_highlighted_words, 0],
53
- [:organic_results, 0, :snippet]
52
+ [:organic_results, 0, :snippet],
53
+ [:organic_results, 0, :snippet_highlighted_words, 0]
54
54
  ].freeze
55
55
 
56
56
  def find_answer(res)
@@ -50,7 +50,7 @@ module Boxcars
50
50
  # the thought should be the frist line here if it doesn't start with "Action:"
51
51
  thought = engine_output.split(/\n+/).reject(&:empty?).first
52
52
  Boxcars.debug("Thought: #{thought}", :yellow)
53
- regex = /Action: (?<action>.*)\n+Action Input: (?<action_input>.*)/
53
+ regex = /Action(?<extra>[\s\d]*): (?<action>.+?)\n+Action Input:(?<action_input>.+)/m
54
54
  match = regex.match(engine_output)
55
55
 
56
56
  # we have an unexpected output from the engine
data/lib/boxcars/train.rb CHANGED
@@ -196,6 +196,8 @@ module Boxcars
196
196
  begin
197
197
  observation = boxcar.run(output.boxcar_input)
198
198
  return_direct = boxcar.return_direct
199
+ rescue Boxcars::ConfigurationError, Boxcars::SecurityError => e
200
+ raise e
199
201
  rescue StandardError => e
200
202
  Boxcars.error "Error in #{boxcar.name} boxcar#call: #{e}", :red
201
203
  observation = "Error - #{e}, correct and try again."
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Boxcars
4
4
  # The current version of the gem.
5
- VERSION = "0.2.3"
5
+ VERSION = "0.2.4"
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.2.3
4
+ version: 0.2.4
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-03-20 00:00:00.000000000 Z
12
+ date: 2023-03-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: debug