Skip to content

Commit f642a27

Browse files
authored
FIX: Dall E / Artist broken when tool_details is disabled (#667)
We were missing logic to handle custom_html from tools This also fixes image generation in chat
1 parent 8a0c202 commit f642a27

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

lib/ai_bot/bot.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,12 @@ def invoke_tool(tool, llm, cancel, context, &update_blk)
152152
end
153153

154154
tool_details = build_placeholder(tool.summary, tool.details, custom_raw: tool.custom_raw)
155-
update_blk.call(tool_details, cancel, nil) if !context[:skip_tool_details]
155+
156+
if context[:skip_tool_details] && tool.custom_raw.present?
157+
update_blk.call(tool.custom_raw, cancel, nil)
158+
elsif !context[:skip_tool_details]
159+
update_blk.call(tool_details, cancel, nil)
160+
end
156161

157162
result
158163
end

spec/lib/modules/ai_bot/playground_spec.rb

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -647,23 +647,25 @@
647647
end
648648

649649
context "with Dall E bot" do
650-
let(:bot) do
651-
persona =
652-
AiPersona
653-
.find(
654-
DiscourseAi::AiBot::Personas::Persona.system_personas[
655-
DiscourseAi::AiBot::Personas::DallE3
656-
],
657-
)
658-
.class_instance
659-
.new
660-
DiscourseAi::AiBot::Bot.as(bot_user, persona: persona)
650+
before { SiteSetting.ai_openai_api_key = "123" }
651+
652+
let(:persona) do
653+
AiPersona.find(
654+
DiscourseAi::AiBot::Personas::Persona.system_personas[
655+
DiscourseAi::AiBot::Personas::DallE3
656+
],
657+
)
661658
end
662659

663-
it "does not include placeholders in conversation context (simulate DALL-E)" do
664-
SiteSetting.ai_openai_api_key = "123"
660+
let(:bot) { DiscourseAi::AiBot::Bot.as(bot_user, persona: persona.class_instance.new) }
661+
let(:data) do
662+
image =
663+
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
664+
665+
[{ b64_json: image, revised_prompt: "a pink cow 1" }]
666+
end
665667

666-
response = (<<~TXT).strip
668+
let(:response) { (<<~TXT).strip }
667669
<function_calls>
668670
<invoke>
669671
<tool_name>dall_e</tool_name>
@@ -675,11 +677,24 @@
675677
</function_calls>
676678
TXT
677679

678-
image =
679-
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
680+
it "properly returns an image when skipping tool details" do
681+
persona.update!(tool_details: false)
680682

681-
data = [{ b64_json: image, revised_prompt: "a pink cow 1" }]
683+
WebMock.stub_request(:post, SiteSetting.ai_openai_dall_e_3_url).to_return(
684+
status: 200,
685+
body: { data: data }.to_json,
686+
)
687+
688+
DiscourseAi::Completions::Llm.with_prepared_responses([response]) do
689+
playground.reply_to(third_post)
690+
end
691+
692+
last_post = third_post.topic.reload.posts.order(:post_number).last
682693

694+
expect(last_post.raw).to include("a pink cow")
695+
end
696+
697+
it "does not include placeholders in conversation context (simulate DALL-E)" do
683698
WebMock.stub_request(:post, SiteSetting.ai_openai_dall_e_3_url).to_return(
684699
status: 200,
685700
body: { data: data }.to_json,

0 commit comments

Comments
 (0)