Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

FIX: Dall E / Artist broken when tool_details is disabled #667

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/ai_bot/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ def invoke_tool(tool, llm, cancel, context, &update_blk)
end

tool_details = build_placeholder(tool.summary, tool.details, custom_raw: tool.custom_raw)
update_blk.call(tool_details, cancel, nil) if !context[:skip_tool_details]

if context[:skip_tool_details] && tool.custom_raw.present?
update_blk.call(tool.custom_raw, cancel, nil)
elsif !context[:skip_tool_details]
update_blk.call(tool_details, cancel, nil)
end

result
end
Expand Down
49 changes: 32 additions & 17 deletions spec/lib/modules/ai_bot/playground_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -647,23 +647,25 @@
end

context "with Dall E bot" do
let(:bot) do
persona =
AiPersona
.find(
DiscourseAi::AiBot::Personas::Persona.system_personas[
DiscourseAi::AiBot::Personas::DallE3
],
)
.class_instance
.new
DiscourseAi::AiBot::Bot.as(bot_user, persona: persona)
before { SiteSetting.ai_openai_api_key = "123" }

let(:persona) do
AiPersona.find(
DiscourseAi::AiBot::Personas::Persona.system_personas[
DiscourseAi::AiBot::Personas::DallE3
],
)
end

it "does not include placeholders in conversation context (simulate DALL-E)" do
SiteSetting.ai_openai_api_key = "123"
let(:bot) { DiscourseAi::AiBot::Bot.as(bot_user, persona: persona.class_instance.new) }
let(:data) do
image =
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="

[{ b64_json: image, revised_prompt: "a pink cow 1" }]
end

response = (<<~TXT).strip
let(:response) { (<<~TXT).strip }
<function_calls>
<invoke>
<tool_name>dall_e</tool_name>
Expand All @@ -675,11 +677,24 @@
</function_calls>
TXT

image =
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
it "properly returns an image when skipping tool details" do
persona.update!(tool_details: false)

data = [{ b64_json: image, revised_prompt: "a pink cow 1" }]
WebMock.stub_request(:post, SiteSetting.ai_openai_dall_e_3_url).to_return(
status: 200,
body: { data: data }.to_json,
)

DiscourseAi::Completions::Llm.with_prepared_responses([response]) do
playground.reply_to(third_post)
end

last_post = third_post.topic.reload.posts.order(:post_number).last

expect(last_post.raw).to include("a pink cow")
end

it "does not include placeholders in conversation context (simulate DALL-E)" do
WebMock.stub_request(:post, SiteSetting.ai_openai_dall_e_3_url).to_return(
status: 200,
body: { data: data }.to_json,
Expand Down