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

🐛 [BUG]: Working with Windows, Crashing on Linux #47

Open XCraftTM opened 1 year ago

XCraftTM commented 1 year ago

Prerequisites

Bug Description

So i coded a Discord Bot in Discord.JS in CJS and imported it correctly and everything works when using it in Windows, but when i upload it to a Linux Server(Running Ubuntu 20) it crashes when using Bard.Chat().ask() trying to ask something...

Reproduction Steps

Using:

const Bard = await import("bard-ai").catch(e => {
   throw "Missing Module: The Package 'bard-ai' was not found, please install it manually using 'npm i bard-ai'"
});
await Bard.init(config.aicookie);
let conv = new Bard.Chat();
await conv.ask("A MSG");

After i start the Bot it Gives this Error:

node:events:492
      throw er; // Unhandled 'error' event
      ^

Error: Google Bard encountered an error )]}'

38
[["wrb.fr",null,null,null,null,[9]]]
55
[["di",81],["af.httprm",80,"-1146363392943947525",2]]
25
[["e",4,null,null,130]]
.
    at queryBard (file:///Bot/node_modules/bard-ai/index.js:88:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Chat.ask (file:///Bot/node_modules/bard-ai/index.js:147:23)
    at async Object.execute (/Bot/events/ready.js:87:9) // This Being the Lines i sent Above: await conv.ask()
Emitted 'error' event on Client instance at:
    at emitUnhandledRejectionOrErr (node:events:395:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:84:21)

Node.js v18.17.0

Other information

No response

Occurance Rate

I can reproduce this bug 100% of the time.

EvanZhouDev commented 1 year ago

It appears that Bard is not responding correctly. Are you sure that config.aicookie is defined in your new environment?

XCraftTM commented 1 year ago

Yeah it is... i checked it multiple times and it does work on windows but not on the ubuntu server. The config is a JSON file that i imported using require...

XCraftTM commented 1 year ago

I have already pretty much created a CRE... But everything i have tried doesn't work... it throws the same error as of the start of this issue. I tried reimporting the Module, Making a new Project, trying a new File, Trying a ES6 Project, importing it using the import() function... Even just putting the Cookie Secret as a string into the function... Do you guys have any idea how i might be able to fix this?

XCraftTM commented 1 year ago

Weirdly enough i have now tried running this Project in a Ubuntu 20 VM on my PC and it works there.. So i think there might be something wrong with my Server i am running it on....

MarwanRadwan7 commented 1 year ago

Hello, This error happens to me when I try to use the chat function without passing the ids form the export function first. Other than that it works.

EvanZhouDev commented 1 year ago

Any updates? Closing otherwise.

XCraftTM commented 1 year ago

I still haven't found a solution for the issue but i do want to use it without a id...

EvanZhouDev commented 1 year ago

Try with bard-ai v2. Just released.

EvanZhouDev commented 1 year ago

There are quite a few breaking changes though 😅

Overall, the experience should be more streamlined and modern.

XCraftTM commented 1 year ago

It did? Okay i will test that... i will report tomorrow if it works or not...

XCraftTM commented 1 year ago
file:///Bot/node_modules/bard-ai/index.js:242
        const answer = chatData[4][0];
                               ^

TypeError: Cannot read properties of null (reading '4')
    at #query (file:///Bot/node_modules/bard-ai/index.js:242:32)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Chat.ask (file:///Bot/node_modules/bard-ai/index.js:344:32)
    at async /Bot/test.js:7:17

Node.js v18.17.0

Getting this error now... but works on my PC again... No idea why it happens...

Using:

import("bard-ai").then(async ({ default: Bard }) => {
    let bard = new Bard({
        "__Secure-1PSID": "COOKIE SECRET",    
        "__Secure-1PSIDTS": "COOKIE SECRET",
        });
    let conv = bard.createChat();
    console.log(await conv.ask("test"));
});
EvanZhouDev commented 1 year ago

Can you give a minimal recreation of your problem?

Like complete code to recreate the problem you are having.

XCraftTM commented 1 year ago

The Code i sent is everything i tested it with...