Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@google/generative-ai
Advanced tools
[!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.
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:
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-1.5-flash-latest" });
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-1.5-flash-latest" });
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());
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/node
folder and run npm install
.
Assign your API key to an environment variable: export API_KEY=MY_API_KEY
.
Run the sample file you're interested in. Example: node simple-text.js
.
To try out the sample web 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/web
folder and run npm install
.
Assign your API key to an environment variable: export API_KEY=MY_API_KEY
.
Serve your web app by running: npm run http-server
. Open the displayed URL in a browser.
npm install @google/generative-ai
.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.
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:
@google/generative-ai
- CHANGELOG.mdSee 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.13.0
countTokens
method to alternatively accept a GenerateContentRequest
.GoogleAICacheManager
utility to allow caching large content to be used in inference. This class is exported from the @google/generative-ai/server
subpath. Breaking change: The GoogleAIFileManager
class has been moved to be exported from this subpath as well instead of the /files
subpath.model
field from the internally formatted payload of countToken
requests as it was unnecessary.FAQs
Google AI JavaScript SDK
The npm package @google/generative-ai receives a total of 241,431 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.