From 809c5ac0939e81f1c76417fdd3858720ca8f1d3c Mon Sep 17 00:00:00 2001 From: buzzcode2007 <73412182+buzz_lightsnack_2007@users.noreply.github.com> Date: Thu, 11 Apr 2024 17:21:58 +0800 Subject: [PATCH] add analyzer function --- _locales/en/messages.json | 3 +++ scripts/product.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 7d9c0d2..b6a9423 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -223,5 +223,8 @@ }, "error_msg_APImissing": { "message": "You have not yet added the API keys. To continue, please add one in the options." + }, + "AI_message_prompt": { + "message": "" } } diff --git a/scripts/product.js b/scripts/product.js index e034402..8ea2f1a 100644 --- a/scripts/product.js +++ b/scripts/product.js @@ -85,4 +85,23 @@ export default class product { // Write the analysis data to the storage. (this[`analysis`]) ? secretariat.write([`sites`, this.URL, `analysis`], this.analysis): false; }; + + async analyze() { + // Stop when the data is already analyzed. + if (this[`analysis`]) {return(this.analysis)} + else if (this.status ? (!this.status.update) : false) {this.analysis = await secretariat.read([`sites`, this.URL, `analysis`]);} + else { + // Analyze the data. + const gemini = (await import(chrome.runtime.getURL("scripts/AI/gemini.js"))).default; + let analyzer = new gemini (await secretariat.read([`settings`,`analysis`,`api`,`key`]), `gemini-pro`); + + // Analyze the data. + await analyzer.generate(this.details); + + // Return the analysis + this.analysis = analyzer.response; + } + + return(this.analysis); + }; };