Last active
November 22, 2024 04:07
-
-
Save cannin/ee92d007e81e9f1c63349f74dfc1e515 to your computer and use it in GitHub Desktop.
PubMed Central LLM Summaries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name PubMed Central LLM Summaries | |
// @namespace http://example.com | |
// @version 0.2 | |
// @description Add LLM Summaries to PMC | |
// @author cannin | |
// @match https://pubmed.ncbi.nlm.nih.gov/?term=* | |
// @match https://pubmed.ncbi.nlm.nih.gov/*/ | |
// @match https://www.ncbi.nlm.nih.gov/labs/pmc/articles/*/ | |
// @match https://www.ncbi.nlm.nih.gov/pmc/articles/*/ | |
// @match https://pmc.ncbi.nlm.nih.gov/articles/*/ | |
// @icon https://www.google.com/s2/favicons?domain=nih.gov | |
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js | |
// @grant GM_xmlhttpRequest | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
if(window.top.document.location.href.indexOf('pmc') !== -1) { | |
$('p').each(function(index) { | |
var item = $(this); | |
var text = item.text(); | |
//console.log(text); | |
// OpenAI ChatGPT (pay); https://platform.openai.com/ | |
var url_llm = 'https://api.openai.com/v1/chat/completions'; | |
var apikey = "sk-proj-FIXME"; | |
var model = "gpt-4o-mini"; | |
// Ollama (free); https://ollama.com/ | |
//var url_llm = 'http://localhost:11434/v1/chat/completions'; | |
//var apikey = ""; | |
//var model = "llama3.2:3b"; | |
var prompt = "Do not provide introductory text. Summarize the following INPUT TEXT in one sentence. Include all acronym definitions in the summary. VERY IMPORTANT: The summary should be in Spanish. INPUT TEXT: "; | |
if(text.length < 500) { | |
return true; | |
} | |
console.log(url_llm); | |
var data = { | |
"model": model, | |
"messages": [ | |
{ | |
"role": "user", | |
"content": prompt + text | |
} | |
] | |
}; | |
var jsonStr = JSON.stringify(data).trim(); | |
console.log(jsonStr); | |
GM_xmlhttpRequest({ | |
method: "POST", | |
data: jsonStr, | |
headers: { | |
"Content-Type": "application/json", | |
"Authorization": `Bearer ${apikey}` | |
}, | |
url: url_llm, | |
onload: function(response) { | |
if(response.status == 200) { | |
var data = JSON.parse(response.responseText); | |
var newItem = '<p class="p p-first-last"><font color="darkred"><strong>TLDR: </strong>' + data.choices[0].message.content + '</font></p>'; | |
item.before(newItem); | |
console.log("SUMMARY: " + data.choices[0].message.content); | |
} else { | |
console.log("ERROR: LLM"); | |
} | |
} | |
}); | |
console.log("DONE"); | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment