foobara-llm-backed-command 0.0.2 → 0.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/src/llm_backed_command.rb +21 -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: b9cb07021ef2c77ed1e05d97c0d4b5cfaddca33c909c704fe3af57beddc5b2c4
|
4
|
+
data.tar.gz: c8da8cc8464a78c6ed709bd466de6bd55dab9ce371cdd7744aa8a875281726eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ee46b5b1f6d5a45d2b1bff8781256a1e63f0df734c5a1473ab0eb348d89c6ef3b9352892bc88f1bc5e0a637e68ce9321ac49fecd2b4448d32d2495d407f2a8b
|
7
|
+
data.tar.gz: 598341d453c7b9e6b17d0d7c5d09a34212f4ff697e7d91780eb0cc3ac3428134be890722c85189bc8f0d35ecb6feaf3bc5cf770405aaf88dd33795406f9d49da
|
data/CHANGELOG.md
CHANGED
data/src/llm_backed_command.rb
CHANGED
@@ -72,9 +72,28 @@ module Foobara
|
|
72
72
|
|
73
73
|
def parse_answer
|
74
74
|
stripped_answer = answer.gsub(/<THINK>.*?<\/THINK>/mi, "")
|
75
|
-
|
75
|
+
fencepostless_answer = stripped_answer.gsub(/^\s*```\w*\n(.*)```\s*\z/m, "\\1")
|
76
76
|
# TODO: should we verify against json-schema or no?
|
77
|
-
self.parsed_answer =
|
77
|
+
self.parsed_answer = begin
|
78
|
+
JSON.parse(fencepostless_answer)
|
79
|
+
rescue => e
|
80
|
+
# see if we can extract the last fence-posts content just in case
|
81
|
+
last_fence_post_regex = /```\w*\s*\n((?:(?!```).)+)\n```(?:(?!```).)*\z/m
|
82
|
+
begin
|
83
|
+
match = last_fence_post_regex.match(stripped_answer)
|
84
|
+
if match
|
85
|
+
JSON.parse(match[1])
|
86
|
+
else
|
87
|
+
# :nocov:
|
88
|
+
raise e
|
89
|
+
# :nocov:
|
90
|
+
end
|
91
|
+
rescue
|
92
|
+
# :nocov:
|
93
|
+
raise e
|
94
|
+
# :nocov:
|
95
|
+
end
|
96
|
+
end
|
78
97
|
end
|
79
98
|
|
80
99
|
module ClassMethods
|