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

🐛 Fix iterating images data bugs, and chat ids #20

Closed Aldhanekaa closed 1 year ago

Aldhanekaa commented 1 year ago

Bugs from https://github.com/EvanZhouDev/bard-ai/commit/9ae833e7247cfd646511a0ba82cd12e5387c7bd4 that I fixed in this commit;

Iterating Images Data Bugs

Unable to iterate

This error occurs when there is no images replied from Bard;

    let images = jsonChatData[4].map((x) => {
                                 ^

TypeError: Cannot read properties of null (reading 'map')

Unable to get image url.

It returns an error when it tries to get the image url, it turns out that on x[0][5], the value was null.

url: x[0][5].match(/imgurl=([^&%]+)/)[1],
                         ^

TypeError: Cannot read properties of undefined (reading 'match')

✨ Proposing new feature!

In addition, I also proposing new data for the images returned from the queryBard function, and that is the image source, it contains the origin site, favicon, and page url the image was taken from.

source: {
    url: 'https://support.apple.com/id-id/HT201296',
    name: 'support.apple.com',
    favicon: 'https://encrypted-tbn1.gstatic.com/favicon-tbn?q=tbn:ANd9GcSJqnLNI_iecnSYb17tgaI6s89jZ7Bwu_L_KKgAB8-3S1RFhvojRd-j9V3UlDmEM-m26mQwS9JKa1nvliUshzVUJzhzNIUBzQwlsTg'
  }

Chat Ids Bugs

I notice that, the conversationID and responseID returned was not really the ID. This is the ID that is being returned;

    conversationID: 'Sure, here are some of the most popular Apple products',
    responseID: undefined,

It turns out because both conversationID and responseID, indexing from const jsonChatData = JSON.parse(chatData)[4][0] , however it should directly indexed from JSON.parse(chatData) (JSON array)

EvanZhouDev commented 1 year ago

See 96e55b0dba6ff121396bfaf75d354dd552b87a06. I added all of these changes but did some edits. You're added as a co-author 🙂. Please verify that it works, and I'll push to NPM!

EvanZhouDev commented 1 year ago

Unfortunately, I'm going to have to publish without your review, because I also forgot to push the types! I've tested things, and it works well, so if you have any additional concerns, you have my Slack :)

EvanZhouDev commented 1 year ago

Will be closing, reopen if you need to.

nainglynndw commented 1 year ago

url: x[0][5].match(/imgurl=([^&%]+)/)[1], remove that line from index.js and it will work