foobara-llm-backed-command 0.0.6 → 0.0.7
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/README.md +2 -2
- data/src/llm_backed_execute_method.rb +19 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d0fd4526fdfafec7f3f36b2734206b6d5a21e9af138081344b7662bb192e0df
|
4
|
+
data.tar.gz: 471ddc74cdd4782c46c74ae5c872eb698b85a73514474a945968776477303137
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45197b581cef44bf69b6b75fe158c045d03670902f008e213db2e76d5d148d2bb152ebf7cda5ebe7163856ea490934d09d27a29798c3da86726cd2ded442aaa9
|
7
|
+
data.tar.gz: bfdcfae305ed54a01e78cc50ffcd6addd3bac578d8201638790d4b7b28b0a27e24f1edd78f2aa72b9586b5ff15ae45f766cf7e8514e596ff9f162fee089eccfb
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Foobara::LlmBackedCommand
|
1
|
+
# Foobara::LlmBackedCommand
|
2
2
|
|
3
|
-
|
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
|
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
|
-
|
98
|
+
fencepostless_answer = match[1]
|
99
|
+
JSON.parse(fencepostless_answer)
|
90
100
|
else
|
91
101
|
# :nocov:
|
92
|
-
raise
|
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
|
-
|
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
|
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.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Georgi
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: foobara
|
@@ -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.
|
89
|
+
rubygems_version: 3.6.7
|
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
|