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

✨ Google Lens Support, Image Recognition v1.6.0 #27

Closed Aldhanekaa closed 1 year ago

Aldhanekaa commented 1 year ago

NEW Features!

The new feature enables us to bring image along with Bard! Supports format: JPEG , JPG, PNG, WebP

How to use it?

Get Image Buffer

You need to get the buffer of the image first, whether it's from internet or your local machine

Upload the Image to Google Service

By using Bard.uploadImage function, it will upload your buffer file to Google Service, it returns image location that placed in Google Service.

    let imageLocation = await Bard.uploadImage(
        fileSize,
        "FILE_NAME.jpg",
        fileBuffer
    );

Ask It!

The previous imageLocation is needed as function argument for askAI or the method Chat.ask

   console.log(
        await myConversation.ask("What city is this?", true, {
            fileName: "FILE_NAME.jpg",
            imageFileLocation: imageLocation,
        })
    );

Example

import Bard from "bard-ai";
import fs from "fs";

const fileData = fs.readFileSync("./Tokyo.webp");

(async function () {
    let imageLocation = await Bard.uploadImage(
        fileData.buffer.byteLength,
        "FILE_NAME.jpg",
        fileData.buffer
    );

    console.log(
        await myConversation.ask("What city is this?", true, {
            fileName: "FILE_NAME.jpg",
            imageFileLocation: imageLocation,
        })
    );
})();
Aldhanekaa commented 1 year ago

What do you guys think, especially @EvanZhouDev @ThatXliner? Should we just separate different function to upload the image to Google Service? Or just move it inside queryBard function?

Im still considering this, to be honest.

EvanZhouDev commented 1 year ago

@RFS-ADRENO is also a great contributor around here :)

But let's talk about this on Slack, I have a few suggestions...

Aldhanekaa commented 1 year ago

Move To Version 2