Skip to content

Commit 29b2a36

Browse files
copybara-service[bot]Zhenyi Qi
andauthored
feat: [vertexai] Remove 'preview' namespace and start using @BetaApi (#10330)
BREAKING_CHANGE: all APIs under preview namespace will be taken out from it and we'll use @BetaApi to align with other java libraries. PiperOrigin-RevId: 604637135 Co-authored-by: Zhenyi Qi <[email protected]>
1 parent 5b5bff4 commit 29b2a36

File tree

13 files changed

+95
-34
lines changed

13 files changed

+95
-34
lines changed

java-vertexai/README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Vertex AI SDK allows you to access the service programmatically. The following c
9696
package <your package name>
9797

9898
import com.google.cloud.vertexai.VertexAI;
99-
import com.google.cloud.vertexai.generativeai.preview.GenerativeModel;
99+
import com.google.cloud.vertexai.generativeai.GenerativeModel;
100100
import com.google.cloud.vertexai.api.GenerateContentResponse;
101101
import java.io.IOException;
102102

@@ -123,8 +123,8 @@ To get a streamed output, you can use the `generateContentStream` method
123123
package <your package name>
124124

125125
import com.google.cloud.vertexai.VertexAI;
126-
import com.google.cloud.vertexai.generativeai.preview.GenerativeModel;
127-
import com.google.cloud.vertexai.generativeai.preview.ResponseStream;
126+
import com.google.cloud.vertexai.generativeai.GenerativeModel;
127+
import com.google.cloud.vertexai.generativeai.ResponseStream;
128128
import com.google.cloud.vertexai.api.GenerateContentResponse;
129129
import java.io.IOException;
130130

@@ -151,10 +151,10 @@ To generate text based on data of multiple modalities, one needs to make a `Cont
151151
package <your package name>;
152152

153153
import com.google.cloud.vertexai.VertexAI;
154-
import com.google.cloud.vertexai.generativeai.preview.GenerativeModel;
155-
import com.google.cloud.vertexai.generativeai.preview.ResponseStream;
156-
import com.google.cloud.vertexai.generativeai.preview.ContentMaker;
157-
import com.google.cloud.vertexai.generativeai.preview.PartMaker;
154+
import com.google.cloud.vertexai.generativeai.GenerativeModel;
155+
import com.google.cloud.vertexai.generativeai.ResponseStream;
156+
import com.google.cloud.vertexai.generativeai.ContentMaker;
157+
import com.google.cloud.vertexai.generativeai.PartMaker;
158158
import com.google.cloud.vertexai.api.GenerateContentResponse;
159159
import java.util.Arrays;
160160

@@ -188,9 +188,9 @@ package <your package name>;
188188
import com.google.cloud.vertexai.VertexAI;
189189
import com.google.cloud.vertexai.api.Content;
190190
import com.google.cloud.vertexai.api.GenerateContentResponse;
191-
import com.google.cloud.vertexai.generativeai.preview.ContentMaker;
192-
import com.google.cloud.vertexai.generativeai.preview.GenerativeModel;
193-
import com.google.cloud.vertexai.generativeai.preview.ResponseHandler;
191+
import com.google.cloud.vertexai.generativeai.ContentMaker;
192+
import com.google.cloud.vertexai.generativeai.GenerativeModel;
193+
import com.google.cloud.vertexai.generativeai.ResponseHandler;
194194
import java.io.IOException;
195195
import java.util.Arrays;
196196
import java.util.List;
@@ -233,9 +233,9 @@ Yeah, we know, that isn't the most intuitive and easy way to chat with a model.
233233
package <your package name>;
234234
235235
import com.google.cloud.vertexai.VertexAI;
236-
import com.google.cloud.vertexai.generativeai.preview.GenerativeModel;
237-
import com.google.cloud.vertexai.generativeai.preview.ChatSession;
238-
import com.google.cloud.vertexai.generativeai.preview.ResponseStream;
236+
import com.google.cloud.vertexai.generativeai.GenerativeModel;
237+
import com.google.cloud.vertexai.generativeai.ChatSession;
238+
import com.google.cloud.vertexai.generativeai.ResponseStream;
239239
import com.google.cloud.vertexai.api.GenerateContentResponse;
240240
import com.google.cloud.vertexai.api.GenerationConfig;
241241
import java.io.IOException;
@@ -278,10 +278,10 @@ In a chat, we can also do function calling.
278278
```java
279279
package <your package name>;
280280
import com.google.cloud.vertexai.VertexAI;
281-
import com.google.cloud.vertexai.generativeai.preview.ChatSession;
282-
import com.google.cloud.vertexai.generativeai.preview.GenerativeModel;
283-
import com.google.cloud.vertexai.generativeai.preview.ResponseHandler;
284-
import com.google.cloud.vertexai.generativeai.preview.ResponseStream;
281+
import com.google.cloud.vertexai.generativeai.ChatSession;
282+
import com.google.cloud.vertexai.generativeai.GenerativeModel;
283+
import com.google.cloud.vertexai.generativeai.ResponseHandler;
284+
import com.google.cloud.vertexai.generativeai.ResponseStream;
285285
import com.google.cloud.vertexai.api.Content;
286286
import com.google.cloud.vertexai.api.GenerateContentResponse;
287287
import java.io.IOException;
@@ -369,8 +369,8 @@ Vertex AI uses gRPC and rest for the transport layer. By default, we use gRPC tr
369369
package <your package name>
370370

371371
import com.google.cloud.vertexai.VertexAI;
372-
import com.google.cloud.vertexai.generativeai.preview.GenerativeModel;
373-
import com.google.cloud.vertexai.generativeai.preview.Transport;
372+
import com.google.cloud.vertexai.generativeai.GenerativeModel;
373+
import com.google.cloud.vertexai.generativeai.Transport;
374374
import com.google.cloud.vertexai.api.GenerateContentResponse;
375375
import java.io.IOException;
376376

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.google.cloud.vertexai.generativeai.preview;
17+
package com.google.cloud.vertexai.generativeai;
1818

19-
import static com.google.cloud.vertexai.generativeai.preview.ResponseHandler.aggregateStreamIntoResponse;
20-
import static com.google.cloud.vertexai.generativeai.preview.ResponseHandler.getContent;
21-
import static com.google.cloud.vertexai.generativeai.preview.ResponseHandler.getFinishReason;
19+
import static com.google.cloud.vertexai.generativeai.ResponseHandler.aggregateStreamIntoResponse;
20+
import static com.google.cloud.vertexai.generativeai.ResponseHandler.getContent;
21+
import static com.google.cloud.vertexai.generativeai.ResponseHandler.getFinishReason;
2222

23+
import com.google.api.core.BetaApi;
2324
import com.google.cloud.vertexai.api.Candidate.FinishReason;
2425
import com.google.cloud.vertexai.api.Content;
2526
import com.google.cloud.vertexai.api.GenerateContentResponse;
@@ -37,6 +38,7 @@ public class ChatSession {
3738
private ResponseStream<GenerateContentResponse> currentResponseStream = null;
3839
private GenerateContentResponse currentResponse = null;
3940

41+
@BetaApi
4042
public ChatSession(GenerativeModel model) {
4143
if (model == null) {
4244
throw new IllegalArgumentException("model should not be null");
@@ -51,6 +53,7 @@ public ChatSession(GenerativeModel model) {
5153
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
5254
* stream by stream() method.
5355
*/
56+
@BetaApi
5457
public ResponseStream<GenerateContentResponse> sendMessageStream(String text) throws IOException {
5558
return sendMessageStream(text, null, null);
5659
}
@@ -63,6 +66,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(String text) th
6366
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
6467
* stream by stream() method.
6568
*/
69+
@BetaApi
6670
public ResponseStream<GenerateContentResponse> sendMessageStream(
6771
String text, GenerationConfig generationConfig) throws IOException {
6872
return sendMessageStream(text, generationConfig, null);
@@ -76,6 +80,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
7680
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
7781
* stream by stream() method.
7882
*/
83+
@BetaApi("safetySettings is a preview feature.")
7984
public ResponseStream<GenerateContentResponse> sendMessageStream(
8085
String text, List<SafetySetting> safetySettings) throws IOException {
8186
return sendMessageStream(text, null, safetySettings);
@@ -90,6 +95,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
9095
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
9196
* stream by stream() method.
9297
*/
98+
@BetaApi("safetySettings is a preview feature.")
9399
public ResponseStream<GenerateContentResponse> sendMessageStream(
94100
String text, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
95101
throws IOException {
@@ -111,6 +117,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
111117
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
112118
* stream by stream() method.
113119
*/
120+
@BetaApi
114121
public ResponseStream<GenerateContentResponse> sendMessageStream(Content content)
115122
throws IOException, IllegalArgumentException {
116123
return sendMessageStream(content, null, null);
@@ -124,6 +131,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(Content content
124131
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
125132
* stream by stream() method.
126133
*/
134+
@BetaApi
127135
public ResponseStream<GenerateContentResponse> sendMessageStream(
128136
Content content, GenerationConfig generationConfig)
129137
throws IOException, IllegalArgumentException {
@@ -138,6 +146,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
138146
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
139147
* stream by stream() method.
140148
*/
149+
@BetaApi("safetySettings is a preview feature.")
141150
public ResponseStream<GenerateContentResponse> sendMessageStream(
142151
Content content, List<SafetySetting> safetySettings)
143152
throws IOException, IllegalArgumentException {
@@ -153,6 +162,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
153162
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
154163
* stream by stream() method.
155164
*/
165+
@BetaApi("safetySettings is a preview feature.")
156166
public ResponseStream<GenerateContentResponse> sendMessageStream(
157167
Content content, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
158168
throws IOException {
@@ -172,6 +182,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
172182
* @param text the message to be sent.
173183
* @return a response.
174184
*/
185+
@BetaApi
175186
public GenerateContentResponse sendMessage(String text) throws IOException {
176187
return sendMessage(text, null, null);
177188
}
@@ -183,6 +194,7 @@ public GenerateContentResponse sendMessage(String text) throws IOException {
183194
* @param generationConfig the generation config.
184195
* @return a response.
185196
*/
197+
@BetaApi
186198
public GenerateContentResponse sendMessage(String text, GenerationConfig generationConfig)
187199
throws IOException {
188200
return sendMessage(text, generationConfig, null);
@@ -195,6 +207,7 @@ public GenerateContentResponse sendMessage(String text, GenerationConfig generat
195207
* @param safetySettings the safety settings.
196208
* @return a response.
197209
*/
210+
@BetaApi("safetySettings is a preview feature.")
198211
public GenerateContentResponse sendMessage(String text, List<SafetySetting> safetySettings)
199212
throws IOException {
200213
return sendMessage(text, null, safetySettings);
@@ -208,6 +221,7 @@ public GenerateContentResponse sendMessage(String text, List<SafetySetting> safe
208221
* @param safetySettings the safety settings.
209222
* @return a response.
210223
*/
224+
@BetaApi("Both sendMessage and safetySettings are preview features.")
211225
public GenerateContentResponse sendMessage(
212226
String text, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
213227
throws IOException {
@@ -227,6 +241,7 @@ public GenerateContentResponse sendMessage(
227241
* @param content the content to be sent.
228242
* @return a response.
229243
*/
244+
@BetaApi
230245
public GenerateContentResponse sendMessage(Content content) throws IOException {
231246
return sendMessage(content, null, null);
232247
}
@@ -238,6 +253,7 @@ public GenerateContentResponse sendMessage(Content content) throws IOException {
238253
* @param generationConfig the generation config.
239254
* @return a response.
240255
*/
256+
@BetaApi
241257
public GenerateContentResponse sendMessage(Content content, GenerationConfig generationConfig)
242258
throws IOException {
243259
return sendMessage(content, generationConfig, null);
@@ -250,6 +266,7 @@ public GenerateContentResponse sendMessage(Content content, GenerationConfig gen
250266
* @param safetySettings the safety settings.
251267
* @return a response.
252268
*/
269+
@BetaApi("Both sendMessage and safetySettings are preview features.")
253270
public GenerateContentResponse sendMessage(Content content, List<SafetySetting> safetySettings)
254271
throws IOException {
255272
return sendMessage(content, null, safetySettings);
@@ -263,6 +280,7 @@ public GenerateContentResponse sendMessage(Content content, List<SafetySetting>
263280
* @param safetySettings the safety settings.
264281
* @return a response.
265282
*/
283+
@BetaApi("Both sendMessage and safetySettings are preview features.")
266284
public GenerateContentResponse sendMessage(
267285
Content content, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
268286
throws IOException {
@@ -326,6 +344,7 @@ private void checkLastResponseAndEditHistory() throws IllegalStateException {
326344
*
327345
* @return an unmodifiable history of the conversation.
328346
*/
347+
@BetaApi
329348
public List<Content> getHistory() {
330349
try {
331350
checkLastResponseAndEditHistory();
@@ -343,6 +362,7 @@ public List<Content> getHistory() {
343362
}
344363

345364
/** Set the history to a list of Content */
365+
@BetaApi
346366
public void setHistory(List<Content> history) {
347367
this.history = history;
348368
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.google.cloud.vertexai.generativeai.preview;
17+
package com.google.cloud.vertexai.generativeai;
1818

1919
import com.google.common.collect.ImmutableSet;
2020

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.google.cloud.vertexai.generativeai.preview;
17+
package com.google.cloud.vertexai.generativeai;
1818

1919
import com.google.cloud.vertexai.api.Content;
2020
import com.google.cloud.vertexai.api.Part;

0 commit comments

Comments
 (0)