1
0
mirror of synced 2026-08-05 15:26:55 +00:00

FEATURE: Truncate AI Captions to a reasonable max size (#907)

This commit is contained in:
Rafael dos Santos Silva
2024-11-12 15:52:46 -03:00
committed by GitHub
parent 9583964676
commit aef9a03d4c
2 changed files with 10 additions and 1 deletions
+3 -1
View File
@@ -3,6 +3,8 @@
module DiscourseAi
module AiHelper
class Assistant
IMAGE_CAPTION_MAX_WORDS = 50
def self.prompt_cache
@prompt_cache ||= ::DiscourseAi::MultisiteHash.new("prompt_cache")
end
@@ -164,7 +166,7 @@ module DiscourseAi
feature_name: "image_caption",
)
raw_caption.delete("|").squish
raw_caption.delete("|").squish.truncate_words(IMAGE_CAPTION_MAX_WORDS)
end
private
@@ -163,6 +163,13 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do
end
end
it "truncates the caption from the LLM" do
request_caption({ image_url: image_url, image_url_type: "long_url" }, caption * 10) do |r|
expect(r.status).to eq(200)
expect(r.parsed_body["caption"].size).to be < caption.size * 10
end
end
context "when the image_url is a short_url" do
let(:image_url) { upload.short_url }