foobara-llm-backed-command 0.0.6 → 0.0.8

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: 1a99e4dfeadb80533aa7e5206636a4c5950600730d9851b958c8d7fee30fa6b2
4
+ data.tar.gz: c552bc618a58e71b7613b9d405273843fc92f949f97c35cae356eb2892e90fc4
5
5
  SHA512:
6
- metadata.gz: 24facf55a6108124f8f0109b53acd0e2b5782d52f4ee812f8a7f223f725cdaedbb79a3bad11b0c67efa0253c612edacf50f7db56025c91991dac23e7344306f7
7
- data.tar.gz: 80d4bd1e19ecdfd28b58ff84026ed5245c06dce067a0a7dffb5ed887bf97fe35395274eb2f25a581ab08ba53a7448b9e01dcaf67c032ef07e70c4096cd89994f
6
+ metadata.gz: 37440535a4b5a690efdb7f130e8a88f87e31ee78899316c7a0d1f35410d5f6f50059a853a21e1fccebd9c834b1ac34068bf4f68a4fe85fe89cf1ad055f502d57
7
+ data.tar.gz: 9b09abf6b2ed06f6fb274aac373f4df0a701d8ba5ea6d4257860b93e1bb48f3a673324a808ee354988c5fa7ae13603cfe3efd3d095c5f5d82460ecf84d5ccf20
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.0.8] - 2025-06-19
2
+
3
+ - Convert result type entities to their primary key types with a description
4
+
5
+ ## [0.0.7] - 2025-05-30
6
+
7
+ - Add a could-not-parse-json command error instead of raising
8
+
1
9
  ## [0.0.6] - 2025-05-21
2
10
 
3
11
  - 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
@@ -147,7 +161,10 @@ module Foobara
147
161
  end
148
162
 
149
163
  def result_json_schema
150
- @result_json_schema ||= JsonSchemaGenerator.to_json_schema(result_type)
164
+ @result_json_schema ||= JsonSchemaGenerator.to_json_schema(
165
+ result_type,
166
+ association_depth: JsonSchemaGenerator::AssociationDepth::PRIMARY_KEY_ONLY
167
+ )
151
168
  end
152
169
 
153
170
  def llm_instructions
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.8
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
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 0.0.92
18
+ version: 0.0.132
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: 0.0.92
25
+ version: 0.0.132
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: foobara-ai
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -43,14 +43,14 @@ dependencies:
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 0.0.1
46
+ version: 0.0.6
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: 0.0.1
53
+ version: 0.0.6
54
54
  email:
55
55
  - azimux@gmail.com
56
56
  executables: []
@@ -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.9
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