From bd3356483b16fe3ad722118c6616eb546a7744cd Mon Sep 17 00:00:00 2001 From: Giom-V Date: Wed, 19 Jun 2024 14:40:13 +0200 Subject: [PATCH 1/9] Aligning README with the Python's one --- README.md | 70 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c6a3e2d2e..7b7b1dd77 100644 --- a/README.md +++ b/README.md @@ -8,20 +8,40 @@ > 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: -- Generate text from text-only input -- Generate text from text-and-images input (multimodal) -- Build multi-turn conversations (chat) -- _(for Node.js)_ Embedding +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. -You can use this JavaScript SDK for applications built with Node.js or for web apps. +You can use this JavaScript SDK for applications built with Node.js or for web apps (but be careful to secure your API key). + +## Get started with the Gemini API +1. Go to [Google AI Studio](https://aistudio.google.com/). +2. Login with your Google account. +3. [Create](https://aistudio.google.com/app/apikey) an API key. Note that in Europe the free tier is not available. +4. Try one of the Javascript SDK quickstarts: +- [Quickstart for Node.js](https://ai.google.dev/tutorials/node_quickstart) +- [Quickstart for web apps](https://ai.google.dev/tutorials/web_quickstart) -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: +## Usage example +See the [Node.js](https://ai.google.dev/tutorials/node_quickstart) or [Javascript](https://ai.google.dev/tutorials/web_quickstart) quickstarts for complete code. + +### For Node.js +1. Install the SDK package + ```js +npm install @google/generative-ai +``` + +2. Initialize the model +```js +const { GoogleGenerativeAI } = require("@google/generative-ai"); + +const genAI = new GoogleGenerativeAI(process.env.API_KEY); + const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash-latest" }); +``` +3. Run a prompt +```js const prompt = "Does this look store-bought or homemade?"; const image = { inlineData: { @@ -34,10 +54,32 @@ const result = await model.generateContent([prompt, image]); console.log(result.response.text()); ``` -For web: +### Web +1. Import the SDK +```html + + +``` + +2. Initialize the model + ```js +import { GoogleGenerativeAI } from "@google/generative-ai"; +const API_KEY = "..."; // Reminder: This should only be for local testing +const genAI = new GoogleGenerativeAI(API_KEY); const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash-latest" }); +``` +3. Run a prompt +```js const prompt = "Does this look store-bought or homemade?"; const image = { inlineData: { @@ -95,15 +137,7 @@ These quickstarts describe how to add your API key and the SDK to your app, init ## 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: -- [GoogleGenerativeAI](/docs/reference/main/generative-ai.md) -- [GoogleAIFileManager](/docs/reference/files/generative-ai.googleaifilemanager.md) - -## Changelog -- `@google/generative-ai` - [CHANGELOG.md](/packages/main/CHANGELOG.md) +See the [Gemini API Cookbook](https://github.com/google-gemini/gemini-api-cookbook/) or [ai.google.dev](https://ai.google.dev) for complete documentation. ## Contributing From 0a9d4b2aca733ee2a9e2e7af27a97e8898786390 Mon Sep 17 00:00:00 2001 From: Guillaume Vernade Date: Thu, 27 Jun 2024 14:50:55 +0200 Subject: [PATCH 2/9] Removing web version --- README.md | 71 ++----------------------------------------------------- 1 file changed, 2 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 7b7b1dd77..1e7410faf 100644 --- a/README.md +++ b/README.md @@ -16,15 +16,12 @@ You can use this JavaScript SDK for applications built with Node.js or for web a 1. Go to [Google AI Studio](https://aistudio.google.com/). 2. Login with your Google account. 3. [Create](https://aistudio.google.com/app/apikey) an API key. Note that in Europe the free tier is not available. -4. Try one of the Javascript SDK quickstarts: -- [Quickstart for Node.js](https://ai.google.dev/tutorials/node_quickstart) -- [Quickstart for web apps](https://ai.google.dev/tutorials/web_quickstart) +4. Try the [Node.js quickstart](https://ai.google.dev/tutorials/node_quickstart) ## Usage example -See the [Node.js](https://ai.google.dev/tutorials/node_quickstart) or [Javascript](https://ai.google.dev/tutorials/web_quickstart) quickstarts for complete code. +See the [Node.js quickstart](https://ai.google.dev/tutorials/node_quickstart) for complete code. -### For Node.js 1. Install the SDK package ```js @@ -54,44 +51,6 @@ const result = await model.generateContent([prompt, image]); console.log(result.response.text()); ``` -### Web -1. Import the SDK -```html - - -``` - -2. Initialize the model - -```js -import { GoogleGenerativeAI } from "@google/generative-ai"; -const API_KEY = "..."; // Reminder: This should only be for local testing -const genAI = new GoogleGenerativeAI(API_KEY); -const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash-latest" }); -``` - -3. Run a prompt -```js -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. @@ -109,32 +68,6 @@ This repository contains sample Node and web apps demonstrating how the SDK can 1. 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` - -1. [Obtain an API key](https://makersuite.google.com/app/apikey) to use with the Google AI SDKs. - -1. cd into the `samples/web` folder and run `npm install`. - -1. Assign your API key to an environment variable: `export API_KEY=MY_API_KEY`. - -1. 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: - - -- [Quickstart for Node.js](https://ai.google.dev/tutorials/node_quickstart) -- [Quickstart for web apps](https://ai.google.dev/tutorials/web_quickstart) - -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 See the [Gemini API Cookbook](https://github.com/google-gemini/gemini-api-cookbook/) or [ai.google.dev](https://ai.google.dev) for complete documentation. From 3684b92e85559f9ffce83e304ad5da4e6749207e Mon Sep 17 00:00:00 2001 From: Guillaume Vernade Date: Thu, 27 Jun 2024 15:42:58 +0200 Subject: [PATCH 3/9] Adding links to the Gemini models and Deepmind --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e7410faf..3ad4fbb85 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ > if you embed your API key directly in your JavaScript app or fetch it remotely > at runtime. -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. +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](https://ai.google.dev/models/gemini) created by [Google DeepMind](https://deepmind.google/technologies/gemini/#introduction). Gemini models are built from the ground up to be multimodal, so you can reason seamlessly across text, images, and code. You can use this JavaScript SDK for applications built with Node.js or for web apps (but be careful to secure your API key). From 6d05510dccff0f8b8d15f7cf9126f19ad8cf8dc0 Mon Sep 17 00:00:00 2001 From: Guillaume Vernade Date: Thu, 27 Jun 2024 15:43:56 +0200 Subject: [PATCH 4/9] Moving the warning slightly lower --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3ad4fbb85..cb6efd0ae 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Google AI SDK for JavaScript +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](https://ai.google.dev/models/gemini) created by [Google DeepMind](https://deepmind.google/technologies/gemini/#introduction). 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 @@ -8,10 +10,6 @@ > if you embed your API key directly in your JavaScript app or fetch it remotely > at runtime. -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](https://ai.google.dev/models/gemini) created by [Google DeepMind](https://deepmind.google/technologies/gemini/#introduction). Gemini models are built from the ground up to be multimodal, so you can reason seamlessly across text, images, and code. - -You can use this JavaScript SDK for applications built with Node.js or for web apps (but be careful to secure your API key). - ## Get started with the Gemini API 1. Go to [Google AI Studio](https://aistudio.google.com/). 2. Login with your Google account. From f6a8273c8459fc7659c14e2e2f42ee86a50e16ff Mon Sep 17 00:00:00 2001 From: Guillaume Vernade Date: Thu, 27 Jun 2024 16:41:30 +0200 Subject: [PATCH 5/9] Formatting --- README.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index cb6efd0ae..b91bebd13 100644 --- a/README.md +++ b/README.md @@ -11,15 +11,16 @@ The Google AI JavaScript SDK is the easiest way for JavaScript developers to bui > at runtime. ## Get started with the Gemini API + 1. Go to [Google AI Studio](https://aistudio.google.com/). 2. Login with your Google account. 3. [Create](https://aistudio.google.com/app/apikey) an API key. Note that in Europe the free tier is not available. 4. Try the [Node.js quickstart](https://ai.google.dev/tutorials/node_quickstart) - ## Usage example + See the [Node.js quickstart](https://ai.google.dev/tutorials/node_quickstart) for complete code. - + 1. Install the SDK package ```js @@ -27,6 +28,7 @@ npm install @google/generative-ai ``` 2. Initialize the model + ```js const { GoogleGenerativeAI } = require("@google/generative-ai"); @@ -36,6 +38,7 @@ const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash-latest" }); ``` 3. Run a prompt + ```js const prompt = "Does this look store-bought or homemade?"; const image = { @@ -55,16 +58,16 @@ This repository contains sample Node and web apps demonstrating how the SDK can **To try out the sample Node app, follow these steps:** -1. Check out this repository.\ +1. Check out this repository.\ `git clone https://github.com/google/generative-ai-js` -1. [Obtain an API key](https://makersuite.google.com/app/apikey) to use with the Google AI SDKs. +1. [Obtain an API key](https://makersuite.google.com/app/apikey) to use with the Google AI SDKs. -1. cd into the `samples/node` folder and run `npm install`. +1. cd into the `samples/node` folder and run `npm install`. -1. Assign your API key to an environment variable: `export API_KEY=MY_API_KEY`. +1. Assign your API key to an environment variable: `export API_KEY=MY_API_KEY`. -1. Run the sample file you're interested in. Example: `node simple-text.js`. +1. Run the sample file you're interested in. Example: `node simple-text.js`. ## Documentation From 69d8aecaf6602e06e37b2936aee470afa4aa9155 Mon Sep 17 00:00:00 2001 From: Guillaume Vernade Date: Fri, 28 Jun 2024 11:37:59 +0200 Subject: [PATCH 6/9] Duplicating the main README in packages/main/README.md --- packages/main/README.md | 92 ++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 62 deletions(-) diff --git a/packages/main/README.md b/packages/main/README.md index 003ae41fb..b91bebd13 100644 --- a/packages/main/README.md +++ b/packages/main/README.md @@ -1,5 +1,7 @@ # Google AI SDK for JavaScript +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](https://ai.google.dev/models/gemini) created by [Google DeepMind](https://deepmind.google/technologies/gemini/#introduction). 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 @@ -8,40 +10,40 @@ > 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: -- Generate text from text-only input -- Generate text from text-and-images input (multimodal) -- Build multi-turn conversations (chat) -- _(for Node.js)_ Embedding +## Get started with the Gemini API -You can use this JavaScript SDK for applications built with Node.js or for web apps. +1. Go to [Google AI Studio](https://aistudio.google.com/). +2. Login with your Google account. +3. [Create](https://aistudio.google.com/app/apikey) an API key. Note that in Europe the free tier is not available. +4. Try the [Node.js quickstart](https://ai.google.dev/tutorials/node_quickstart) -For example, with just a few lines of code, you can access Gemini's multimodal capabilities to generate text from text-and-image input. +## Usage example -For Node.js: -``` -const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash-latest" }); +See the [Node.js quickstart](https://ai.google.dev/tutorials/node_quickstart) for complete code. -const prompt = "Does this look store-bought or homemade?"; -const image = { - inlineData: { - data: Buffer.from(fs.readFileSync("cookie.png")).toString("base64"), - mimeType: "image/png", - }, -}; +1. Install the SDK package -const result = await model.generateContent([prompt, image]); -console.log(result.response.text()); +```js +npm install @google/generative-ai ``` -For web: -``` +2. Initialize the model + +```js +const { GoogleGenerativeAI } = require("@google/generative-ai"); + +const genAI = new GoogleGenerativeAI(process.env.API_KEY); + const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash-latest" }); +``` +3. Run a prompt + +```js const prompt = "Does this look store-bought or homemade?"; const image = { inlineData: { - data: base64EncodedImage /* see JavaScript quickstart for details */, + data: Buffer.from(fs.readFileSync("cookie.png")).toString("base64"), mimeType: "image/png", }, }; @@ -56,54 +58,20 @@ This repository contains sample Node and web apps demonstrating how the SDK can **To try out the sample Node app, follow these steps:** -1. Check out this repository.\ -`git clone https://github.com/google/generative-ai-js` - -1. [Obtain an API key](https://makersuite.google.com/app/apikey) to use with the Google AI SDKs. - -1. cd into the `samples/node` folder and run `npm install`. - -1. Assign your API key to an environment variable: `export API_KEY=MY_API_KEY`. - -1. 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.\ +1. Check out this repository.\ `git clone https://github.com/google/generative-ai-js` -1. [Obtain an API key](https://makersuite.google.com/app/apikey) to use with the Google AI SDKs. +1. [Obtain an API key](https://makersuite.google.com/app/apikey) to use with the Google AI SDKs. -1. cd into the `samples/web` folder and run `npm install`. +1. cd into the `samples/node` folder and run `npm install`. -1. Assign your API key to an environment variable: `export API_KEY=MY_API_KEY`. +1. Assign your API key to an environment variable: `export API_KEY=MY_API_KEY`. -1. 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: - - -- [Quickstart for Node.js](https://ai.google.dev/tutorials/node_quickstart) -- [Quickstart for web apps](https://ai.google.dev/tutorials/web_quickstart) - -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. +1. Run the sample file you're interested in. Example: `node simple-text.js`. ## 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: -- [GoogleGenerativeAI](/docs/reference/main/generative-ai.md) -- [GoogleAIFileManager](/docs/reference/files/generative-ai.googleaifilemanager.md) - -## Changelog -- `@google/generative-ai` - [CHANGELOG.md](/main/packages/main/CHANGELOG.md) +See the [Gemini API Cookbook](https://github.com/google-gemini/gemini-api-cookbook/) or [ai.google.dev](https://ai.google.dev) for complete documentation. ## Contributing From 6dd4dc8a903070af8e5d5fc5c865eabd31e7bd4f Mon Sep 17 00:00:00 2001 From: Guillaume Vernade Date: Fri, 28 Jun 2024 11:40:10 +0200 Subject: [PATCH 7/9] Better link naming for creating an API key --- README.md | 2 +- packages/main/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b91bebd13..284fa02bf 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The Google AI JavaScript SDK is the easiest way for JavaScript developers to bui 1. Go to [Google AI Studio](https://aistudio.google.com/). 2. Login with your Google account. -3. [Create](https://aistudio.google.com/app/apikey) an API key. Note that in Europe the free tier is not available. +3. [Create an API key](https://aistudio.google.com/app/apikey). Note that in Europe the free tier is not available. 4. Try the [Node.js quickstart](https://ai.google.dev/tutorials/node_quickstart) ## Usage example diff --git a/packages/main/README.md b/packages/main/README.md index b91bebd13..284fa02bf 100644 --- a/packages/main/README.md +++ b/packages/main/README.md @@ -14,7 +14,7 @@ The Google AI JavaScript SDK is the easiest way for JavaScript developers to bui 1. Go to [Google AI Studio](https://aistudio.google.com/). 2. Login with your Google account. -3. [Create](https://aistudio.google.com/app/apikey) an API key. Note that in Europe the free tier is not available. +3. [Create an API key](https://aistudio.google.com/app/apikey). Note that in Europe the free tier is not available. 4. Try the [Node.js quickstart](https://ai.google.dev/tutorials/node_quickstart) ## Usage example From 8f90472e137eeb490d388243eaa9c0a2fbffdc22 Mon Sep 17 00:00:00 2001 From: Guillaume Vernade Date: Fri, 28 Jun 2024 16:11:43 +0200 Subject: [PATCH 8/9] Formatting --- README.md | 67 ++++++++++++++++++++++++----------------- packages/main/README.md | 67 ++++++++++++++++++++++++----------------- 2 files changed, 80 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 284fa02bf..a2e081414 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,40 @@ # Google AI SDK for JavaScript -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](https://ai.google.dev/models/gemini) created by [Google DeepMind](https://deepmind.google/technologies/gemini/#introduction). 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. +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](https://ai.google.dev/models/gemini) created by +[Google DeepMind](https://deepmind.google/technologies/gemini/#introduction). +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. ## Get started with the Gemini API -1. Go to [Google AI Studio](https://aistudio.google.com/). -2. Login with your Google account. -3. [Create an API key](https://aistudio.google.com/app/apikey). Note that in Europe the free tier is not available. -4. Try the [Node.js quickstart](https://ai.google.dev/tutorials/node_quickstart) +1. Go to [Google AI Studio](https://aistudio.google.com/). +2. Login with your Google account. +3. [Create an API key](https://aistudio.google.com/app/apikey). Note that in + Europe the free tier is not available. +4. Try the + [Node.js quickstart](https://ai.google.dev/tutorials/node_quickstart) ## Usage example -See the [Node.js quickstart](https://ai.google.dev/tutorials/node_quickstart) for complete code. +See the [Node.js quickstart](https://ai.google.dev/tutorials/node_quickstart) +for complete code. -1. Install the SDK package +1. Install the SDK package ```js npm install @google/generative-ai ``` -2. Initialize the model +1. Initialize the model ```js const { GoogleGenerativeAI } = require("@google/generative-ai"); @@ -37,7 +44,7 @@ const genAI = new GoogleGenerativeAI(process.env.API_KEY); const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash-latest" }); ``` -3. Run a prompt +1. Run a prompt ```js const prompt = "Does this look store-bought or homemade?"; @@ -54,29 +61,35 @@ 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. +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` +1. Check out this repository. \ + `git clone https://github.com/google/generative-ai-js` -1. [Obtain an API key](https://makersuite.google.com/app/apikey) to use with the Google AI SDKs. +1. [Obtain an API key](https://makersuite.google.com/app/apikey) to use with + the Google AI SDKs. -1. cd into the `samples/node` folder and run `npm install`. +1. cd into the `samples/node` folder and run `npm install`. -1. Assign your API key to an environment variable: `export API_KEY=MY_API_KEY`. +1. Assign your API key to an environment variable: `export API_KEY=MY_API_KEY`. -1. Run the sample file you're interested in. Example: `node simple-text.js`. +1. Run the sample file you're interested in. Example: `node simple-text.js`. ## Documentation -See the [Gemini API Cookbook](https://github.com/google-gemini/gemini-api-cookbook/) or [ai.google.dev](https://ai.google.dev) for complete documentation. +See the +[Gemini API Cookbook](https://github.com/google-gemini/gemini-api-cookbook/) or +[ai.google.dev](https://ai.google.dev) for complete documentation. ## Contributing -See [Contributing](/docs/contributing.md) for more information on contributing to the Google AI JavaScript SDK. +See [Contributing](/docs/contributing.md) 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](http://www.apache.org/licenses/LICENSE-2.0). +The contents of this repository are licensed under the +[Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0). \ No newline at end of file diff --git a/packages/main/README.md b/packages/main/README.md index 284fa02bf..a2e081414 100644 --- a/packages/main/README.md +++ b/packages/main/README.md @@ -1,33 +1,40 @@ # Google AI SDK for JavaScript -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](https://ai.google.dev/models/gemini) created by [Google DeepMind](https://deepmind.google/technologies/gemini/#introduction). 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. +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](https://ai.google.dev/models/gemini) created by +[Google DeepMind](https://deepmind.google/technologies/gemini/#introduction). +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. ## Get started with the Gemini API -1. Go to [Google AI Studio](https://aistudio.google.com/). -2. Login with your Google account. -3. [Create an API key](https://aistudio.google.com/app/apikey). Note that in Europe the free tier is not available. -4. Try the [Node.js quickstart](https://ai.google.dev/tutorials/node_quickstart) +1. Go to [Google AI Studio](https://aistudio.google.com/). +2. Login with your Google account. +3. [Create an API key](https://aistudio.google.com/app/apikey). Note that in + Europe the free tier is not available. +4. Try the + [Node.js quickstart](https://ai.google.dev/tutorials/node_quickstart) ## Usage example -See the [Node.js quickstart](https://ai.google.dev/tutorials/node_quickstart) for complete code. +See the [Node.js quickstart](https://ai.google.dev/tutorials/node_quickstart) +for complete code. -1. Install the SDK package +1. Install the SDK package ```js npm install @google/generative-ai ``` -2. Initialize the model +1. Initialize the model ```js const { GoogleGenerativeAI } = require("@google/generative-ai"); @@ -37,7 +44,7 @@ const genAI = new GoogleGenerativeAI(process.env.API_KEY); const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash-latest" }); ``` -3. Run a prompt +1. Run a prompt ```js const prompt = "Does this look store-bought or homemade?"; @@ -54,29 +61,35 @@ 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. +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` +1. Check out this repository. \ + `git clone https://github.com/google/generative-ai-js` -1. [Obtain an API key](https://makersuite.google.com/app/apikey) to use with the Google AI SDKs. +1. [Obtain an API key](https://makersuite.google.com/app/apikey) to use with + the Google AI SDKs. -1. cd into the `samples/node` folder and run `npm install`. +1. cd into the `samples/node` folder and run `npm install`. -1. Assign your API key to an environment variable: `export API_KEY=MY_API_KEY`. +1. Assign your API key to an environment variable: `export API_KEY=MY_API_KEY`. -1. Run the sample file you're interested in. Example: `node simple-text.js`. +1. Run the sample file you're interested in. Example: `node simple-text.js`. ## Documentation -See the [Gemini API Cookbook](https://github.com/google-gemini/gemini-api-cookbook/) or [ai.google.dev](https://ai.google.dev) for complete documentation. +See the +[Gemini API Cookbook](https://github.com/google-gemini/gemini-api-cookbook/) or +[ai.google.dev](https://ai.google.dev) for complete documentation. ## Contributing -See [Contributing](/docs/contributing.md) for more information on contributing to the Google AI JavaScript SDK. +See [Contributing](/docs/contributing.md) 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](http://www.apache.org/licenses/LICENSE-2.0). +The contents of this repository are licensed under the +[Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0). \ No newline at end of file From 69e59dc4f87466841fe4e92589cbb1df574fee99 Mon Sep 17 00:00:00 2001 From: Giom-V Date: Thu, 4 Jul 2024 14:59:46 +0200 Subject: [PATCH 9/9] Adding back the SDK documentation --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a2e081414..96decf7b5 100644 --- a/README.md +++ b/README.md @@ -80,9 +80,14 @@ access and utilize the Gemini model for various use cases. ## Documentation -See the +Check out the docs for this SDK here in the repo and in particular +[GoogleGenerativeAI](/docs/reference/main/generative-ai.md) and +[GoogleAIFileManager](/docs/reference/files/generative-ai.googleaifilemanager.md). + +See also the [Gemini API Cookbook](https://github.com/google-gemini/gemini-api-cookbook/) or -[ai.google.dev](https://ai.google.dev) for complete documentation. +[ai.google.dev](https://ai.google.dev) for more generic documentation about the +Gemini API. ## Contributing