From 9b7f1e6ee910d1d8e00f7cf2374a4041e248c5ea Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Thu, 12 Jun 2025 12:33:12 -0300 Subject: [PATCH] FIX: Helper wasn't working when the persona doesn't use structured output (#1433) --- lib/ai_helper/assistant.rb | 4 ++-- spec/lib/modules/ai_helper/assistant_spec.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/ai_helper/assistant.rb b/lib/ai_helper/assistant.rb index 8213458d..9a0aff2a 100644 --- a/lib/ai_helper/assistant.rb +++ b/lib/ai_helper/assistant.rb @@ -140,8 +140,8 @@ module DiscourseAi end elsif type.blank? # Assume response is a regular completion. - helper_response << helper_chunk - block.call(helper_chunk) if block + helper_response << partial + block.call(partial) if block end end diff --git a/spec/lib/modules/ai_helper/assistant_spec.rb b/spec/lib/modules/ai_helper/assistant_spec.rb index 6ac8ef04..98cd9256 100644 --- a/spec/lib/modules/ai_helper/assistant_spec.rb +++ b/spec/lib/modules/ai_helper/assistant_spec.rb @@ -176,6 +176,20 @@ RSpec.describe DiscourseAi::AiHelper::Assistant do expect(response[:suggestions]).to contain_exactly(english_text) end + + context "when the persona is not using structured outputs" do + it "still works" do + regular_persona = Fabricate(:ai_persona, response_format: nil) + SiteSetting.ai_helper_translator_persona = regular_persona.id + + response = + DiscourseAi::Completions::Llm.with_prepared_responses([english_text]) do + subject.generate_and_send_prompt(mode, text_to_translate, user) + end + + expect(response[:suggestions]).to contain_exactly(english_text) + end + end end context "when using a prompt that returns a list" do