use the ES6 import method for gemini.js

This commit is contained in:
buzz-lightsnack-2007 2024-05-25 00:00:33 +08:00
parent 0d36039ba5
commit 0c52ce4d08

View file

@ -2,10 +2,10 @@
// Import the file module. // Import the file module.
// import file from `./net.js`; // import file from `./net.js`;
const texts = (await import(chrome.runtime.getURL("scripts/mapping/read.js"))).default; import texts from "/scripts/mapping/read.js";
// Don't forget to set the class as export default. // Don't forget to set the class as export default.
export default class gemini { class gemini {
#key; #key;
#request; #request;
@ -65,7 +65,7 @@ export default class gemini {
REQUEST[`contents`] = []; REQUEST[`contents`] = [];
/* /*
Add the blob to a generative part. Add the blob to a generative part.
Function below by Google (https://ai.google.dev/tutorials/get_started_web) Function below by Google (https://ai.google.dev/tutorials/get_started_web)
@param {Blob} image the image to add @param {Blob} image the image to add
@ -80,7 +80,7 @@ export default class gemini {
reader.onloadend = () => resolve(reader.result.split(',')[1]); reader.onloadend = () => resolve(reader.result.split(',')[1]);
reader.readAsDataURL(image[`blob`]); reader.readAsDataURL(image[`blob`]);
}); });
return {inlineData: { data: image[`base64`], mimeType: image[`type`] }}; return {inlineData: { data: image[`base64`], mimeType: image[`type`] }};
}; };
@ -98,7 +98,7 @@ export default class gemini {
? PROMPT[REQUEST[`contents`].length][`images`] = [PROMPT[REQUEST[`contents`].length][`images`]] ? PROMPT[REQUEST[`contents`].length][`images`] = [PROMPT[REQUEST[`contents`].length][`images`]]
: false; : false;
// Add the photos, which are already in the blob format. // Add the photos, which are already in the blob format.
while ((PROMPT[REQUEST[`contents`].length][`images`]) ? (MESSAGE[`parts`].length < PROMPT[REQUEST[`contents`].length][`images`].length) : false) { while ((PROMPT[REQUEST[`contents`].length][`images`]) ? (MESSAGE[`parts`].length < PROMPT[REQUEST[`contents`].length][`images`].length) : false) {
let MESSAGE_IMAGE = await fileToGenerativePart(PROMPT[REQUEST[`contents`].length][`images`][MESSAGE[`parts`].length]); let MESSAGE_IMAGE = await fileToGenerativePart(PROMPT[REQUEST[`contents`].length][`images`][MESSAGE[`parts`].length]);
if (MESSAGE_IMAGE) { if (MESSAGE_IMAGE) {
@ -151,7 +151,7 @@ export default class gemini {
let analyze = (RESPONSE_RAW) => { let analyze = (RESPONSE_RAW) => {
let RESPONSES = []; let RESPONSES = [];
// Delete previous block state, if any. // Delete previous block state, if any.
delete this.blocked; delete this.blocked;
while (RESPONSES.length < RESPONSE_RAW[`candidates`].length && !this.blocked) { while (RESPONSES.length < RESPONSE_RAW[`candidates`].length && !this.blocked) {
@ -188,3 +188,5 @@ export default class gemini {
return(analyze(this.response)); return(analyze(this.response));
} }
}; };
export {gemini as default};