From 78e0eb503ced649bd9455ca88a2ef00fe6d2415a Mon Sep 17 00:00:00 2001 From: "H. Saw" <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Thu, 11 Apr 2024 06:08:54 +0000 Subject: [PATCH 1/4] ignore test scripts --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a46d914..ef167a0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /bin /gui/styles/external/ /config/config.json +test.js From 9f5dc33ce813cd086ad5bfb03891ff7420091a28 Mon Sep 17 00:00:00 2001 From: "H. Saw" <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Thu, 11 Apr 2024 06:09:11 +0000 Subject: [PATCH 2/4] relocate AI scripts to a dedicated folder --- scripts/{ => AI}/gemini.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) rename scripts/{ => AI}/gemini.js (99%) diff --git a/scripts/gemini.js b/scripts/AI/gemini.js similarity index 99% rename from scripts/gemini.js rename to scripts/AI/gemini.js index 6ec48d1..f933ba7 100644 --- a/scripts/gemini.js +++ b/scripts/AI/gemini.js @@ -2,7 +2,7 @@ // Import the file module. // import file from `./net.js`; -export default class gemini { +class gemini { #key; #request; @@ -178,3 +178,5 @@ export default class gemini { return(analyze(RESPONSE_RAW)); } }; + +module.exports = gemini; From 33f13a237a79bd953e85992f1abef558c5b83fdb Mon Sep 17 00:00:00 2001 From: "H. Saw" <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Thu, 11 Apr 2024 06:35:25 +0000 Subject: [PATCH 3/4] add API version flag I'm not sure what exactly is the name of that thing (the one with v1beta). --- scripts/AI/gemini.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/AI/gemini.js b/scripts/AI/gemini.js index f933ba7..640edf8 100644 --- a/scripts/AI/gemini.js +++ b/scripts/AI/gemini.js @@ -2,7 +2,8 @@ // Import the file module. // import file from `./net.js`; -class gemini { +// Don't forget to set the class as export default. +export default class gemini { #key; #request; @@ -10,8 +11,9 @@ class gemini { @param {string} key the API key. Remember to not commit your API keys. @param {string} model the model to use + @param {object} version the API and bot version */ - constructor (key, model) { + constructor (key, model, version = {"API": "v1beta"}) { if ((key) ? (((typeof key).includes(`str`)) ? !(key.trim()) : true) : true) { throw new Error(`The API key is required.`); }; @@ -31,7 +33,7 @@ class gemini { this.model[`name`] = ((typeof model).includes(`str`) && model) ? ((model.includes(`models/`)) ? model : `models/`.concat(model)) : 'gemini-pro'; // Set the request location. - this.#request[`location`] = `https://generativelanguage.googleapis.com/v1beta/`.concat(this.model.name); + this.#request[`location`] = `https://generativelanguage.googleapis.com/`.concat(((version != null && !Array.isArray(version) && typeof(version).includes(`obj`)) ? version[`API`] : false) ? version[`API`] : `v1beta`, `/`, this.model.name); }; @@ -178,5 +180,3 @@ class gemini { return(analyze(RESPONSE_RAW)); } }; - -module.exports = gemini; From 0ae1a831f819b7c3db2560919ddd2de8f10e0c96 Mon Sep 17 00:00:00 2001 From: "H. Saw" <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Thu, 11 Apr 2024 06:36:25 +0000 Subject: [PATCH 4/4] create product analyzer function --- scripts/product.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 scripts/product.js diff --git a/scripts/product.js b/scripts/product.js new file mode 100644 index 0000000..7d8b295 --- /dev/null +++ b/scripts/product.js @@ -0,0 +1,27 @@ +/* ask.js +Ask product information to Google Gemini. */ + +// Import the storage management module. +const secretariat = await import(chrome.runtime.getURL("scripts/secretariat.js")); + +// Don't forget to set the class as export default. +class product { + /* Initialize a new product with its details. + + @param {object} details the product details + */ + constructor (details) { + }; + + /* Get the product information. + + @param {object} options the options + @returns {object} the analysis + */ + analyze(options) { + const gemini = (await import('./AI/gemini.js')).default; + let analyzer = new gemini ((typeof(options).includes(`obj`) && !Array.isArray(options) && options != null) ? options[`API Key`] : await secretariat.read([`settings`,`analysis`,`api`,`key`], 1), `gemini-pro`); + + + } +};