diff --git a/_locales/en/messages.json b/_locales/en/messages.json index a7a0102d..08f5a2f8 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1012,11 +1012,15 @@ "description": "" }, "prompt_summarize_full_text": { - "message": "Summarize the following email or emails into a bullet point list. If there are multiple emails, consider the entire thread for the summary.\n------------------\n\n", + "message": "Summarize the following email or emails into a bullet point list. If there are multiple emails, consider the entire thread for the summary.", "description": "" }, "prompt_summarize_email_template": { - "message": "From: {%author%}\nTo: {%recipients%}\nCC: {%cc_list%}\nSubject: {%mail_subject%}\nDate: {%mail_datetime%}\nAttachments:\n{%mail_attachments_info%}\nBody:\n{%mail_text_body%}\n---------------\n\n", + "message": "From: {%author%}\nTo: {%recipients%}\nCC: {%cc_list%}\nSubject: {%mail_subject%}\nDate: {%mail_datetime%}\nAttachments:\n{%mail_attachments_info%}\nBody:\n{%mail_text_body%}", + "description": "" + }, + "prompt_summarize_email_separator": { + "message": "\n\n---------- NEXT EMAIL ----------\n\n", "description": "" }, "prompt_get_task": { diff --git a/js/mzta-prompts.js b/js/mzta-prompts.js index f68a3997..76736064 100644 --- a/js/mzta-prompts.js +++ b/js/mzta-prompts.js @@ -355,6 +355,22 @@ const specialPrompts = [ api_model: '', is_default: "1", is_special: "1", + }, + { + id: 'prompt_summarize_email_separator', + name: "__MSG_prompt_summarize_email_separator__", + text: "prompt_summarize_email_separator_full_text", + type: "1", + action: "0", + need_selected: "0", + need_signature: "0", + need_custom_text: "0", + define_response_lang: "0", + use_diff_viewer: "0", + api_type: '', + api_model: '', + is_default: "1", + is_special: "1", } ]; @@ -619,4 +635,4 @@ export async function clearPromptAPI(id){ } // console.log(">>>>>>>>>>>>> clearPromptAPI _prompt AFTER: " + JSON.stringify(_prompt)); await savePrompt(_prompt); -} \ No newline at end of file +} diff --git a/mzta-background.js b/mzta-background.js index 5b92c76c..46370b6f 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -1028,11 +1028,12 @@ browser.menus.onClicked.addListener( (info, tab) => { async function summarizeEmails(messages) { taWorkingStatus.startWorking(); - // we have two prompts, the actual assignment for the LLM and the email - // template prompt. + // we have three prompts, the actual assignment for the LLM, the email + // template prompt, and the email separator prompt const specialPrompts = await getSpecialPrompts(); const prompt = specialPrompts.find((prompt) => prompt.id === 'prompt_summarize'); const prompt_email = specialPrompts.find((prompt) => prompt.id === 'prompt_summarize_email_template'); + const prompt_email_separator = specialPrompts.find((prompt) => prompt.id === 'prompt_summarize_email_separator'); const tabs = await browser.tabs.query({ active: true, currentWindow: true }); const chatgpt_lang = await taPromptUtils.getDefaultLang(prompt); @@ -1059,11 +1060,11 @@ async function summarizeEmails(messages) { msg_text: curr_body_full_html, })); }; - let messages_string = messages_list.join("\n\n--- Next Email ---\n\n"); + const messages_string = messages_list.join(prompt_email_separator_string); - let full_prompt = prompt.text + "\n\n\n" + messages_string; + const full_prompt = prompt_string + prompt_email_separator_string + messages_string; - console.log(full_prompt); + // console.log(full_prompt); // send the prompt to the chat interface openChatGPT( diff --git a/pages/summarize/mzta-summarize.css b/pages/summarize/mzta-summarize.css index 26b08e10..add7a975 100644 --- a/pages/summarize/mzta-summarize.css +++ b/pages/summarize/mzta-summarize.css @@ -11,6 +11,10 @@ width: 100%; } +#summarize_email_separator_text { + width: 100%; +} + .infoline { font-size: 0.8em; font-style: italic; diff --git a/pages/summarize/mzta-summarize.html b/pages/summarize/mzta-summarize.html index 82679339..12c94b3c 100644 --- a/pages/summarize/mzta-summarize.html +++ b/pages/summarize/mzta-summarize.html @@ -79,6 +79,22 @@ __MSG_save__ + + +
+ + +
+ +
+
+ + +
diff --git a/pages/summarize/mzta-summarize.js b/pages/summarize/mzta-summarize.js index 20252fc4..bd57c0c5 100644 --- a/pages/summarize/mzta-summarize.js +++ b/pages/summarize/mzta-summarize.js @@ -44,6 +44,7 @@ document.addEventListener("DOMContentLoaded", async () => { let specialPrompts = await getSpecialPrompts(); let summarize_prompt = specialPrompts.find((prompt) => prompt.id === 'prompt_summarize'); let summarize_email_template = specialPrompts.find((prompt) => prompt.id === 'prompt_summarize_email_template'); + let summarize_email_separator = specialPrompts.find((prompt) => prompt.id === 'prompt_summarize_email_separator'); if (summarize_prompt && summarize_prompt.api_type && summarize_prompt.api_type !== '') { let update_prefs = {}; @@ -80,8 +81,12 @@ document.addEventListener("DOMContentLoaded", async () => { let summarize_textarea_email_template = document.getElementById("summarize_email_template_text"); let summarize_reset_email_template_btn = document.getElementById("btn_reset_email_template"); let summarize_save_email_template_btn = document.getElementById("btn_save_email_template"); + let summarize_email_separator_textarea = document.getElementById("summarize_email_separator_text"); + let summarize_email_separator_save_btn = document.getElementById("btn_save_email_separator"); + let summarize_email_separator_reset_btn = document.getElementById("btn_reset_email_separator"); + // on changing textareas summarize_textarea.addEventListener("input", (event) => { summarize_reset_btn.disabled = (event.target.value === browser.i18n.getMessage('prompt_summarize_full_text')); summarize_save_btn.disabled = (event.target.value === summarize_prompt.text); @@ -91,7 +96,14 @@ document.addEventListener("DOMContentLoaded", async () => { summarize_reset_email_template_btn.disabled = (event.target.value === browser.i18n.getMessage('prompt_summarize_email_template')); summarize_save_email_template_btn.disabled = (event.target.value === summarize_email_template.text); }); + + summarize_email_separator_textarea.addEventListener("input", (event) => { + summarize_email_separator_reset_btn.disabled = (event.target.value === browser.i18n.getMessage('prompt_summarize_email_separator')); + summarize_email_separator_save_btn.disabled = (event.target.value === summarize_email_separator.text); + }); + + // on clicking buttons, reset summarize_reset_email_template_btn.addEventListener("click", () => { summarize_textarea_email_template.value = browser.i18n.getMessage("prompt_summarize_email_template"); summarize_reset_email_template_btn.disabled = true; @@ -105,7 +117,15 @@ document.addEventListener("DOMContentLoaded", async () => { let event = new Event("input", { bubbles: true, cancelable: true }); summarize_textarea.dispatchEvent(event); }); + + summarize_email_separator_reset_btn.addEventListener("click", () => { + summarize_email_separator_textarea.value = browser.i18n.getMessage("prompt_summarize_email_separator"); + summarize_email_separator_reset_btn.disabled = true; + let event = new Event("input", { bubbles: true, cancelable: true }); + summarize_email_separator_textarea.dispatchEvent(event); + }); + // on clicking buttons, save summarize_save_email_template_btn.addEventListener("click", () => { specialPrompts.find(prompt => prompt.id === 'prompt_summarize_email_template').text = summarize_textarea_email_template.value; setSpecialPrompts(specialPrompts); @@ -119,6 +139,14 @@ document.addEventListener("DOMContentLoaded", async () => { summarize_save_btn.disabled = true; browser.runtime.sendMessage({ command: "reload_menus" }); }); + + summarize_email_separator_save_btn.addEventListener("click", () => { + specialPrompts.find(prompt => prompt.id === 'prompt_summarize_email_separator').text = summarize_email_separator_textarea.value; + setSpecialPrompts(specialPrompts); + summarize_email_separator_save_btn.disabled = true; + browser.runtime.sendMessage({ command: "reload_menus" }); + }); + if(summarize_prompt.text === 'prompt_summarize_full_text'){ summarize_prompt.text = browser.i18n.getMessage(summarize_prompt.text); @@ -126,16 +154,24 @@ document.addEventListener("DOMContentLoaded", async () => { if(summarize_email_template === 'prompt_summarize_email_template'){ summarize_email_template.text = browser.i18n.getMessage(summarize_email_template.text); } + if(summarize_email_separator.text === 'prompt_summarize_email_separator'){ + summarize_email_separator.text = browser.i18n.getMessage(summarize_email_separator.text); + } + summarize_textarea_email_template.value = summarize_email_template.text; summarize_reset_email_template_btn.disabled = (summarize_email_template.value === browser.i18n.getMessage("prompt_summarize_email_template")); summarize_textarea.value = summarize_prompt.text; summarize_reset_btn.disabled = (summarize_textarea.value === browser.i18n.getMessage("prompt_summarize_full_text")); + summarize_email_separator_textarea.value = summarize_email_separator.text; + summarize_email_separator_reset_btn.disabled = (summarize_email_separator.value === browser.i18n.getMessage("prompt_summarize_email_separator")); autocompleteSuggestions = (await getPlaceholders(true)) .filter((p) => p.id !== "additional_text") .map(mapPlaceholderToSuggestion); + textareaAutocomplete(summarize_textarea, autocompleteSuggestions, 1); textareaAutocomplete(summarize_textarea_email_template, autocompleteSuggestions, 1); + textareaAutocomplete(summarize_email_separator_textarea, autocompleteSuggestions, 1); });