Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@google/generative-ai
Advanced tools
The Google AI JavaScript SDK is the easiest way for JavaScript developers to build with the Gemini API. The Gemini API gives you access to Gemini models created by Google DeepMind. Gemini models are built from the ground up to be multimodal, so you can reason seamlessly across text, images, and code.
[!CAUTION] Using the Google AI SDK for JavaScript directly from a client-side app is recommended for prototyping only. If you plan to enable billing, we strongly recommend that you call the Google AI Gemini API only server-side to keep your API key safe. You risk potentially exposing your API key to malicious actors if you embed your API key directly in your JavaScript app or fetch it remotely at runtime.
See the Node.js quickstart for complete code.
npm install @google/generative-ai
const { GoogleGenerativeAI } = require("@google/generative-ai");
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
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());
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:
Check out this repository.
git clone https://github.com/google/generative-ai-js
Obtain an API key to use with the Google AI SDKs.
cd into the samples
folder and run npm install
.
Assign your API key to an environment variable: export API_KEY=MY_API_KEY
.
Open the sample file you're interested in. Example: text_generation.js
.
In the runAll()
function, comment out any samples you don't want to run.
Run the sample file. Example: node text_generation.js
.
See the Gemini API Cookbook or ai.google.dev for complete documentation.
See Contributing for more information on contributing to the Google AI JavaScript SDK.
The contents of this repository are licensed under the Apache License, version 2.0.
0.20.0
frequencyPenalty
, presencePenalty
, responseLogprobs
, and logProbs
parameters support for generationConfig
. Added avgLogprobs
and logprobsResult
to GenerateContentResponse
. Updated test cases.FAQs
Google AI JavaScript SDK
The npm package @google/generative-ai receives a total of 177,746 weekly downloads. As such, @google/generative-ai popularity was classified as popular.
We found that @google/generative-ai demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.