foobara-llm-backed-command 1.0.1 → 1.0.3
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/foobara/llm_backed_command.rb +2 -2
- data/src/llm_backed_execute_method.rb +37 -11
- metadata +7 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: db414e87fff804a75d681c2ab455fbb8c451de1ef45e1b9372057700fbf6f2a0
|
|
4
|
+
data.tar.gz: 5ea0d6368f246450905e30625f69341cce3512312a0ed707dbc463e16160a36b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6a81124c1e05859be811881e0ec32a850bb42f8d1e314af3e11fdac4c9c803472f2428f1b5345da58447fc00641c09ceaf1de2bf41ab64677bdd141b2519770b
|
|
7
|
+
data.tar.gz: e84c195fade06f93fb2a86d472af0a6c2b68a57f529cd96e9bcec35705d649a5bd0100c5201ebf71954d7d13cdfb703a46fb529a2330a7799038d574d3526ef4
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## [1.0.3] - 2026-09-11
|
|
2
|
+
|
|
3
|
+
- Handle removed JSON.fast_generate
|
|
4
|
+
|
|
5
|
+
## [1.0.2] - 2025-08-11
|
|
6
|
+
|
|
7
|
+
- Handle situation where smaller models incorrectly use {"result":"whatever"} instead of "whatever"
|
|
8
|
+
|
|
1
9
|
## [1.0.1] - 2025-07-09
|
|
2
10
|
|
|
3
11
|
- Use foobara-ai version 1.0.0
|
|
@@ -5,10 +5,10 @@ require "foobara/ai"
|
|
|
5
5
|
require "foobara/json_schema_generator"
|
|
6
6
|
|
|
7
7
|
if Foobara::Ai.foobara_all_command.empty?
|
|
8
|
-
# :
|
|
8
|
+
# simplecov:disable
|
|
9
9
|
raise "No api services loaded. " \
|
|
10
10
|
"Did you forget to set a URL/API key env var or a require for either ollama, anthropic, or openai?"
|
|
11
|
-
# :
|
|
11
|
+
# simplecov:enable
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
Foobara::Util.require_directory "#{__dir__}/../../src"
|
|
@@ -35,11 +35,12 @@ module Foobara
|
|
|
35
35
|
construct_messages
|
|
36
36
|
generate_answer
|
|
37
37
|
parse_answer
|
|
38
|
+
attempt_to_recover_from_bad_format
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
final_answer
|
|
40
41
|
end
|
|
41
42
|
|
|
42
|
-
attr_accessor :answer, :parsed_answer, :messages, :assistant_serializer, :user_serializer,
|
|
43
|
+
attr_accessor :final_answer, :answer, :parsed_answer, :messages, :assistant_serializer, :user_serializer,
|
|
43
44
|
:computed_assistant_association_depth, :computed_user_association_depth,
|
|
44
45
|
:llm_instructions
|
|
45
46
|
|
|
@@ -80,9 +81,9 @@ module Foobara
|
|
|
80
81
|
when Foobara::AssociationDepth::PRIMARY_KEY_ONLY
|
|
81
82
|
Foobara::CommandConnectors::Serializers::EntitiesToPrimaryKeysSerializer
|
|
82
83
|
else
|
|
83
|
-
# :
|
|
84
|
+
# simplecov:disable
|
|
84
85
|
raise "Unknown depth: #{depth}"
|
|
85
|
-
# :
|
|
86
|
+
# simplecov:enable
|
|
86
87
|
end.instance
|
|
87
88
|
end
|
|
88
89
|
|
|
@@ -119,7 +120,7 @@ module Foobara
|
|
|
119
120
|
end
|
|
120
121
|
|
|
121
122
|
content = serializer.serialize(content)
|
|
122
|
-
message.merge(content: JSON.
|
|
123
|
+
message.merge(content: JSON.generate(content))
|
|
123
124
|
end
|
|
124
125
|
end
|
|
125
126
|
end
|
|
@@ -165,22 +166,47 @@ module Foobara
|
|
|
165
166
|
fencepostless_answer = match[1]
|
|
166
167
|
JSON.parse(fencepostless_answer)
|
|
167
168
|
else
|
|
168
|
-
# :
|
|
169
|
+
# simplecov:disable
|
|
169
170
|
raise
|
|
170
|
-
# :
|
|
171
|
+
# simplecov:enable
|
|
171
172
|
end
|
|
172
173
|
rescue JSON::ParserError => e
|
|
173
174
|
# TODO: figure out how to test this code path
|
|
174
|
-
# :
|
|
175
|
+
# simplecov:disable
|
|
175
176
|
add_runtime_error :could_not_parse_result_json,
|
|
176
177
|
"Could not parse result JSON: #{e.message}",
|
|
177
178
|
raw_answer: answer,
|
|
178
179
|
stripped_answer: fencepostless_answer
|
|
179
|
-
# :
|
|
180
|
+
# simplecov:enable
|
|
180
181
|
end
|
|
181
182
|
end
|
|
182
183
|
end
|
|
183
184
|
|
|
185
|
+
# Sometimes we get {"result": "whatever"} instead of just "whatever" from some smaller models.
|
|
186
|
+
# Let's detect that and handle it...
|
|
187
|
+
def attempt_to_recover_from_bad_format
|
|
188
|
+
self.final_answer = if parsed_answer.is_a?(::Hash) && parsed_answer.keys == ["result"]
|
|
189
|
+
result_type = self.class.result_type
|
|
190
|
+
|
|
191
|
+
# TODO: implement a Type#valid? method
|
|
192
|
+
if result_type.process_value(parsed_answer).success?
|
|
193
|
+
parsed_answer
|
|
194
|
+
else
|
|
195
|
+
result = parsed_answer["result"]
|
|
196
|
+
|
|
197
|
+
if result_type.process_value(result).success?
|
|
198
|
+
result
|
|
199
|
+
else
|
|
200
|
+
# simplecov:disable
|
|
201
|
+
parsed_answer
|
|
202
|
+
# simplecov:enable
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
else
|
|
206
|
+
parsed_answer
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
184
210
|
module ClassMethods
|
|
185
211
|
def inputs_json_schema(association_depth)
|
|
186
212
|
JsonSchemaGenerator.to_json_schema(
|
|
@@ -236,9 +262,9 @@ module Foobara
|
|
|
236
262
|
@llm_instructions_cache ||= {}
|
|
237
263
|
|
|
238
264
|
if @llm_instructions_cache.key?(key)
|
|
239
|
-
# :
|
|
265
|
+
# simplecov:disable
|
|
240
266
|
@llm_instructions_cache[key]
|
|
241
|
-
# :
|
|
267
|
+
# simplecov:enable
|
|
242
268
|
else
|
|
243
269
|
@llm_instructions_cache[key] = build_llm_instructions(user_association_depth, assistant_association_depth)
|
|
244
270
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: foobara-llm-backed-command
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Miles Georgi
|
|
@@ -15,7 +15,7 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.
|
|
18
|
+
version: 0.1.1
|
|
19
19
|
- - "<"
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
21
|
version: 2.0.0
|
|
@@ -25,7 +25,7 @@ dependencies:
|
|
|
25
25
|
requirements:
|
|
26
26
|
- - ">="
|
|
27
27
|
- !ruby/object:Gem::Version
|
|
28
|
-
version: 0.
|
|
28
|
+
version: 0.1.1
|
|
29
29
|
- - "<"
|
|
30
30
|
- !ruby/object:Gem::Version
|
|
31
31
|
version: 2.0.0
|
|
@@ -98,13 +98,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
98
98
|
- - ">="
|
|
99
99
|
- !ruby/object:Gem::Version
|
|
100
100
|
version: 3.4.0
|
|
101
|
+
- - "<"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '4.1'
|
|
101
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
105
|
requirements:
|
|
103
106
|
- - ">="
|
|
104
107
|
- !ruby/object:Gem::Version
|
|
105
108
|
version: '0'
|
|
106
109
|
requirements: []
|
|
107
|
-
rubygems_version:
|
|
110
|
+
rubygems_version: 4.0.16
|
|
108
111
|
specification_version: 4
|
|
109
112
|
summary: Provides an easy way to implement a command whose logic is managed by an
|
|
110
113
|
LLM
|