Skip to content

Commit

Permalink
feat: [vertexai] Remove 'preview' namespace and start using @BetaApi (#…
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
copybara-service[bot] and Zhenyi Qi authored Feb 8, 2024
1 parent 5b5bff4 commit 29b2a36
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 34 deletions.
38 changes: 19 additions & 19 deletions java-vertexai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Vertex AI SDK allows you to access the service programmatically. The following c
package <your package name>

import com.google.cloud.vertexai.VertexAI;
import com.google.cloud.vertexai.generativeai.preview.GenerativeModel;
import com.google.cloud.vertexai.generativeai.GenerativeModel;
import com.google.cloud.vertexai.api.GenerateContentResponse;
import java.io.IOException;

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

import com.google.cloud.vertexai.VertexAI;
import com.google.cloud.vertexai.generativeai.preview.GenerativeModel;
import com.google.cloud.vertexai.generativeai.preview.ResponseStream;
import com.google.cloud.vertexai.generativeai.GenerativeModel;
import com.google.cloud.vertexai.generativeai.ResponseStream;
import com.google.cloud.vertexai.api.GenerateContentResponse;
import java.io.IOException;

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

import com.google.cloud.vertexai.VertexAI;
import com.google.cloud.vertexai.generativeai.preview.GenerativeModel;
import com.google.cloud.vertexai.generativeai.preview.ResponseStream;
import com.google.cloud.vertexai.generativeai.preview.ContentMaker;
import com.google.cloud.vertexai.generativeai.preview.PartMaker;
import com.google.cloud.vertexai.generativeai.GenerativeModel;
import com.google.cloud.vertexai.generativeai.ResponseStream;
import com.google.cloud.vertexai.generativeai.ContentMaker;
import com.google.cloud.vertexai.generativeai.PartMaker;
import com.google.cloud.vertexai.api.GenerateContentResponse;
import java.util.Arrays;

Expand Down Expand Up @@ -188,9 +188,9 @@ package <your package name>;
import com.google.cloud.vertexai.VertexAI;
import com.google.cloud.vertexai.api.Content;
import com.google.cloud.vertexai.api.GenerateContentResponse;
import com.google.cloud.vertexai.generativeai.preview.ContentMaker;
import com.google.cloud.vertexai.generativeai.preview.GenerativeModel;
import com.google.cloud.vertexai.generativeai.preview.ResponseHandler;
import com.google.cloud.vertexai.generativeai.ContentMaker;
import com.google.cloud.vertexai.generativeai.GenerativeModel;
import com.google.cloud.vertexai.generativeai.ResponseHandler;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -233,9 +233,9 @@ Yeah, we know, that isn't the most intuitive and easy way to chat with a model.
package <your package name>;
import com.google.cloud.vertexai.VertexAI;
import com.google.cloud.vertexai.generativeai.preview.GenerativeModel;
import com.google.cloud.vertexai.generativeai.preview.ChatSession;
import com.google.cloud.vertexai.generativeai.preview.ResponseStream;
import com.google.cloud.vertexai.generativeai.GenerativeModel;
import com.google.cloud.vertexai.generativeai.ChatSession;
import com.google.cloud.vertexai.generativeai.ResponseStream;
import com.google.cloud.vertexai.api.GenerateContentResponse;
import com.google.cloud.vertexai.api.GenerationConfig;
import java.io.IOException;
Expand Down Expand Up @@ -278,10 +278,10 @@ In a chat, we can also do function calling.
```java
package <your package name>;
import com.google.cloud.vertexai.VertexAI;
import com.google.cloud.vertexai.generativeai.preview.ChatSession;
import com.google.cloud.vertexai.generativeai.preview.GenerativeModel;
import com.google.cloud.vertexai.generativeai.preview.ResponseHandler;
import com.google.cloud.vertexai.generativeai.preview.ResponseStream;
import com.google.cloud.vertexai.generativeai.ChatSession;
import com.google.cloud.vertexai.generativeai.GenerativeModel;
import com.google.cloud.vertexai.generativeai.ResponseHandler;
import com.google.cloud.vertexai.generativeai.ResponseStream;
import com.google.cloud.vertexai.api.Content;
import com.google.cloud.vertexai.api.GenerateContentResponse;
import java.io.IOException;
Expand Down Expand Up @@ -369,8 +369,8 @@ Vertex AI uses gRPC and rest for the transport layer. By default, we use gRPC tr
package <your package name>

import com.google.cloud.vertexai.VertexAI;
import com.google.cloud.vertexai.generativeai.preview.GenerativeModel;
import com.google.cloud.vertexai.generativeai.preview.Transport;
import com.google.cloud.vertexai.generativeai.GenerativeModel;
import com.google.cloud.vertexai.generativeai.Transport;
import com.google.cloud.vertexai.api.GenerateContentResponse;
import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

package com.google.cloud.vertexai.generativeai.preview;
package com.google.cloud.vertexai.generativeai;

import static com.google.cloud.vertexai.generativeai.preview.ResponseHandler.aggregateStreamIntoResponse;
import static com.google.cloud.vertexai.generativeai.preview.ResponseHandler.getContent;
import static com.google.cloud.vertexai.generativeai.preview.ResponseHandler.getFinishReason;
import static com.google.cloud.vertexai.generativeai.ResponseHandler.aggregateStreamIntoResponse;
import static com.google.cloud.vertexai.generativeai.ResponseHandler.getContent;
import static com.google.cloud.vertexai.generativeai.ResponseHandler.getFinishReason;

import com.google.api.core.BetaApi;
import com.google.cloud.vertexai.api.Candidate.FinishReason;
import com.google.cloud.vertexai.api.Content;
import com.google.cloud.vertexai.api.GenerateContentResponse;
Expand All @@ -37,6 +38,7 @@ public class ChatSession {
private ResponseStream<GenerateContentResponse> currentResponseStream = null;
private GenerateContentResponse currentResponse = null;

@BetaApi
public ChatSession(GenerativeModel model) {
if (model == null) {
throw new IllegalArgumentException("model should not be null");
Expand All @@ -51,6 +53,7 @@ public ChatSession(GenerativeModel model) {
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
* stream by stream() method.
*/
@BetaApi
public ResponseStream<GenerateContentResponse> sendMessageStream(String text) throws IOException {
return sendMessageStream(text, null, null);
}
Expand All @@ -63,6 +66,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(String text) th
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
* stream by stream() method.
*/
@BetaApi
public ResponseStream<GenerateContentResponse> sendMessageStream(
String text, GenerationConfig generationConfig) throws IOException {
return sendMessageStream(text, generationConfig, null);
Expand All @@ -76,6 +80,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
* stream by stream() method.
*/
@BetaApi("safetySettings is a preview feature.")
public ResponseStream<GenerateContentResponse> sendMessageStream(
String text, List<SafetySetting> safetySettings) throws IOException {
return sendMessageStream(text, null, safetySettings);
Expand All @@ -90,6 +95,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
* stream by stream() method.
*/
@BetaApi("safetySettings is a preview feature.")
public ResponseStream<GenerateContentResponse> sendMessageStream(
String text, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
throws IOException {
Expand All @@ -111,6 +117,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
* stream by stream() method.
*/
@BetaApi
public ResponseStream<GenerateContentResponse> sendMessageStream(Content content)
throws IOException, IllegalArgumentException {
return sendMessageStream(content, null, null);
Expand All @@ -124,6 +131,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(Content content
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
* stream by stream() method.
*/
@BetaApi
public ResponseStream<GenerateContentResponse> sendMessageStream(
Content content, GenerationConfig generationConfig)
throws IOException, IllegalArgumentException {
Expand All @@ -138,6 +146,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
* stream by stream() method.
*/
@BetaApi("safetySettings is a preview feature.")
public ResponseStream<GenerateContentResponse> sendMessageStream(
Content content, List<SafetySetting> safetySettings)
throws IOException, IllegalArgumentException {
Expand All @@ -153,6 +162,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
* stream by stream() method.
*/
@BetaApi("safetySettings is a preview feature.")
public ResponseStream<GenerateContentResponse> sendMessageStream(
Content content, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
throws IOException {
Expand All @@ -172,6 +182,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
* @param text the message to be sent.
* @return a response.
*/
@BetaApi
public GenerateContentResponse sendMessage(String text) throws IOException {
return sendMessage(text, null, null);
}
Expand All @@ -183,6 +194,7 @@ public GenerateContentResponse sendMessage(String text) throws IOException {
* @param generationConfig the generation config.
* @return a response.
*/
@BetaApi
public GenerateContentResponse sendMessage(String text, GenerationConfig generationConfig)
throws IOException {
return sendMessage(text, generationConfig, null);
Expand All @@ -195,6 +207,7 @@ public GenerateContentResponse sendMessage(String text, GenerationConfig generat
* @param safetySettings the safety settings.
* @return a response.
*/
@BetaApi("safetySettings is a preview feature.")
public GenerateContentResponse sendMessage(String text, List<SafetySetting> safetySettings)
throws IOException {
return sendMessage(text, null, safetySettings);
Expand All @@ -208,6 +221,7 @@ public GenerateContentResponse sendMessage(String text, List<SafetySetting> safe
* @param safetySettings the safety settings.
* @return a response.
*/
@BetaApi("Both sendMessage and safetySettings are preview features.")
public GenerateContentResponse sendMessage(
String text, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
throws IOException {
Expand All @@ -227,6 +241,7 @@ public GenerateContentResponse sendMessage(
* @param content the content to be sent.
* @return a response.
*/
@BetaApi
public GenerateContentResponse sendMessage(Content content) throws IOException {
return sendMessage(content, null, null);
}
Expand All @@ -238,6 +253,7 @@ public GenerateContentResponse sendMessage(Content content) throws IOException {
* @param generationConfig the generation config.
* @return a response.
*/
@BetaApi
public GenerateContentResponse sendMessage(Content content, GenerationConfig generationConfig)
throws IOException {
return sendMessage(content, generationConfig, null);
Expand All @@ -250,6 +266,7 @@ public GenerateContentResponse sendMessage(Content content, GenerationConfig gen
* @param safetySettings the safety settings.
* @return a response.
*/
@BetaApi("Both sendMessage and safetySettings are preview features.")
public GenerateContentResponse sendMessage(Content content, List<SafetySetting> safetySettings)
throws IOException {
return sendMessage(content, null, safetySettings);
Expand All @@ -263,6 +280,7 @@ public GenerateContentResponse sendMessage(Content content, List<SafetySetting>
* @param safetySettings the safety settings.
* @return a response.
*/
@BetaApi("Both sendMessage and safetySettings are preview features.")
public GenerateContentResponse sendMessage(
Content content, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
throws IOException {
Expand Down Expand Up @@ -326,6 +344,7 @@ private void checkLastResponseAndEditHistory() throws IllegalStateException {
*
* @return an unmodifiable history of the conversation.
*/
@BetaApi
public List<Content> getHistory() {
try {
checkLastResponseAndEditHistory();
Expand All @@ -343,6 +362,7 @@ public List<Content> getHistory() {
}

/** Set the history to a list of Content */
@BetaApi
public void setHistory(List<Content> history) {
this.history = history;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.google.cloud.vertexai.generativeai.preview;
package com.google.cloud.vertexai.generativeai;

import com.google.common.collect.ImmutableSet;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.google.cloud.vertexai.generativeai.preview;
package com.google.cloud.vertexai.generativeai;

import com.google.cloud.vertexai.api.Content;
import com.google.cloud.vertexai.api.Part;
Expand Down
Loading

0 comments on commit 29b2a36

Please sign in to comment.