Skip to content

Commit

Permalink
BREAKING CHANGE: [vertexai] remove namespace 'preview' and use @BetaApi.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 604637135
  • Loading branch information
Zhenyi Qi authored and copybara-github committed Feb 6, 2024
1 parent e83701b commit 29e0875
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.cloud.vertexai.api.PredictionServiceSettings;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -60,16 +61,38 @@ public class VertexAI implements AutoCloseable {
private LlmUtilityServiceClient llmUtilityRestClient = null;

/**
* Construct a VertexAI instance with custom credentials.
* Construct a VertexAI instance.
*
* @param projectId the default project to use when making API calls
* @param location the default location to use when making API calls
* @param credentials the custom credentials to use when making API calls
*/
public VertexAI(String projectId, String location, Credentials credentials) {
public VertexAI(String projectId, String location) {
this.projectId = projectId;
this.location = location;
this.apiEndpoint = String.format("%s-aiplatform.googleapis.com", this.location);
}

/**
* Construct a VertexAI instance with default transport layer.
*
* @param projectId the default project to use when making API calls
* @param location the default location to use when making API calls
* @param transport the default {@link Transport} layer to use to send API requests
*/
public VertexAI(String projectId, String location, Transport transport) {
this(projectId, location);
this.transport = transport;
}

/**
* Construct a VertexAI instance with custom credentials.
*
* @param projectId the default project to use when making API calls
* @param location the default location to use when making API calls
* @param credentials the custom credentials to use when making API calls
*/
public VertexAI(String projectId, String location, Credentials credentials) {
this(projectId, location);
this.credentialsProvider = FixedCredentialsProvider.create(credentials);
}

Expand All @@ -91,9 +114,47 @@ public VertexAI(String projectId, String location, Transport transport, Credenti
*
* @param projectId the default project to use when making API calls
* @param location the default location to use when making API calls
* @param scopes List of scopes in the default credentials. Make sure you have specified
* "https://www.googleapis.com/auth/cloud-platform" scope to access resources on Vertex AI.
*/
public VertexAI(String projectId, String location, List<String> scopes) throws IOException {
this(projectId, location);

CredentialsProvider credentialsProvider =
scopes.size() == 0
? null
: GoogleCredentialsProvider.newBuilder()
.setScopesToApply(scopes)
.setUseJwtAccessWithScope(true)
.build();
this.credentialsProvider = credentialsProvider;
}

/**
* Construct a VertexAI instance with default transport layer and application default credentials.
*
* @param projectId the default project to use when making API calls
* @param location the default location to use when making API calls
* @param transport the default {@link Transport} layer to use to send API requests
* @param scopes List of scopes in the default credentials. Make sure you have specified
* "https://www.googleapis.com/auth/cloud-platform" scope to access resources on Vertex AI.
*/
public VertexAI(String projectId, String location, Transport transport, List<String> scopes)
throws IOException {
this(projectId, location, scopes);
this.transport = transport;
}

/**
* Construct a VertexAI instance with application default credentials.
*
* @deprecated Use {@link #VertexAI(String, String, List<String>)} instead.
* @param projectId the default project to use when making API calls
* @param location the default location to use when making API calls
* @param scopes collection of scopes in the default credentials. Make sure you have specified
* "https://www.googleapis.com/auth/cloud-platform" scope to access resources on Vertex AI.
*/
@Deprecated
public VertexAI(String projectId, String location, String... scopes) throws IOException {
CredentialsProvider credentialsProvider =
scopes.length == 0
Expand All @@ -112,11 +173,13 @@ public VertexAI(String projectId, String location, String... scopes) throws IOEx
/**
* Construct a VertexAI instance with default transport layer and application default credentials.
*
* @deprecated Use {@link #VertexAI(String, String, Transport, List<String>)} instead.
* @param projectId the default project to use when making API calls
* @param location the default location to use when making API calls
* @param transport the default {@link Transport} layer to use to send API requests
* @param scopes collection of scopes in the default credentials
*/
@Deprecated
public VertexAI(String projectId, String location, Transport transport, String... scopes)
throws IOException {
this(projectId, location, scopes);
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 Down Expand Up @@ -51,6 +52,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 +65,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 +79,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(
String text, List<SafetySetting> safetySettings) throws IOException {
return sendMessageStream(text, null, safetySettings);
Expand All @@ -90,6 +94,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(
String text, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
throws IOException {
Expand All @@ -111,6 +116,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 +130,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 +145,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, List<SafetySetting> safetySettings)
throws IOException, IllegalArgumentException {
Expand All @@ -153,6 +161,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, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
throws IOException {
Expand All @@ -172,6 +181,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 +193,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 +206,7 @@ public GenerateContentResponse sendMessage(String text, GenerationConfig generat
* @param safetySettings the safety settings.
* @return a response.
*/
@BetaApi
public GenerateContentResponse sendMessage(String text, List<SafetySetting> safetySettings)
throws IOException {
return sendMessage(text, null, safetySettings);
Expand All @@ -208,6 +220,7 @@ public GenerateContentResponse sendMessage(String text, List<SafetySetting> safe
* @param safetySettings the safety settings.
* @return a response.
*/
@BetaApi
public GenerateContentResponse sendMessage(
String text, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
throws IOException {
Expand All @@ -227,6 +240,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 +252,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 +265,7 @@ public GenerateContentResponse sendMessage(Content content, GenerationConfig gen
* @param safetySettings the safety settings.
* @return a response.
*/
@BetaApi
public GenerateContentResponse sendMessage(Content content, List<SafetySetting> safetySettings)
throws IOException {
return sendMessage(content, null, safetySettings);
Expand All @@ -263,6 +279,7 @@ public GenerateContentResponse sendMessage(Content content, List<SafetySetting>
* @param safetySettings the safety settings.
* @return a response.
*/
@BetaApi
public GenerateContentResponse sendMessage(
Content content, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
throws IOException {
Expand Down Expand Up @@ -326,6 +343,7 @@ private void checkLastResponseAndEditHistory() throws IllegalStateException {
*
* @return an unmodifiable history of the conversation.
*/
@BetaApi
public List<Content> getHistory() {
try {
checkLastResponseAndEditHistory();
Expand All @@ -343,6 +361,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 29e0875

Please sign in to comment.