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
This commit is contained in:
parent
8a0c2020f2
commit
f642a27f11
|
@ -152,7 +152,12 @@ module DiscourseAi
|
||||||
end
|
end
|
||||||
|
|
||||||
tool_details = build_placeholder(tool.summary, tool.details, custom_raw: tool.custom_raw)
|
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
|
result
|
||||||
end
|
end
|
||||||
|
|
|
@ -647,23 +647,25 @@ RSpec.describe DiscourseAi::AiBot::Playground do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with Dall E bot" do
|
context "with Dall E bot" do
|
||||||
let(:bot) do
|
before { SiteSetting.ai_openai_api_key = "123" }
|
||||||
persona =
|
|
||||||
AiPersona
|
let(:persona) do
|
||||||
.find(
|
AiPersona.find(
|
||||||
DiscourseAi::AiBot::Personas::Persona.system_personas[
|
DiscourseAi::AiBot::Personas::Persona.system_personas[
|
||||||
DiscourseAi::AiBot::Personas::DallE3
|
DiscourseAi::AiBot::Personas::DallE3
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.class_instance
|
|
||||||
.new
|
|
||||||
DiscourseAi::AiBot::Bot.as(bot_user, persona: persona)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not include placeholders in conversation context (simulate DALL-E)" do
|
let(:bot) { DiscourseAi::AiBot::Bot.as(bot_user, persona: persona.class_instance.new) }
|
||||||
SiteSetting.ai_openai_api_key = "123"
|
let(:data) do
|
||||||
|
image =
|
||||||
|
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
|
||||||
|
|
||||||
response = (<<~TXT).strip
|
[{ b64_json: image, revised_prompt: "a pink cow 1" }]
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:response) { (<<~TXT).strip }
|
||||||
<function_calls>
|
<function_calls>
|
||||||
<invoke>
|
<invoke>
|
||||||
<tool_name>dall_e</tool_name>
|
<tool_name>dall_e</tool_name>
|
||||||
|
@ -675,11 +677,24 @@ RSpec.describe DiscourseAi::AiBot::Playground do
|
||||||
</function_calls>
|
</function_calls>
|
||||||
TXT
|
TXT
|
||||||
|
|
||||||
image =
|
it "properly returns an image when skipping tool details" do
|
||||||
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
|
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(
|
WebMock.stub_request(:post, SiteSetting.ai_openai_dall_e_3_url).to_return(
|
||||||
status: 200,
|
status: 200,
|
||||||
body: { data: data }.to_json,
|
body: { data: data }.to_json,
|
||||||
|
|
Loading…
Reference in New Issue