Skip to content

Commit

Permalink
Merge pull request #68 from Tasnim1147/f24
Browse files Browse the repository at this point in the history
Implement LLM Experiment Integration with Server-Side Functionality
  • Loading branch information
jdufitum authored Nov 19, 2024
2 parents 046eb4c + 260aca7 commit f1e4f22
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
branches:
- f24
# - f24-p4
workflow_call: # Usually called from deploy

defaults:
Expand Down
18 changes: 18 additions & 0 deletions public/src/client/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,35 @@ define('forum/topic', [
addParentHandler();
addRepliesHandler();
addPostsPreviewHandler();
configurePostToggle();
setupQuickReply();
handleBookmark(tid);
handleThumbs();

$(window).on('scroll', utils.debounce(updateTopicTitle, 250));



handleTopicSearch();

hooks.fire('action:topic.loaded', ajaxify.data);
};

function configurePostToggle() {
$(".topic").on("click", ".view-translated-btn", function () {
// Toggle the visibility of the next .translated-content div
$(this).closest('.sensitive-content-message').next('.translated-content').toggle();
console.log("Toggle btn clicked");
// Optionally, change the button text based on visibility
var isVisible = $(this).closest('.sensitive-content-message').next('.translated-content').is(':visible');
if (isVisible) {
$(this).text('Hide the translated message.');
} else {
$(this).text('Click here to view the translated message.');
}
});
}

function handleTopicSearch() {
require(['mousetrap'], (mousetrap) => {
if (config.topicSearchEnabled) {
Expand Down
8 changes: 8 additions & 0 deletions src/meta/src/post.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@

<div class="content mt-2 text-break" component="post/content" itemprop="text">
{posts.content}
{{{if !posts.isEnglish }}}
<div class="sensitive-content-message">
<a class="btn btn-sm btn-primary view-translated-btn">Click here to view the translated message.</a>
</div>
<div class="translated-content" style="display:none;">
{posts.translatedContent}
</div>
{{{end}}}
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/posts/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const topics = require('../topics');
const categories = require('../categories');
const groups = require('../groups');
const privileges = require('../privileges');
const translate = require('../translate');

module.exports = function (Posts) {
Posts.create = async function (data) {
Expand All @@ -19,6 +20,7 @@ module.exports = function (Posts) {
const content = data.content.toString();
const timestamp = data.timestamp || Date.now();
const isMain = data.isMain || false;
const [isEnglish, translatedContent] = await translate.translate(data)
const { isApproved } = data;
const { annonymousType } = data;

Expand All @@ -37,6 +39,8 @@ module.exports = function (Posts) {
tid: tid,
content: content,
timestamp: timestamp,
translatedContent: translatedContent,
isEnglish: isEnglish,
isApproved: isApproved,
annonymousType: annonymousType,
};
Expand Down
2 changes: 2 additions & 0 deletions src/posts/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,7 @@ function modifyPost(post, fields) {
if (post.hasOwnProperty('edited')) {
post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : '';
}
// Mark post as "English" if decided by translator service or if it has no info
post.isEnglish = post.isEnglish == "true" || post.isEnglish === undefined;
}
}
11 changes: 11 additions & 0 deletions src/translate/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var request = require('request');

const translatorApi = module.exports;

translatorApi.translate = async function (postData) {
// Edit the translator URL below
const TRANSLATOR_API = "https://nodebb-f24-translator.azurewebsites.net/"
const response = await fetch(TRANSLATOR_API+'/?content='+postData.content);
const data = await response.json();
return [data["is_english"], data["translated_content"]]
}

0 comments on commit f1e4f22

Please sign in to comment.