@google/genai 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -39
- package/dist/genai.d.ts +393 -15
- package/dist/index.js +3018 -2160
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3018 -2161
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.js +3201 -2304
- package/dist/node/index.js.map +1 -1
- package/dist/node/node.d.ts +393 -15
- package/dist/web/index.mjs +3195 -2297
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +393 -15
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -23,7 +23,6 @@ The Google Gen AI SDK is designed to work with Gemini 2.0 features.
|
|
|
23
23
|
> **API Key Security:** Avoid exposing API keys in client-side code.
|
|
24
24
|
> Use server-side implementations in production environments.
|
|
25
25
|
|
|
26
|
-
|
|
27
26
|
## Prerequisites
|
|
28
27
|
|
|
29
28
|
* Node.js version 18 or later
|
|
@@ -58,39 +57,6 @@ async function main() {
|
|
|
58
57
|
main();
|
|
59
58
|
```
|
|
60
59
|
|
|
61
|
-
## Web quickstart
|
|
62
|
-
|
|
63
|
-
The package contents are also available unzipped in the
|
|
64
|
-
`package/` directory of the bucket, so an equivalent web example is:
|
|
65
|
-
|
|
66
|
-
```html
|
|
67
|
-
<!DOCTYPE html>
|
|
68
|
-
<html lang="en">
|
|
69
|
-
<head>
|
|
70
|
-
<meta charset="UTF-8" />
|
|
71
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
72
|
-
<title>Using My Package</title>
|
|
73
|
-
</head>
|
|
74
|
-
<body>
|
|
75
|
-
<script type="module">
|
|
76
|
-
import {GoogleGenAI} from 'https://cdn.jsdelivr.net/npm/@google/genai@latest/+esm'
|
|
77
|
-
|
|
78
|
-
const ai = new GoogleGenAI({apiKey:"GEMINI_API_KEY"});
|
|
79
|
-
|
|
80
|
-
async function main() {
|
|
81
|
-
const response = await ai.models.generateContent({
|
|
82
|
-
model: 'gemini-2.0-flash-001',
|
|
83
|
-
contents: 'Why is the sky blue?',
|
|
84
|
-
});
|
|
85
|
-
console.log(response.text);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
main();
|
|
89
|
-
</script>
|
|
90
|
-
</body>
|
|
91
|
-
</html>
|
|
92
|
-
```
|
|
93
|
-
|
|
94
60
|
## Initialization
|
|
95
61
|
|
|
96
62
|
The Google Gen AI SDK provides support for both the
|
|
@@ -141,19 +107,19 @@ const ai = new GoogleGenAI({
|
|
|
141
107
|
All API features are accessed through an instance of the `GoogleGenAI` classes.
|
|
142
108
|
The submodules bundle together related API methods:
|
|
143
109
|
|
|
144
|
-
- [`ai.models`](https://googleapis.github.io/js-genai/classes/models.Models.html):
|
|
110
|
+
- [`ai.models`](https://googleapis.github.io/js-genai/main/classes/models.Models.html):
|
|
145
111
|
Use `models` to query models (`generateContent`, `generateImages`, ...), or
|
|
146
112
|
examine their metadata.
|
|
147
|
-
- [`ai.caches`](https://googleapis.github.io/js-genai/classes/caches.Caches.html):
|
|
113
|
+
- [`ai.caches`](https://googleapis.github.io/js-genai/main/classes/caches.Caches.html):
|
|
148
114
|
Create and manage `caches` to reduce costs when repeatedly using the same
|
|
149
115
|
large prompt prefix.
|
|
150
|
-
- [`ai.chats`](https://googleapis.github.io/js-genai/classes/chats.Chats.html):
|
|
116
|
+
- [`ai.chats`](https://googleapis.github.io/js-genai/main/classes/chats.Chats.html):
|
|
151
117
|
Create local stateful `chat` objects to simplify multi turn interactions.
|
|
152
|
-
- [`ai.files`](https://googleapis.github.io/js-genai/classes/files.Files.html):
|
|
118
|
+
- [`ai.files`](https://googleapis.github.io/js-genai/main/classes/files.Files.html):
|
|
153
119
|
Upload `files` to the API and reference them in your prompts.
|
|
154
120
|
This reduces bandwidth if you use a file many times, and handles files too
|
|
155
121
|
large to fit inline with your prompt.
|
|
156
|
-
- [`ai.live`](https://googleapis.github.io/js-genai/classes/live.Live.html):
|
|
122
|
+
- [`ai.live`](https://googleapis.github.io/js-genai/main/classes/live.Live.html):
|
|
157
123
|
Start a `live` session for real time interaction, allows text + audio + video
|
|
158
124
|
input, and text or audio output.
|
|
159
125
|
|
|
@@ -246,6 +212,31 @@ async function main() {
|
|
|
246
212
|
main();
|
|
247
213
|
```
|
|
248
214
|
|
|
215
|
+
### Generate Content
|
|
216
|
+
|
|
217
|
+
#### How to structure `contents` argument for `generateContent`
|
|
218
|
+
|
|
219
|
+
The SDK allows you to specify the following types in the `contents` parameter:
|
|
220
|
+
|
|
221
|
+
#### Content
|
|
222
|
+
|
|
223
|
+
- `Content`: The SDK will wrap the singular `Content` instance in an array which
|
|
224
|
+
contains only the given content instance
|
|
225
|
+
- `Content[]`: No transformation happens
|
|
226
|
+
|
|
227
|
+
#### Part
|
|
228
|
+
|
|
229
|
+
Parts will be aggregated on a singular Content, with role 'user'.
|
|
230
|
+
|
|
231
|
+
- `Part | string`: The SDK will wrap the `string` or `Part` in a `Content`
|
|
232
|
+
instance with role 'user'.
|
|
233
|
+
- `Part[] | string[]`: The SDK will wrap the full provided list into a single
|
|
234
|
+
`Content` with role 'user'.
|
|
235
|
+
|
|
236
|
+
**_NOTE:_** This doesn't apply to `FunctionCall` and `FunctionResponse` parts,
|
|
237
|
+
if you are specifying those, you need to explicitly provide the full
|
|
238
|
+
`Content[]` structure making it explicit which Parts are 'spoken' by the model,
|
|
239
|
+
or the user. The SDK will throw an exception if you try this.
|
|
249
240
|
|
|
250
241
|
## Preview Launch
|
|
251
242
|
|
|
@@ -253,3 +244,12 @@ The SDK is curently in a preview launch stage, per [Google's launch stages](http
|
|
|
253
244
|
|
|
254
245
|
> At Preview, products or features are ready for testing by customers. Preview offerings are often publicly announced, but are not necessarily feature-complete, and no SLAs or technical support commitments are provided for these. Unless stated otherwise by Google, Preview offerings are intended for use in test environments only. The average Preview stage lasts about six months.
|
|
255
246
|
|
|
247
|
+
## How is this different from the other Google AI SDKs
|
|
248
|
+
This SDK (`@google/genai`) is Google Deepmind’s "vanilla" SDK for its generative AI offerings, and is where Google Deepmind adds new AI features.
|
|
249
|
+
|
|
250
|
+
Models hosted either on the [Vertex AI platform](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/overview) or the [Gemini Developer platform](https://ai.google.dev/gemini-api/docs) are accessible through this SDK.
|
|
251
|
+
|
|
252
|
+
Other SDKs may be offering additional AI frameworks on top of this SDK, or may be targeting specific project environments (like Firebase).
|
|
253
|
+
|
|
254
|
+
The `@google/generative_language` and `@google-cloud/vertexai` SDKs are previous iterations of this SDK and are no longer receiving new Gemini 2.0+ features.
|
|
255
|
+
|