npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@google/generative-ai

v0.8.0

Published

Google AI JavaScript SDK

Downloads

374,889

Readme

Google AI JavaScript SDK

The Google AI JavaScript SDK enables developers to use Google's state-of-the-art generative AI models (like Gemini) to build AI-powered features and applications. This SDK supports use cases like:

  • Generate text from text-only input
  • Generate text from text-and-images input (multimodal)
  • Build multi-turn conversations (chat)
  • (for Node.js) Embedding

You can use this JavaScript SDK for applications built with Node.js or for web apps.

For example, with just a few lines of code, you can access Gemini's multimodal capabilities to generate text from text-and-image input.

For Node.js:

const model = genAI.getGenerativeModel({ model: "gemini-pro-vision" });

const prompt = "Does this look store-bought or homemade?";
const image = {
  inlineData: {
    data: Buffer.from(fs.readFileSync("cookie.png")).toString("base64"),
    mimeType: "image/png",
  },
};

const result = await model.generateContent([prompt, image]);
console.log(result.response.text());

For web:

const model = genAI.getGenerativeModel({ model: "gemini-pro-vision" });

const prompt = "Does this look store-bought or homemade?";
const image = {
  inlineData: {
    data: base64EncodedImage /* see JavaScript quickstart for details */,
    mimeType: "image/png",
  },
};

const result = await model.generateContent([prompt, image]);
console.log(result.response.text());

Try out a sample app

This repository contains sample Node and web apps demonstrating how the SDK can access and utilize the Gemini model for various use cases.

To try out the sample Node app, follow these steps:

  1. Check out this repository.
    git clone https://github.com/google/generative-ai-js

  2. Obtain an API key to use with the Google AI SDKs.

  3. cd into the samples/node folder and run npm install.

  4. Assign your API key to an environment variable: export API_KEY=MY_API_KEY.

  5. Run the sample file you're interested in. Example: node simple-text.js.

To try out the sample web app, follow these steps:

  1. Check out this repository.
    git clone https://github.com/google/generative-ai-js

  2. Obtain an API key to use with the Google AI SDKs.

  3. cd into the samples/web folder and run npm install.

  4. Assign your API key to an environment variable: export API_KEY=MY_API_KEY.

  5. Serve your web app by running: npm run http-server. Open the displayed URL in a browser.

Installation and usage

  • For Node.js (or web projects using NPM), run npm install @google/generative-ai.
  • For web, add import { GoogleGenerativeAI } from "https://esm.run/@google/generative-ai".

For detailed instructions, you can find quickstarts for the Google AI JavaScript SDK in the Google documentation:

These quickstarts describe how to add your API key and the SDK to your app, initialize the model, and then call the API to access the model. It also describes some additional use cases and features, like streaming, counting tokens, and controlling responses. For Node.js, embedding is also available.

Documentation

Find complete documentation for the Google AI SDKs and the Gemini model in the Google documentation:
https://ai.google.dev/docs

Find reference docs for this SDK here in the repo:

Changelog

Contributing

See Contributing for more information on contributing to the Google AI JavaScript SDK.

License

The contents of this repository are licensed under the Apache License, version 2.0.