Skip to content

Commit

Permalink
Improving customization of prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
frianasoa committed Dec 26, 2023
1 parent 63e20be commit b00a610
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 25 deletions.
1 change: 1 addition & 0 deletions content/lib/fontawesome/6.1.1/svgs/repeat.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions content/lib/fontawesome/6.1.1/svgs/robot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion content/notes/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ Actions = {
});
},

openaiparaphrase(annotation)
openaiparaphrase(annotation, direct=false)
{
if(Zotero.ZeNotes.Prefs.getb("openai-api-key")=="")
{
Expand All @@ -287,6 +287,13 @@ Actions = {
}

Zotero.ZeNotes.Ai.OpenAi.paraphrase(annotation["annotationText"]).then(r=>{
if(direct)
{
annotation.annotationComment = currentcomment+"\n\n<b>[Paraphrase]</b>\n"+r[0]+"\n";
annotation.saveTx({skipSelect:true}).then(e=>{});
return;
}

var table = AiUi.createdialog(annotation, currentcomment, r, "gpt");
var model = Zotero.ZeNotes.Prefs.get("openai-model");
Dialog.open(table, function(){}, "Edit and choose a paraphrase [OpenAi: "+model+"]", "close");
Expand All @@ -300,6 +307,11 @@ Actions = {
{
html="-"+r;
}
if(direct)
{
alert(html);
return;
}
Dialog.open(html, function(){
});
});
Expand Down
2 changes: 1 addition & 1 deletion content/notes/menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Menus = {

if(Zotero.ZeNotes.Prefs.getb("bard-api-key")!="")
{
items_ai["paraphrase-annotation"]["items"]["paraphrase-bard"] = {name: "Using bard", icon: "fa-b"};
items_ai["paraphrase-annotation"]["items"]["paraphrase-bard"] = {name: "Using Bard", icon: "fa-b"};
items_ai["custom-prompt-on-cell"]["items"]["custom-prompt-cell-bard"] = {name: "Using bard", icon: "fa-b"};
items_ai["custom-prompt-on-row"]["items"]["custom-prompt-row-bard"] = {name: "Using bard", icon: "fa-b"};
items_ai["custom-prompt-on-table"]["items"]["custom-prompt-row-table"] = {name: "Using bard", icon: "fa-b"};
Expand Down
6 changes: 1 addition & 5 deletions content/settings/ai.xhtml → content/settings/ai-api.xhtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div xmlns="http:https://www.w3.org/1999/xhtml">
<table id="ai" width="100%">
<table id="ai-api" width="100%">
<tr><td>DeepL API key</td><td colspan="4"><input id="zn-deepl-api-key" type="password" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'deepl-api-key', 'encrypt');" style="width:100%;" placeholder="Enter your DeepL API key"/></td><td></td></tr>
<tr><td>Google translate API key</td><td colspan="4"><input id="zn-google-translate-key" type="password" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'google-translate-key', 'encrypt');" style="width:100%;" placeholder="Enter your google translate API key"/></td><td></td></tr>
<tr>
Expand All @@ -21,9 +21,5 @@
<tr>
<td>OpenAi max token</td><td colspan="4"><input id="zn-openai-max-token" type="text" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'openai-max-token');" style="width:100%;" placeholder="Enter max number of token used"/></td>
</tr>
<tr><td>Cell custom prompt</td><td colspan="4"><textarea id="zn-cell-custom-prompt" type="text" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'cell-custom-prompt');" style="width:100%;" placeholder="The annotation will be appended to your prompt."></textarea></td></tr>
<tr><td>Row summary prompt</td><td colspan="4"><textarea id="zn-row-custom-prompt" type="text" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'row-custom-prompt');" style="width:100%;" placeholder="The row annotations/notes data will be appended to your prompt."></textarea></td></tr>
<tr><td>Table summary prompt</td><td colspan="4"><textarea id="zn-table-custom-prompt" type="text" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'table-custom-prompt');" style="width:100%;" placeholder="The table annotations/notes data will be appended to your prompt."></textarea></td></tr>

