foobara-llm-backed-command 1.0.1 → 1.0.2
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 +4 -0
- data/src/llm_backed_execute_method.rb +28 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf89dfdfd181a03c728a1e4776440dca2f5421ed0f488d2e3fc3a7630b497c64
|
4
|
+
data.tar.gz: 60ae5ea17c418ffc323eeed3b6642e86e408a5c4b810e3471ef6a2bdf71ad9a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb2ba5b9634a0f5c7740d338e9f588f67d4bd214f5e101f0373cb91a0f2cf587707eee5b80beafcae0a5ea8c0c311b37138dc58c78279358609e50ffbb7d026f
|
7
|
+
data.tar.gz: 97a025adf7c31a0cebce7c65427811fcd628634b948f7e2654112eaad8b8cfa3d3fb6992595ced1fcf5ca98f7531ce5a018ae97d1af05e4a1d8cc638ac64b61d
|
data/CHANGELOG.md
CHANGED
@@ -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
|
|
@@ -181,6 +182,31 @@ module Foobara
|
|
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
|
+
# :nocov:
|
201
|
+
parsed_answer
|
202
|
+
# :nocov:
|
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(
|