You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See the [Authentication][authentication] section in the base directory's README.
62
+
To learn how to authenticate to the API, see the [Authentication][authentication].
63
63
64
64
## Authorization
65
65
66
-
The client application making API calls must be granted [authorization scopes][auth-scopes] required for the desired Vertex AI APIs, and the authenticated principal must have the [IAM role(s)][predefined-iam-roles] required to access GCP resources using the Vertex AI API calls.
66
+
When a client application makes a call to the Vertex AI API, the application
67
+
must be granted the [authorization scopes][auth-scopes] that are required for
68
+
the API. Additionally, the authenticated principal must have the
69
+
[IAM role(s)][predefined-iam-roles] that are required to access the Google Cloud
70
+
resources being called.
67
71
68
72
## Getting Started
69
73
74
+
Follow the instructions in this section to get started using the Vertex AI SDK for Java.
75
+
70
76
### Prerequisites
71
77
72
-
You will need a [Google Cloud Platform Console][developer-console] project with the Vertex AI [API enabled][enable-api].
73
-
You will need to [enable billing][enable-billing] to use Google Vertex AI.
74
-
[Follow these instructions][create-project] to get your project set up. You will also need to set up the local development environment by
75
-
[installing the Google Cloud Command Line Interface][cloud-cli] and running the following commands in command line:
76
-
`gcloud auth login` and `gcloud config set project [YOUR PROJECT ID]`.
78
+
To use the Vertex AI SDK for Java, you must have completed the following:
79
+
80
+
*[Create a Google Cloud project][create-project].
81
+
*[Enable the Vertex AI API][enable-api] for your project.
82
+
*[Enable billing][enable-billing] for your project.
83
+
*[Install the Google Cloud Command Line Interface][cloud-cli] and run the
84
+
following commands in command line:
77
85
78
-
To acquire user credentials to use for [Application Default Credentials][adc], run `gcloud auth application-default login`.
86
+
```sh
87
+
gcloud auth login &&
88
+
gcloud config set project <var>PROJECT_ID</var>
89
+
```
79
90
80
-
### Installation and setup
91
+
To acquire user credentials to use for [Application Default Credentials][adc],
92
+
run `gcloud auth application-default login`.
81
93
82
-
You'll need to obtain the `google-cloud-vertexai` library. See the [Add Dependency](#add-dependency) section
83
-
to add `google-cloud-vertexai` as a dependency in your code.
94
+
### Install and setup the SDK
84
95
85
-
## About Vertex AI
96
+
You must install the `google-cloud-vertexai` library. See the
97
+
[Add Dependency](#add-dependency) section
98
+
to learn how to add `google-cloud-vertexai` as a dependency in your code.
86
99
87
-
[Vertex AI][product-docs] is an integrated suite of machine learning tools and services for building and using ML models with AutoML or custom code. It was previously known as AI Platform. Vertex AI offers both novices and experts the best workbench for the entire machine learning development lifecycle. This SDK currently only supports Generative AI service on the Vertex AI platform. To access the full set of services on the Vertex AI, consider using the [`google-cloud-aiplatform` client libraries][aiplatform-client-libraries].
100
+
### Use the Vertex AI SDK for Java
88
101
89
-
### Vertex AI SDK
90
-
Vertex AI provides [Generative AI Studio](generative-ai-studio) that supports text generation from multi-modality input via a set of most advanced models from Google. This brings out a wide range of applications.
102
+
The following sections show you how to perform common tasks by using the
103
+
Vertex AI SDK for Java.
91
104
92
105
#### Basic Text Generation
93
106
Vertex AI SDK allows you to access the service programmatically. The following code snippet is the most basic usage of SDK
@@ -116,8 +129,9 @@ public class Main {
116
129
}
117
130
```
118
131
119
-
#### Text Generation with Streaming
120
-
To get a streamed output, you can use the `generateContentStream` method
132
+
#### Stream generated output
133
+
134
+
To get a streamed output, you can use the `generateContentStream` method:
121
135
122
136
```java
123
137
package <your package name>
@@ -178,8 +192,10 @@ public class Main {
178
192
}
179
193
```
180
194
181
-
#### Text Generation from Multi-modal Input
182
-
To generate text based on data of multiple modalities, one needs to make a `Content`, which is made easier by `ContentMaker`:
195
+
#### Generate text from multi-modal input
196
+
197
+
To generate text from a prompt that contains multiple modalities of data, use
198
+
`ContentMaker` to make a `Content`:
183
199
184
200
```java
185
201
package <your package name>;
@@ -260,8 +276,10 @@ public class Main {
260
276
}
261
277
```
262
278
263
-
#### UsingChatSessionforMulti-turn Conversation
264
-
Yeah, we know, that isn't the most intuitive and easy way to chat with a model. Therefore we provide a `Chat` class:
279
+
#### Use `ChatSession` for multi-turn chat
280
+
281
+
The Vertex AI SDK for Java provides a `ChatSession` class that lets you easily
282
+
chat with the model:
265
283
266
284
```java
267
285
package <your package name>;
@@ -305,19 +323,21 @@ public class Main {
305
323
}
306
324
```
307
325
308
-
#### Generation with customized configurations
326
+
#### Update configurations
309
327
310
328
The Vertex AI SDK for Java provides configurations for customizing content
311
329
generation. You can configure options like
312
-
[GenerationConfig][generationconfig-ref] and [SafetySetting][safetysetting-ref],
313
-
or add [Tool][tool-ref] for function calling.
330
+
[GenerationConfig][generationconfig-ref], [SafetySetting][safetysetting-ref], and
331
+
[system instructions][system-instruction], or add [Tool][tool-ref] for function
332
+
calling.
314
333
315
-
You can choose between two configuration approaches: set configs during model
316
-
instantiation for consistency across all text generations, or adjust them on a
317
-
per-request basis for fine-grained control.
334
+
You can choose between two configuration approaches: 1) setconfigurations
335
+
during model instantiation for consistency across all text generations, or 2)
336
+
adjust them on a per-request basis for fine-grained control.
318
337
319
338
##### Model level configurations
320
339
340
+
Below is an example of configure `GenerationConfig`for a `GenerativeModel`:
321
341
```java
322
342
package <PACKAGE_NAME>
323
343
@@ -355,9 +375,45 @@ public class Main {
355
375
}
356
376
```
357
377
358
-
##### Request level configurations
378
+
And an example of configuring preambles as a [system instruction][system-instruction].
379
+
```java
380
+
package <your package name>
359
381
360
-
Our SDK provides fluent APIs to control request level configurations.
0 commit comments