</table>
</div>
9 changes: 9 additions & 0 deletions content/settings/ai-prompts.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div xmlns="http:https://www.w3.org/1999/xhtml" style="width:100%; border: solid 1px;">
<table id="ai-prompts" width="100%" style="min-width: 300px; width:100%;">
<tr><td>Paraphrase custom prompt</td><td colspan="4"><textarea id="zn-paraphrase-custom-prompt" type="text" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'paraphrase-custom-prompt');" style="width:100%;" placeholder="If set, this prompt will be used in paraphrase."></textarea></td></tr>
<tr><td>Cell custom prompt</td><td colspan="4"><textarea id="zn-cell-custom-prompt" type="text" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'cell-custom-prompt');" style="width:100%;" placeholder="The annotation will be appended to your prompt."></textarea></td></tr>
<tr><td>Row custom prompt</td><td colspan="4"><textarea id="zn-row-custom-prompt" type="text" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'row-custom-prompt');" style="width:100%;" placeholder="The row annotations/notes data will be appended to your prompt."></textarea></td></tr>
<tr><td>Table custom prompt</td><td colspan="4"><textarea id="zn-table-custom-prompt" type="text" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'table-custom-prompt');" style="width:100%;" placeholder="The table annotations/notes data will be appended to your prompt."></textarea></td></tr>

</table>
</div>
1 change: 1 addition & 0 deletions content/settings/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ Zotero_Preferences.ZeNotes = {
Zotero_Preferences.ZeNotes.loadpreference("deepl-api-key", "zn-deepl-api-key", "encrypt");


Zotero_Preferences.ZeNotes.loadpreference("paraphrase-custom-prompt", "zn-paraphrase-custom-prompt");
Zotero_Preferences.ZeNotes.loadpreference("cell-custom-prompt", "zn-cell-custom-prompt");
Zotero_Preferences.ZeNotes.loadpreference("row-custom-prompt", "zn-row-custom-prompt");
Zotero_Preferences.ZeNotes.loadpreference("table-custom-prompt", "zn-table-custom-prompt");
Expand Down
7 changes: 6 additions & 1 deletion content/settings/preferences.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<html:fieldset>
<html:legend class='zn-legend'>AI API settings</html:legend>
<div class="zn-include" src="ai.xhtml"> </div>
<div class="zn-include" src="ai-api.xhtml"> </div>
<html:table>
<html:tr><html:td>Target language</html:td><html:td colspan="2">
<box>
Expand All @@ -45,6 +45,11 @@

</html:fieldset>

<html:fieldset>
<html:legend class='zn-legend'>AI custom prompts</html:legend>
<div class="zn-include" src="ai-prompts.xhtml"> </div>
</html:fieldset>

<html:fieldset>
<html:legend class='zn-legend'>Performance</html:legend>
<div class="zn-include" src="performance.xhtml"> </div>
Expand Down
14 changes: 14 additions & 0 deletions content/settings/preferences6.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,22 @@
.zn-include {
padding-top: 0.5em!important;
width: 100%!important;
display: flex;
flex-direction: column;
}

.zn-include table {
}

fieldset {
width: 100%!important;
}

#ai-prompts tr td:nth-child(1){
white-space: nowrap;
width: 1%;
}

