Skip to content

Commit eff2bfa

Browse files
committed
Add spec and fix logic
1 parent 0d131d0 commit eff2bfa

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lib/ai_bot/playground.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def reply_to(post)
420420
Discourse.redis.setex(redis_stream_key, 60, 1)
421421
end
422422

423-
context[:skip_tool_details] &&= !bot.persona.class.tool_details
423+
context[:skip_tool_details] ||= !bot.persona.class.tool_details
424424

425425
new_custom_prompts =
426426
bot.reply(context) do |partial, cancel, placeholder|

spec/lib/modules/ai_bot/playground_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,40 @@
590590
expect(last_post.raw).to include("I found stuff")
591591
end
592592

593+
it "supports disabling tool details" do
594+
persona =
595+
AiPersona.find(
596+
DiscourseAi::AiBot::Personas::Persona.system_personas[
597+
DiscourseAi::AiBot::Personas::General
598+
],
599+
)
600+
601+
persona.update!(tool_details: false)
602+
playground.bot.persona = persona.class_instance.new
603+
604+
response1 = (<<~TXT).strip
605+
<function_calls>
606+
<invoke>
607+
<tool_name>search</tool_name>
608+
<tool_id>search</tool_id>
609+
<parameters>
610+
<search_query>testing various things</search_query>
611+
</parameters>
612+
</invoke>
613+
</function_calls>
614+
TXT
615+
616+
response2 = "I found stuff"
617+
618+
DiscourseAi::Completions::Llm.with_prepared_responses([response1, response2]) do
619+
playground.reply_to(third_post)
620+
end
621+
622+
last_post = third_post.topic.reload.posts.order(:post_number).last
623+
624+
expect(last_post.raw).to eq("I found stuff")
625+
end
626+
593627
it "does not include placeholders in conversation context but includes all completions" do
594628
response1 = (<<~TXT).strip
595629
<function_calls>

0 commit comments

Comments
 (0)