foobara-llm-backed-command 0.0.6 → 0.0.7

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: b425fcdb4e888c59b2bc32f4a7c4a4d066b11cf6fcfee6f6dcb8fc00da88cc21
4
- data.tar.gz: b27ebd00c36a49a2e79001e1122e783a4dcd1406a4d5ef61891af726c64821df
3
+ metadata.gz: 2d0fd4526fdfafec7f3f36b2734206b6d5a21e9af138081344b7662bb192e0df
4
+ data.tar.gz: 471ddc74cdd4782c46c74ae5c872eb698b85a73514474a945968776477303137
5
5
  SHA512:
6
- metadata.gz: 24facf55a6108124f8f0109b53acd0e2b5782d52f4ee812f8a7f223f725cdaedbb79a3bad11b0c67efa0253c612edacf50f7db56025c91991dac23e7344306f7
7
- data.tar.gz: 80d4bd1e19ecdfd28b58ff84026ed5245c06dce067a0a7dffb5ed887bf97fe35395274eb2f25a581ab08ba53a7448b9e01dcaf67c032ef07e70c4096cd89994f
6
+ metadata.gz: 45197b581cef44bf69b6b75fe158c045d03670902f008e213db2e76d5d148d2bb152ebf7cda5ebe7163856ea490934d09d27a29798c3da86726cd2ded442aaa9
7
+ data.tar.gz: bfdcfae305ed54a01e78cc50ffcd6addd3bac578d8201638790d4b7b28b0a27e24f1edd78f2aa72b9586b5ff15ae45f766cf7e8514e596ff9f162fee089eccfb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.0.7] - 2025-05-30
2
+
3
+ - Add a could-not-parse-json command error instead of raising
4
+
1
5
  ## [0.0.6] - 2025-05-21
2
6
 
3
7
  - Give an error if no ai api services have been provided
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Foobara::LlmBackedCommand/Foobara::LlmBackedExecuteMethod
1
+ # Foobara::LlmBackedCommand
2
2
 
3
- Provides a clean and quick way to implement a Foobara::Command that defers to an LLM for the answer
3
+ Extract knowledge and decisions from LLMs in a programmatically useful way with ease!
4
4
 
5
5
  <!-- TOC -->
6
6
  * [Foobara::LlmBackedCommand/Foobara::LlmBackedExecuteMethod](#foobarallmbackedcommandfoobarallmbackedexecutemethod)
@@ -11,6 +11,12 @@ module Foobara
11
11
 
12
12
  on_include do
13
13
  depends_on Ai::AnswerBot::Ask
14
+ possible_error :could_not_parse_result_json,
15
+ message: "Could not parse answer",
16
+ context: {
17
+ raw_answer: :string,
18
+ stripped_answer: :string
19
+ }
14
20
  end
15
21
 
16
22
  def execute
@@ -77,24 +83,32 @@ module Foobara
77
83
  def parse_answer
78
84
  stripped_answer = answer.gsub(/<THINK>.*?<\/THINK>/mi, "")
79
85
  fencepostless_answer = stripped_answer.gsub(/^\s*```\w*\n(.*)```\s*\z/m, "\\1")
86
+
80
87
  # TODO: should we verify against json-schema or no?
81
88
  self.parsed_answer = begin
82
89
  JSON.parse(fencepostless_answer)
83
- rescue => e
90
+ rescue JSON::ParserError
84
91
  # see if we can extract the last fence-posts content just in case
85
92
  last_fence_post_regex = /```\w*\s*\n((?:(?!```).)+)\n```(?:(?!```).)*\z/m
93
+
86
94
  begin
87
95
  match = last_fence_post_regex.match(stripped_answer)
96
+
88
97
  if match
89
- JSON.parse(match[1])
98
+ fencepostless_answer = match[1]
99
+ JSON.parse(fencepostless_answer)
90
100
  else
91
101
  # :nocov:
92
- raise e
102
+ raise
93
103
  # :nocov:
94
104
  end
95
- rescue
105
+ rescue JSON::ParserError => e
106
+ # TODO: figure out how to test this code path
96
107
  # :nocov:
97
- raise e
108
+ add_runtime_error :could_not_parse_result_json,
109
+ "Could not parse result JSON: #{e.message}",
110
+ raw_answer: answer,
111
+ stripped_answer: fencepostless_answer
98
112
  # :nocov:
99
113
  end
100
114
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-llm-backed-command
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-21 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: foobara
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
- rubygems_version: 3.6.2
89
+ rubygems_version: 3.6.7
90
90
  specification_version: 4
91
91
  summary: Provides an easy way to implement a command whose logic is managed by an
92
92
  LLM