summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoricebaker <icebaker@proton.me>2023-11-19 16:43:41 -0300
committericebaker <icebaker@proton.me>2023-11-19 16:43:41 -0300
commit154aa68caf50a18af5c0dff1d368fc639314e0ba (patch)
treeb2ab75665e42de79f22cca82bf03cfc49759f485
parente89a1d57c49c94c16c37a8ee3a69b52a9e2b341b (diff)
improving tools parameters
-rw-r--r--components/providers/openai.rb2
-rw-r--r--controllers/interfaces/tools.rb4
-rw-r--r--logic/providers/openai/tools.rb9
-rw-r--r--spec/data/cartridges/tools.yml5
-rw-r--r--spec/logic/cartridge/tools_spec.rb8
-rw-r--r--spec/logic/providers/openai/tools_spec.rb9
-rw-r--r--static/cartridges/default.yml9
7 files changed, 34 insertions, 12 deletions
diff --git a/components/providers/openai.rb b/components/providers/openai.rb
index a7e7abe..87f2bc5 100644
--- a/components/providers/openai.rb
+++ b/components/providers/openai.rb
@@ -42,7 +42,7 @@ module NanoBot
if event[:message].nil? && event[:meta] && event[:meta][:tool_calls]
{ role: 'assistant', content: nil, tool_calls: event[:meta][:tool_calls] }
elsif event[:who] == 'tool'
- { role: event[:who], content: event[:message],
+ { role: event[:who], content: event[:message].to_s,
tool_call_id: event[:meta][:id], name: event[:meta][:name] }
else
{ role: event[:who] == 'user' ? 'user' : 'assistant', content: event[:message] }
diff --git a/controllers/interfaces/tools.rb b/controllers/interfaces/tools.rb
index aa4fb61..f079a2b 100644
--- a/controllers/interfaces/tools.rb
+++ b/controllers/interfaces/tools.rb
@@ -65,9 +65,9 @@ module NanoBot
if %i[fennel lua clojure].any? { |key| !adapter[key].nil? }
message = adapt(feedback, adapter, cartridge)
else
- message = "(#{feedback[:name]} #{feedback[:parameters].to_json})"
+ message = "#{feedback[:name]} #{feedback[:parameters].to_json}"
- message += " =>\n#{feedback[:output]}" if feedback[:action].to_sym == :responding
+ message += "\n#{feedback[:output]}" if feedback[:action].to_sym == :responding
end
message = "#{adapter[:prefix]}#{message}#{adapter[:suffix]}"
diff --git a/logic/providers/openai/tools.rb b/logic/providers/openai/tools.rb
index 68f2209..1b2882a 100644
--- a/logic/providers/openai/tools.rb
+++ b/logic/providers/openai/tools.rb
@@ -41,13 +41,16 @@ module NanoBot
end
def self.adapt(cartridge)
- {
+ output = {
type: 'function',
function: {
- name: cartridge[:name], description: cartridge[:description],
- parameters: cartridge[:parameters]
+ name: cartridge[:name], description: cartridge[:description]
}
}
+
+ output[:function][:parameters] = (cartridge[:parameters] || { type: 'object', properties: {} })
+
+ output
end
end
end
diff --git a/spec/data/cartridges/tools.yml b/spec/data/cartridges/tools.yml
index 08164a4..3cbd1ea 100644
--- a/spec/data/cartridges/tools.yml
+++ b/spec/data/cartridges/tools.yml
@@ -39,3 +39,8 @@ tools:
clojure: |
(require '[clojure.java.shell :refer [sh]])
(println (apply sh (get parameters "command")))
+
+ - name: clock
+ description: Returns the current date and time.
+ fennel: |
+ (os.date)
diff --git a/spec/logic/cartridge/tools_spec.rb b/spec/logic/cartridge/tools_spec.rb
index 913fa62..d08817c 100644
--- a/spec/logic/cartridge/tools_spec.rb
+++ b/spec/logic/cartridge/tools_spec.rb
@@ -10,11 +10,11 @@ RSpec.describe NanoBot::Logic::Cartridge::Tools do
let(:cartridge) { {} }
it 'uses default values when appropriate' do
- expect(described_class.feedback?(cartridge, :repl, :executing)).to be(true)
- expect(described_class.feedback?(cartridge, :eval, :executing)).to be(true)
+ expect(described_class.feedback?(cartridge, :repl, :executing)).to be(false)
+ expect(described_class.feedback?(cartridge, :eval, :executing)).to be(false)
- expect(described_class.feedback?(cartridge, :repl, :responding)).to be(false)
- expect(described_class.feedback?(cartridge, :eval, :responding)).to be(false)
+ expect(described_class.feedback?(cartridge, :repl, :responding)).to be(true)
+ expect(described_class.feedback?(cartridge, :eval, :responding)).to be(true)
end
end
diff --git a/spec/logic/providers/openai/tools_spec.rb b/spec/logic/providers/openai/tools_spec.rb
index 1758e5f..949d097 100644
--- a/spec/logic/providers/openai/tools_spec.rb
+++ b/spec/logic/providers/openai/tools_spec.rb
@@ -59,6 +59,15 @@ RSpec.describe NanoBot::Logic::OpenAI::Tools do
}
} }
)
+
+ expect(described_class.adapt(cartridge[:tools][3])).to eq(
+ { type: 'function',
+ function: {
+ name: 'clock',
+ description: 'Returns the current date and time.',
+ parameters: { type: 'object', properties: {} }
+ } }
+ )
end
end
diff --git a/static/cartridges/default.yml b/static/cartridges/default.yml
index ce2614d..864d62b 100644
--- a/static/cartridges/default.yml
+++ b/static/cartridges/default.yml
@@ -19,10 +19,15 @@ interfaces:
stream: true
suffix: "\n"
tools:
+ confirming:
+ suffix: ' [yN] '
+ default: 'n'
+ yeses: ['y', 'yes']
executing:
- feedback: true
- responding:
feedback: false
+ responding:
+ suffix: "\n\n"
+ feedback: true
provider:
settings: