boxcars 0.4.3 → 0.4.5

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: 2e58db8383158eb46fa9b359ca29822796f46a83e9770ab262af147f2f26516a
4
- data.tar.gz: 261d53fe053d0c3ea7756ee154ff73a077aa5cd2307056f807c20772f06d97bc
3
+ metadata.gz: 10f7d544a53712e622028ebb6dc8e52c9dec9497f6e4436ef0ab456b27885c1e
4
+ data.tar.gz: 44e91be763215a67dec30899f9155b59b43397c225afe3a7e5677b888bc39056
5
5
  SHA512:
6
- metadata.gz: a6629134fb279e4d2556b2a1ec0a1ef43932370099f92b667a8ea45bf355aa9e9dbf5f8ee53cca0c66ba1b09a1198d38cbf168ecb3b7541814d1513287e4f353
7
- data.tar.gz: fc6d01c0497346f7965296f4ebb7c6b69d67d48f4ec4853a1a8235134e50a966f13cd39ef0b488bab4d27caa8da6d907ae885e70fe63a46732fc859c11c5acde
6
+ metadata.gz: ac6c9bd9ff37d2c7ead36371f26f968fdce01ee5f5cfdcc1c9f876d6a879680c10faef74a285ee0fc1e8a1c23656ebe7c650be7d6d04370884566cc09942aa32
7
+ data.tar.gz: 58aaf3c88912de6cd2b6746a7a2b990f05227c9c9369e4fd3b64811f5ed479dc86608c7a60d8f9ce80cd1d26daefa565a6a3d925091190b4d36acfef4b344fc0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.4.3](https://github.com/BoxcarsAI/boxcars/tree/v0.4.3) (2023-09-19)
4
+
5
+ [Full Changelog](https://github.com/BoxcarsAI/boxcars/compare/v0.4.2...v0.4.3)
6
+
3
7
  ## [v0.4.2](https://github.com/BoxcarsAI/boxcars/tree/v0.4.2) (2023-08-05)
4
8
 
5
9
  [Full Changelog](https://github.com/BoxcarsAI/boxcars/compare/v0.4.1...v0.4.2)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- boxcars (0.4.3)
4
+ boxcars (0.4.5)
5
5
  anthropic (~> 0.1)
6
6
  google_search_results (~> 2.2)
7
7
  gpt4all (~> 0.0.4)
@@ -0,0 +1,66 @@
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 JSONEngineBoxcar < EngineBoxcar
7
+ # A JSON Engine Boxcar is a container for a single tool to run.
8
+ attr_accessor :wanted_data, :data_description
9
+
10
+ # @param prompt [Boxcars::Prompt] The prompt to use for this boxcar with sane defaults.
11
+ # @param wanted_data [String] The data to extract from.
12
+ # @param data_description [String] The description of the data.
13
+ # @param kwargs [Hash] Additional arguments
14
+ def initialize(prompt: nil, wanted_data: nil, data_description: nil, **kwargs)
15
+ @wanted_data = wanted_data || "summarize the pertinent facts from the input data"
16
+ @data_description = data_description || "the input data"
17
+ the_prompt = prompt || default_prompt
18
+ kwargs[:description] ||= "JSON Engine Boxcar"
19
+ super(prompt: the_prompt, **kwargs)
20
+ end
21
+
22
+ def default_prompt
23
+ stock_prompt = <<~SYSPR
24
+ I will provide you with %<data_description>s, and your job is to extract information as described below.
25
+
26
+ Your Output must be valid JSON with no lead in or post answer text in the output format below:
27
+
28
+ Output Format:
29
+ {
30
+ %<wanted_data>s
31
+ }
32
+ SYSPR
33
+ sprompt = format(stock_prompt, wanted_data: wanted_data, data_description: data_description)
34
+ ctemplate = [
35
+ Boxcar.syst(sprompt),
36
+ Boxcar.user("%<input>s")
37
+ ]
38
+ conv = Conversation.new(lines: ctemplate)
39
+ ConversationPrompt.new(conversation: conv, input_variables: [:input], other_inputs: [], output_variables: [:answer])
40
+ end
41
+
42
+ # Parse out the action and input from the engine output.
43
+ # @param engine_output [String] The output from the engine.
44
+ # @return [Result] The result.
45
+ def get_answer(engine_output)
46
+ extract_answer(JSON.parse(engine_output))
47
+ rescue StandardError => e
48
+ Result.from_error("Error: #{e.message}:\n#{engine_output}")
49
+ end
50
+
51
+ # get answer from parsed JSON
52
+ # @param data [Hash] The data to extract from.
53
+ # @return [Result] The result.
54
+ def extract_answer(data)
55
+ reply = data
56
+
57
+ if reply.present?
58
+ Result.new(status: :ok, answer: reply, explanation: reply)
59
+ else
60
+ # we have an unexpected output from the engine
61
+ Result.new(status: :error, answer: nil,
62
+ explanation: "You gave me an improperly formatted answer. I was expecting a valid reply.")
63
+ end
64
+ end
65
+ end
66
+ 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/json_engine_boxcar"
214
215
  require "boxcars/boxcar/xml_engine_boxcar"
215
216
  require "boxcars/boxcar/calculator"
216
217
  require "boxcars/boxcar/ruby_calculator"
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Boxcars
4
4
  # The current version of the gem.
5
- VERSION = "0.4.3"
5
+ VERSION = "0.4.5"
6
6
  end
@@ -28,6 +28,7 @@ module Boxcars
28
28
  end
29
29
 
30
30
  def self.from_xml(xml)
31
+ xml = xml[xml.index("<")..-1] unless xml.start_with?("<")
31
32
  doc = Nokogiri::XML.parse(xml)
32
33
  if doc.errors.any?
33
34
  Boxcars.debug("XML: #{xml}", :yellow)
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.3
4
+ version: 0.4.5
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-09-19 00:00:00.000000000 Z
12
+ date: 2023-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: anthropic
@@ -137,6 +137,7 @@ files:
137
137
  - lib/boxcars/boxcar/calculator.rb
138
138
  - lib/boxcars/boxcar/engine_boxcar.rb
139
139
  - lib/boxcars/boxcar/google_search.rb
140
+ - lib/boxcars/boxcar/json_engine_boxcar.rb
140
141
  - lib/boxcars/boxcar/ruby_calculator.rb
141
142
  - lib/boxcars/boxcar/sql_active_record.rb
142
143
  - lib/boxcars/boxcar/sql_base.rb