Merge branch 'development-ai' into development

This commit is contained in:
buzzcode2007 2024-04-11 16:06:16 +08:00
commit 3511e62e01
3 changed files with 32 additions and 2 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
/bin
/gui/styles/external/
/config/config.json
test.js

View file

@ -2,6 +2,7 @@
// Import the file module.
// import file from `./net.js`;
// Don't forget to set the class as export default.
export default class gemini {
#key;
#request;
@ -10,8 +11,9 @@ export default 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 @@ export default 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);
};

27
scripts/product.js Normal file
View file

@ -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`);
}
};