Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import icon from "discourse-common/helpers/d-icon";
import i18n from "discourse-common/helpers/i18n";

function addResultClass(element) {
element.closest(".fps-result")?.classList.add("ai-result");
}
Comment on lines +5 to +7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heads up: this needs to be conditionally shown only on posts that have generatedByAi not on all search results:

Copy link
Member Author

@davidtaylorhq davidtaylorhq Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @keegangeorge!

I'd assumed that the 'sparkles' icon was only rendered on those results... but now that I look more closely it seems like we're rendering it on every result and then hiding with CSS? 😬

Anyway, I'm not too happy with this .closest() technique. Will close out this PR and make a new one when we have a better strategy.


const SearchResultDecoration = <template>
<div
class="ai-result__icon"
title={{i18n "discourse_ai.embeddings.ai_generated_result"}}
{{didInsert addResultClass}}
>
{{icon "discourse-sparkles"}}
</div>
Expand Down
58 changes: 31 additions & 27 deletions assets/javascripts/initializers/ai-bot-replies.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,38 @@ function attachHeaderIcon(api) {
function initializeAIBotReplies(api) {
initializePauseButton(api);

api.modifyClass("controller:topic", {
pluginId: "discourse-ai",

onAIBotStreamedReply: function (data) {
streamPostText(this.model.postStream, data);
},
subscribe: function () {
this._super();

if (
this.model.isPrivateMessage &&
this.model.details.allowed_users &&
this.model.details.allowed_users.filter(isGPTBot).length >= 1
) {
// we attempt to recover the last message in the bus
// so we subscribe at -2
this.messageBus.subscribe(
`discourse-ai/ai-bot/topic/${this.model.id}`,
this.onAIBotStreamedReply.bind(this),
-2
);
api.modifyClass(
"controller:topic",
(Superclass) =>
class extends Superclass {
onAIBotStreamedReply(data) {
streamPostText(this.model.postStream, data);
}

subscribe() {
super.subscribe();

if (
this.model.isPrivateMessage &&
this.model.details.allowed_users &&
this.model.details.allowed_users.filter(isGPTBot).length >= 1
) {
// we attempt to recover the last message in the bus
// so we subscribe at -2
this.messageBus.subscribe(
`discourse-ai/ai-bot/topic/${this.model.id}`,
this.onAIBotStreamedReply.bind(this),
-2
);
}
}

unsubscribe() {
this.messageBus.unsubscribe("discourse-ai/ai-bot/topic/*");
super.unsubscribe();
}
}
},
unsubscribe: function () {
this.messageBus.unsubscribe("discourse-ai/ai-bot/topic/*");
this._super();
},
});
);
}

function initializePersonaDecorator(api) {
Expand Down
9 changes: 0 additions & 9 deletions assets/javascripts/initializers/ai-semantic-search.js

This file was deleted.