This repository was archived by the owner on Jul 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -156,12 +156,15 @@ def generate_image_caption(upload, user)
156156 ] ,
157157 )
158158
159- DiscourseAi ::Completions ::Llm . proxy ( SiteSetting . ai_helper_image_caption_model ) . generate (
160- prompt ,
161- user : user ,
162- max_tokens : 1024 ,
163- feature_name : "image_caption" ,
164- )
159+ raw_caption =
160+ DiscourseAi ::Completions ::Llm . proxy ( SiteSetting . ai_helper_image_caption_model ) . generate (
161+ prompt ,
162+ user : user ,
163+ max_tokens : 1024 ,
164+ feature_name : "image_caption" ,
165+ )
166+
167+ raw_caption . delete ( "|" ) . squish
165168 end
166169
167170 private
Original file line number Diff line number Diff line change 128128 let ( :caption_with_attrs ) do
129129 "A picture of a cat sitting on a table (#{ I18n . t ( "discourse_ai.ai_helper.image_caption.attribution" ) } )"
130130 end
131+ let ( :bad_caption ) { "A picture of a cat \n sitting on a |table|" }
131132
132133 before { assign_fake_provider_to ( :ai_helper_image_caption_model ) }
133134
134- def request_caption ( params )
135+ def request_caption ( params , caption = "A picture of a cat sitting on a table" )
135136 DiscourseAi ::Completions ::Llm . with_prepared_responses ( [ caption ] ) do
136137 post "/discourse-ai/ai-helper/caption_image" , params : params
137138
@@ -155,6 +156,13 @@ def request_caption(params)
155156 end
156157 end
157158
159+ it "returns a cleaned up caption from the LLM" do
160+ request_caption ( { image_url : image_url , image_url_type : "long_url" } , bad_caption ) do |r |
161+ expect ( r . status ) . to eq ( 200 )
162+ expect ( r . parsed_body [ "caption" ] ) . to eq ( caption_with_attrs )
163+ end
164+ end
165+
158166 context "when the image_url is a short_url" do
159167 let ( :image_url ) { upload . short_url }
160168
You can’t perform that action at this time.
0 commit comments