boxcars 0.4.4 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8de5394d5685d1b4deaa0c3c600b2211c6eda983d00fe474d25beb8733e11cce
4
- data.tar.gz: 73bf2070533a235a8c3e6036d6f48465fc6d4ed22d8b120797d87441cb2657f9
3
+ metadata.gz: 10f7d544a53712e622028ebb6dc8e52c9dec9497f6e4436ef0ab456b27885c1e
4
+ data.tar.gz: 44e91be763215a67dec30899f9155b59b43397c225afe3a7e5677b888bc39056
5
5
  SHA512:
6
- metadata.gz: c7996425e870726fc4a0e395fbf1a2f68b5bae9e584998fdbb6250aace415cdbc5953272871be8127df48a274548b5c5e34a6e8470f822c936b8b8c3df15333c
7
- data.tar.gz: d3231558be47f6496dab661f63592ef4d44c9eb0426f4686a4caacd548b1dd1c2d68f1c1b8cfa97b2e3c3929c86531a121d4dee9473d16360931b44b30f8903e
6
+ metadata.gz: ac6c9bd9ff37d2c7ead36371f26f968fdce01ee5f5cfdcc1c9f876d6a879680c10faef74a285ee0fc1e8a1c23656ebe7c650be7d6d04370884566cc09942aa32
7
+ data.tar.gz: 58aaf3c88912de6cd2b6746a7a2b990f05227c9c9369e4fd3b64811f5ed479dc86608c7a60d8f9ce80cd1d26daefa565a6a3d925091190b4d36acfef4b344fc0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- boxcars (0.4.4)
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.4"
5
+ VERSION = "0.4.5"
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.4
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-10-03 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