FEATURE: Truncate AI Captions to a reasonable max size (#907)
This commit is contained in:
parent
9583964676
commit
aef9a03d4c
|
@ -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 }
|
||||
|
||||
|
|
Loading…
Reference in New Issue