#ai-prompts tr td{
border-bottom: solid 1px;
}
17 changes: 14 additions & 3 deletions core/ai.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,18 @@ Ai.Bard = {

async paraphrase(sentence)
{
model = Zotero.ZeNotes.Prefs.get("bard-model");
var model = Zotero.ZeNotes.Prefs.get("bard-model");
var defaultprompt = Zotero.ZeNotes.Prefs.get("paraphrase-custom-prompt");
if(!defaultprompt)
{
defaultprompt = Ai.prompts["paraphrase"]
}

if(model=="")
{
model = "gemini-pro";
}
return this.sendprompt(sentence, Ai.prompts["paraphrase"], model)
return this.sendprompt(sentence, defaultprompt, model)
},

async customprompt(sentence, target)
Expand Down Expand Up @@ -277,7 +283,12 @@ Ai.DeepL = {
Ai.OpenAi = {
paraphrase(sentence){
var model = Zotero.ZeNotes.Prefs.get("openai-model");
return this.sendprompt(sentence, Ai.prompts["paraphrase"], model)
var defaultprompt = Zotero.ZeNotes.Prefs.get("paraphrase-custom-prompt");
if(!defaultprompt)
{
defaultprompt = Ai.prompts["paraphrase"]
}
return this.sendprompt(sentence, defaultprompt, model)
},

async customprompt(sentence, target)
Expand Down
28 changes: 22 additions & 6 deletions core/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Annotations = {

reader.menus[label] = {
label: 'Translate to '+tl+' [Google]',
icon: 'fa-language',
image: 'fa-language',
onCommand: function(){
for(id of params.ids)
{
Expand All @@ -57,7 +57,7 @@ Annotations = {
label = 'Translate to '+tl+' [DeepL]';
reader.menus[label] = {
label: label,
icon: "fa-language",
image: "fa-language",
onCommand: function(){
for(id of params.ids)
{
Expand All @@ -70,10 +70,10 @@ Annotations = {

if(Zotero.ZeNotes.Prefs.getb("bard-api-key")!="")
{
label = 'Paraphrase [bard]';
label = 'Paraphrase [Bard]';
reader.menus[label] = {
label: label,
icon: "fa-arrow-right-arrow-left",
image: "fa-arrow-right-arrow-left",
onCommand: function(){
for(id of params.ids)
{
Expand All @@ -83,13 +83,29 @@ Annotations = {
}
};
}

if(Zotero.ZeNotes.Prefs.getb("openai-api-key")!="")
{
label = 'Paraphrase [ChatGPT]';
reader.menus[label] = {
label: label,
image: "fa-robot",
onCommand: function(){
for(id of params.ids)
{
var annotation = reader._item.getAnnotations().filter(function(e){return e.key==id})[0];
Zotero.ZeNotes.Actions.openaiparaphrase(annotation, true);
}
}
};
}
},
addmenus(){
Zotero.Reader.registerEventListener('createAnnotationContextMenu', (event) => {
let { reader, params, append } = event;
Annotations.newmenus(reader, params);
for(menu of Object.values(reader.menus))
{
{
append(menu);
}
});
Expand All @@ -116,7 +132,7 @@ Annotations = {
menuitem = reader._window.document.createElement('menuitem');
menuitem.setAttribute('label', menu.label);
menuitem.className = 'menuitem-iconic';
menuitem.setAttribute('image', Annotations.geticon(menu.icon));
menuitem.setAttribute('image', Annotations.geticon(menu.image));
menuitem.addEventListener('command', (e) => {
reader.menus[e.target.label].onCommand();
});
Expand Down
2 changes: 1 addition & 1 deletion install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Description about="urn:mozilla:install-manifest">
<em:id>[email protected]</em:id>
<em:name>ZeNotes</em:name>
<em:version>0.7.0</em:version>
<em:version>0.7.1</em:version>
<em:multiprocessCompatible>true</em:multiprocessCompatible>
<em:updateURL>https://raw.githubusercontent.com/frianasoa/zenotes/main/zenote-update.json</em:updateURL>
<em:homepageURL>https://github.com/frianasoa/zenotes</em:homepageURL>
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Ze Notes",
"version": "0.7.0",
"version": "0.7.1",
"description": "Advanced notes manager",
"homepage_url": "https://github.com/frianasoa/zenotes",
"author": "Fanantenana Rianasoa Andriariniaina",
Expand Down
6 changes: 3 additions & 3 deletions zenote-update.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"[email protected]": {
"updates": [
{
"version": "0.7.0",
"update_link": "https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.0/zenotes-v0.7.0.xpi",
"update_hash": "sha256:7bb77784f1d328877c98b8b1d0da39445b07d93d77be1f82d3f013c14bc7feed",
"version": "0.7.1",
"update_link": "https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.1/zenotes-v0.7.1.xpi",
"update_hash": "sha256:451a29fcd078932d788245d5882e39178600c378d16ccbe0479b8bd88350c332",
"applications": {
"gecko": {
"strict_min_version": "60.0"
Expand Down
6 changes: 3 additions & 3 deletions zenote-update.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<rdf:Seq>
<rdf:li>
<rdf:Description>
<ns1:version>0.7.0</ns1:version>
<ns1:version>0.7.1</ns1:version>
<ns1:targetApplication>
<rdf:Description>
<ns1:id>[email protected]</ns1:id>
<ns1:minVersion>5.0.0</ns1:minVersion>
<ns1:maxVersion>6.*</ns1:maxVersion>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.0/zenotes-v0.7.0.xpi</ns1:updateLink>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.1/zenotes-v0.7.1.xpi</ns1:updateLink>
</rdf:Description>
</ns1:targetApplication>

Expand All @@ -20,7 +20,7 @@
<ns1:id>[email protected]</ns1:id>
<ns1:minVersion>4.999</ns1:minVersion>
<ns1:maxVersion>6.*</ns1:maxVersion>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.0/zenotes-v0.7.0.xpi</ns1:updateLink>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.1/zenotes-v0.7.1.xpi</ns1:updateLink>
</rdf:Description>
</ns1:targetApplication>

Expand Down

0 comments on commit b00a610

Please sign in to comment.