Skip to content

Commit

Permalink
Merge branch 'release/knowledge-integration'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy committed May 29, 2024
2 parents 30c000c + fa1bde1 commit 35d168c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
5 changes: 5 additions & 0 deletions radioUpdater/assets/js/helperScripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ function createHiddenDiv(id, child)

return hiddenDiv
}

const kebabCase = string => string
.replace(/([a-z])([A-Z])/g, "$1-$2")
.replace(/[\s_]+/g, '-')
.toLowerCase();
30 changes: 24 additions & 6 deletions radioUpdater/assets/js/questions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const relatedArticlesSection = document.getElementById('mcq-related-articles')

function updateAutoQuestion() {

// Add the form.
if (relatedArticlesSection) {
const autoQuestionDiv = document.createElement('div')
autoQuestionDiv.id = 'auto-questions'
Expand Down Expand Up @@ -65,29 +65,45 @@ function watchForArticleUpdates()

function getNewQuestion() {

let questionButton = document.getElementById('auto-question-button')
questionButton.disabled = true;

// Get the question textarea.
let questionTextarea = document.getElementById('for_multiple_choice_question_stem')
let stemContent = questionTextarea.querySelectorAll('[contenteditable="true"]')[0]
stemContent.id = 'question-content-textarea'

// Get the explanation textarea.
let explanationContentEditable = document.getElementById('for_multiple_choice_question_explanation').querySelectorAll('[contenteditable="true"]')[0]

let article = document.getElementsByClassName('related-article-form-li')[0].getElementsByTagName('a')[0].getAttribute("href")
// Determine the type of question
let type = 'basic-factual'
let typeList = document.getElementsByClassName('question-category-titles')[0];
let activeType = kebabCase(typeList.getElementsByClassName('active')[0].innerText)

if (activeType === 'image-interpretation') {
alert("We can't auto-generate Image Interpretation questions yet. Change Type at the top of the page.")
return
}

// Disable the question generator button
let questionButton = document.getElementById('auto-question-button')
questionButton.disabled = true;

// Get the first related article
let article = document.getElementsByClassName('related-article-form-li')[0].getElementsByTagName('a')[0].getAttribute("href")
article = article.substring(article.lastIndexOf('/') + 1)

// Generate a prompt
let prompt = document.getElementById('auto-question-input').value

let payload = {
type: activeType,
article: article,
prompt: prompt,
}

chrome.runtime.sendMessage({question: payload}, function ({data}) {

questionButton.disabled = false

if (data.error) {

} else {
Expand Down Expand Up @@ -125,7 +141,9 @@ function getNewQuestion() {
let wrappedExplanation = document.createElement('p')
wrappedExplanation.innerText = data.explanation
explanationContentEditable.prepend(wrappedExplanation)
explanationContentEditable.querySelectorAll('[data-placeholder]')[0].remove()

questionButton.innerText = 'Regenerate'

}

});
Expand Down
2 changes: 1 addition & 1 deletion radioUpdater/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ chrome.runtime.onMessage.addListener(function (message, sender, senderResponse)

} else if(message.question) {

fetch('https://ai.radiopaedia.work/questions/api/' + message.question.article + '/' + message.question.prompt)
fetch('https://ai.radiopaedia.work/questions/' + message.question.type + '/' + message.question.article + '/' + message.question.prompt)
.then(response => response.text())
.then(data => {
let dataObj = JSON.parse(data)
Expand Down
2 changes: 1 addition & 1 deletion radioUpdater/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "RadioUpdater",
"version": "1.0",
"version": "2.0",
"description": "Replace references on Radiopaedia.",
"manifest_version": 3,
"content_scripts": [
Expand Down

0 comments on commit 35d168c

Please sign in to comment.