EvanZhouDev / bard-ai

A lightweight library to access Google Bard.
https://www.npmjs.com/package/bard-ai
GNU General Public License v3.0
117 stars 31 forks source link

Is it possible to use this module with CommonJS & ES5? #40

Closed erturkdotgg closed 1 year ago

erturkdotgg commented 1 year ago

Prerequisites

Feature description

Is it possible to use this module with CommonJS & ES5?

ThatXliner commented 1 year ago

This is not a feature request but instead a question.

@EvanZhouDev perhaps we can set up GitHub discussions for questions. Or our own SO tag

ThatXliner commented 1 year ago

To answer your question

Prerequisites

  • [x] I am using the latest version of bard-ai
  • [x] I have searched the issues and believe that it has not already been requested (and possibly rejected)
  • [x] I agree to follow the Code of Conduct

Feature description

Is it possible to use this module with CommonJS & ES5?

This is a generic JavaScript question. Try searching up “javascript use es6 modules in commonjs”

A quick search finds this SO post that mentions using the dynamic import function. So in your CommonJS code.

import('bard-ai').then(async ({default: Bard}) => {
    const myBard = new Bard(COOKIE);
    console.log(await myBard.ask("Hello, world!"));
})
EvanZhouDev commented 1 year ago

Yes, Dynamic Imports.