mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-03-09 11:48:47 +00:00
FIX: Basic cleanup of AI Caption to remove line breaks and pipes (#857)
This commit is contained in:
parent
9af0c2e719
commit
96f5f8cbd0
@ -156,12 +156,15 @@ module DiscourseAi
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
raw_caption =
|
||||||
DiscourseAi::Completions::Llm.proxy(SiteSetting.ai_helper_image_caption_model).generate(
|
DiscourseAi::Completions::Llm.proxy(SiteSetting.ai_helper_image_caption_model).generate(
|
||||||
prompt,
|
prompt,
|
||||||
user: user,
|
user: user,
|
||||||
max_tokens: 1024,
|
max_tokens: 1024,
|
||||||
feature_name: "image_caption",
|
feature_name: "image_caption",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
raw_caption.delete("|").squish
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -128,10 +128,11 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do
|
|||||||
let(:caption_with_attrs) do
|
let(:caption_with_attrs) do
|
||||||
"A picture of a cat sitting on a table (#{I18n.t("discourse_ai.ai_helper.image_caption.attribution")})"
|
"A picture of a cat sitting on a table (#{I18n.t("discourse_ai.ai_helper.image_caption.attribution")})"
|
||||||
end
|
end
|
||||||
|
let(:bad_caption) { "A picture of a cat \nsitting on a |table|" }
|
||||||
|
|
||||||
before { assign_fake_provider_to(:ai_helper_image_caption_model) }
|
before { assign_fake_provider_to(:ai_helper_image_caption_model) }
|
||||||
|
|
||||||
def request_caption(params)
|
def request_caption(params, caption = "A picture of a cat sitting on a table")
|
||||||
DiscourseAi::Completions::Llm.with_prepared_responses([caption]) do
|
DiscourseAi::Completions::Llm.with_prepared_responses([caption]) do
|
||||||
post "/discourse-ai/ai-helper/caption_image", params: params
|
post "/discourse-ai/ai-helper/caption_image", params: params
|
||||||
|
|
||||||
@ -155,6 +156,13 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns a cleaned up caption from the LLM" do
|
||||||
|
request_caption({ image_url: image_url, image_url_type: "long_url" }, bad_caption) do |r|
|
||||||
|
expect(r.status).to eq(200)
|
||||||
|
expect(r.parsed_body["caption"]).to eq(caption_with_attrs)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "when the image_url is a short_url" do
|
context "when the image_url is a short_url" do
|
||||||
let(:image_url) { upload.short_url }
|
let(:image_url) { upload.short_url }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user