FIX: Double render error with thumbnail suggestions (#968)

This PR fixes a bug where a double render error appears in the logs when thumbnails are suggested
This commit is contained in:
Keegan George 2024-11-28 08:12:27 +09:00 committed by GitHub
parent dabef02919
commit 4da033c667
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -35,7 +35,7 @@ module DiscourseAi
prompt.custom_instruction = params[:custom_prompt]
end
suggest_thumbnails(input) if prompt.id == CompletionPrompt::ILLUSTRATE_POST
return suggest_thumbnails(input) if prompt.id == CompletionPrompt::ILLUSTRATE_POST
hijack do
render json:

View File

@ -101,6 +101,20 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do
end
end
it "prevents double render when mode is ILLUSTRATE_POST" do
DiscourseAi::Completions::Llm.with_prepared_responses([proofread_text]) do
expect {
post "/discourse-ai/ai-helper/suggest",
params: {
mode: CompletionPrompt::ILLUSTRATE_POST,
text: text_to_proofread,
force_default_locale: true,
}
}.not_to raise_error
expect(response.status).to eq(200)
end
end
context "when performing numerous requests" do
it "rate limits" do
RateLimiter.enable