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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d775d26884980d2bf6ab266dbc16fa0b18fedaa4690f3145e1793fec55984f9
4
- data.tar.gz: 12de9bf957015e76e4736a3145383064a7f324ce0beea88748067c47cc64205e
3
+ metadata.gz: b9cb07021ef2c77ed1e05d97c0d4b5cfaddca33c909c704fe3af57beddc5b2c4
4
+ data.tar.gz: c8da8cc8464a78c6ed709bd466de6bd55dab9ce371cdd7744aa8a875281726eb
5
5
  SHA512:
6
- metadata.gz: 32ee0f1ae9c357072be04e252f275c7daf0597964d438dae2f74f9fa345c5ad1e181a14146a277d9dc1956ae61046bbe8b61608add7e8c4910364bc8f1db7251
7
- data.tar.gz: 6404bf3f85d207fdd9d637fe6c072b04120c749416a920a472db086882274e5979ac7e0fff3f4bc18ae72fc49ab3dc771a94465a715d406c405fc5459e73f358
6
+ metadata.gz: 5ee46b5b1f6d5a45d2b1bff8781256a1e63f0df734c5a1473ab0eb348d89c6ef3b9352892bc88f1bc5e0a637e68ce9321ac49fecd2b4448d32d2495d407f2a8b
7
+ data.tar.gz: 598341d453c7b9e6b17d0d7c5d09a34212f4ff697e7d91780eb0cc3ac3428134be890722c85189bc8f0d35ecb6feaf3bc5cf770405aaf88dd33795406f9d49da
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.0.3] - 2025-03-05
2
+
3
+ - Support answers with an explanation followed by the proper answer in fence posts
4
+
5
+ ## [0.0.2] - 2025-03-05
6
+
7
+ - Strip <think> blocks out of answers
8
+
1
9
  ## [0.0.1] - 2025-03-05
2
10
 
3
11
  - Release as a gem
@@ -72,9 +72,28 @@ module Foobara
72
72
 
73
73
  def parse_answer
74
74
  stripped_answer = answer.gsub(/<THINK>.*?<\/THINK>/mi, "")
75
- stripped_answer = stripped_answer.gsub(/^\s*```\w*\n(.*)```\s*\z/m, "\\1")
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 = JSON.parse(stripped_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
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: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi