FIX: tools broke on Claude with no params (#574)

Some tools may have no params, allow that
This commit is contained in:
Sam 2024-04-11 15:17:56 +10:00 committed by GitHub
parent 3b0cfdbe5c
commit a77658e2b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -158,7 +158,7 @@ module DiscourseAi
return "" if prompt.tools.blank?
has_arrays =
prompt.tools.any? { |tool| tool[:parameters].any? { |p| p[:type] == "array" } }
prompt.tools.any? { |tool| tool[:parameters]&.any? { |p| p[:type] == "array" } }
(<<~TEXT).strip
#{self.class.tool_preamble(include_array_tip: has_arrays)}

View File

@ -47,6 +47,15 @@ RSpec.describe DiscourseAi::Completions::Dialects::Dialect do
expect(dialect.build_tools_prompt).to include("array")
end
it "does not break if there are no params" do
prompt = DiscourseAi::Completions::Prompt.new("12345")
prompt.tools = [{ name: "categories", description: "lookup all categories" }]
dialect = TestDialect.new(prompt, "test")
expect(dialect.build_tools_prompt).not_to include("array")
end
end
describe "#trim_messages" do