Compare commits
3
Commits
main
...
ai-caption-fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5cb4127b95 | ||
|
|
3db9c32ec3 | ||
|
|
0ebcf52761 |
@@ -3,19 +3,26 @@ import { LinkTo } from "@ember/routing";
|
||||
import dIcon from "discourse-common/helpers/d-icon";
|
||||
import i18n from "discourse-common/helpers/i18n";
|
||||
|
||||
function showAiPreferences(user) {
|
||||
function showAiPreferences(user, settings) {
|
||||
// Since we only have one AI related user setting we don't show
|
||||
// AI preferences if these conditions aren't met.
|
||||
// If we add more user settings in the future we can move this
|
||||
// logic to the the specific settings and conditionally show it in the template.
|
||||
return user?.user_allowed_ai_auto_image_captions;
|
||||
const aiHelperEnabledFeatures =
|
||||
settings.ai_helper_enabled_features.split("|");
|
||||
|
||||
return (
|
||||
user?.user_allowed_ai_auto_image_captions &&
|
||||
aiHelperEnabledFeatures.includes("image_caption") &&
|
||||
settings.ai_helper_enabled
|
||||
);
|
||||
}
|
||||
|
||||
export default class AutoImageCaptionSetting extends Component {
|
||||
static shouldRender(outletArgs, helper) {
|
||||
return (
|
||||
helper.siteSettings.discourse_ai_enabled &&
|
||||
showAiPreferences(outletArgs.model)
|
||||
showAiPreferences(outletArgs.model, helper.siteSettings)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,17 @@ export default class PreferencesAiController extends Controller {
|
||||
@service siteSettings;
|
||||
@tracked saved = false;
|
||||
|
||||
get showAutoImageCaptionSetting() {
|
||||
const aiHelperEnabledFeatures =
|
||||
this.siteSettings.ai_helper_enabled_features.split("|");
|
||||
|
||||
return (
|
||||
this.model?.user_allowed_ai_auto_image_captions &&
|
||||
aiHelperEnabledFeatures.includes("image_caption") &&
|
||||
this.siteSettings.ai_helper_enabled
|
||||
);
|
||||
}
|
||||
|
||||
@action
|
||||
save() {
|
||||
this.saved = false;
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
<label class="control-label">{{i18n "discourse_ai.title"}}</label>
|
||||
{{!
|
||||
Later when we have more preferences,
|
||||
move the conditional (showAutoImageCaptionSetting)
|
||||
to be only around the auto-image-caption preference.
|
||||
}}
|
||||
{{#if this.showAutoImageCaptionSetting}}
|
||||
<label class="control-label">{{i18n "discourse_ai.title"}}</label>
|
||||
|
||||
<div class="control-group ai-setting">
|
||||
<PreferenceCheckbox
|
||||
@labelKey="discourse_ai.ai_helper.image_caption.automatic_caption_setting"
|
||||
@checked={{this.model.user_option.auto_image_caption}}
|
||||
data-setting-name="auto-image-caption"
|
||||
class="pref-auto-image-caption"
|
||||
<div class="control-group ai-setting">
|
||||
<PreferenceCheckbox
|
||||
@labelKey="discourse_ai.ai_helper.image_caption.automatic_caption_setting"
|
||||
@checked={{this.model.user_option.auto_image_caption}}
|
||||
data-setting-name="auto-image-caption"
|
||||
class="pref-auto-image-caption"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<SaveControls
|
||||
@id="user_ai_preference_save"
|
||||
@model={{this.model}}
|
||||
@action={{this.save}}
|
||||
@saved={{this.saved}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<SaveControls
|
||||
@id="user_ai_preference_save"
|
||||
@model={{this.model}}
|
||||
@action={{this.save}}
|
||||
@saved={{this.saved}}
|
||||
/>
|
||||
{{/if}}
|
||||
@@ -84,10 +84,10 @@ export default apiInitializer("1.25.0", (api) => {
|
||||
}
|
||||
);
|
||||
|
||||
// Checks if image is small (≤ 0.4 MP)
|
||||
// Checks if image is small (≤ 0.1 MP)
|
||||
function isSmallImage(width, height) {
|
||||
const megapixels = (width * height) / 1000000;
|
||||
return megapixels <= 0.4;
|
||||
return megapixels <= 0.1;
|
||||
}
|
||||
|
||||
function needsImprovedCaption(caption) {
|
||||
|
||||
@@ -22,6 +22,7 @@ RSpec.describe "AI image caption", type: :system, js: true do
|
||||
Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)
|
||||
assign_fake_provider_to(:ai_helper_model)
|
||||
assign_fake_provider_to(:ai_helper_image_caption_model)
|
||||
SiteSetting.ai_helper_enabled = true
|
||||
SiteSetting.ai_helper_enabled_features = "image_caption"
|
||||
sign_in(user)
|
||||
end
|
||||
@@ -87,6 +88,15 @@ RSpec.describe "AI image caption", type: :system, js: true do
|
||||
end
|
||||
|
||||
describe "automatic image captioning" do
|
||||
context "when ai helper is disabled" do
|
||||
before { SiteSetting.ai_helper_enabled = false }
|
||||
|
||||
it "should not have the setting present in the user preferences page" do
|
||||
user_preferences_ai_page.visit(user)
|
||||
expect(user_preferences_ai_page).to have_no_ai_preference("pref-auto-image-caption")
|
||||
end
|
||||
end
|
||||
|
||||
context "when toggling the setting from the user preferences page" do
|
||||
before { user.user_option.update!(auto_image_caption: false) }
|
||||
|
||||
|
||||
@@ -12,6 +12,14 @@ module PageObjects
|
||||
page.find(".#{preference} input").checked?
|
||||
end
|
||||
|
||||
def has_ai_preference?(preference)
|
||||
page.has_css?(".#{preference} input")
|
||||
end
|
||||
|
||||
def has_no_ai_preference?(preference)
|
||||
page.has_no_css?(".#{preference} input")
|
||||
end
|
||||
|
||||
def toggle_setting(preference)
|
||||
page.find(".#{preference} input").click
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user