Skip to content

Commit

Permalink
BREAKING_CHANGE: [vertexai] remove deprecated methods in GenerativeMo…
Browse files Browse the repository at this point in the history
…del and ChatSession (#10560)

PiperOrigin-RevId: 616903374

Co-authored-by: Jaycee Li <jayceeli@google.com>
  • Loading branch information
copybara-service[bot] and jaycee-li authored Mar 19, 2024
1 parent 36307f2 commit c54eaa9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 735 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import com.google.cloud.vertexai.api.Candidate.FinishReason;
import com.google.cloud.vertexai.api.Content;
import com.google.cloud.vertexai.api.GenerateContentResponse;
import com.google.cloud.vertexai.api.GenerationConfig;
import com.google.cloud.vertexai.api.SafetySetting;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -55,7 +53,7 @@ public ChatSession(GenerativeModel model) {
*/
@BetaApi
public ResponseStream<GenerateContentResponse> sendMessageStream(String text) throws IOException {
return sendMessageStream(text, null, null);
return sendMessageStream(text, GenerateContentConfig.newBuilder().build());
}

/**
Expand All @@ -73,64 +71,6 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
return sendMessageStream(ContentMaker.fromString(text), config);
}

/**
* Sends a message to the model and returns a stream of responses.
*
* @param text the message to be sent.
* @param generationConfig the generation config.
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
* stream by stream() method.
* @deprecated use {@link #sendMessageStream(String, GenerateContentConfig)} instead
*/
@BetaApi
@Deprecated
public ResponseStream<GenerateContentResponse> sendMessageStream(
String text, GenerationConfig generationConfig) throws IOException {
return sendMessageStream(text, generationConfig, null);
}

/**
* Sends a message to the model and returns a stream of responses.
*
* @param text the message to be sent.
* @param safetySettings the safety settings.
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
* stream by stream() method.
* @deprecated use {@link #sendMessageStream(String, GenerateContentConfig)} instead
*/
@BetaApi("safetySettings is a preview feature.")
@Deprecated
public ResponseStream<GenerateContentResponse> sendMessageStream(
String text, List<SafetySetting> safetySettings) throws IOException {
return sendMessageStream(text, null, safetySettings);
}

/**
* Sends a message to the model and returns a stream of responses.
*
* @param text the message to be sent.
* @param generationConfig the generation config.
* @param safetySettings the safety settings.
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
* stream by stream() method.
* @deprecated use {@link #sendMessageStream(String, GenerateContentConfig)} instead
*/
@BetaApi("safetySettings is a preview feature.")
@Deprecated
public ResponseStream<GenerateContentResponse> sendMessageStream(
String text, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
throws IOException {
checkLastResponseAndEditHistory();

history.add(ContentMaker.fromString(text));

ResponseStream<GenerateContentResponse> respStream =
model.generateContentStream(history, generationConfig, safetySettings);
currentResponseStream = respStream;
currentResponse = null;
return respStream;
}

/**
* Sends a message to the model and returns a stream of responses.
*
Expand All @@ -141,7 +81,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
@BetaApi
public ResponseStream<GenerateContentResponse> sendMessageStream(Content content)
throws IOException, IllegalArgumentException {
return sendMessageStream(content, null, null);
return sendMessageStream(content, GenerateContentConfig.newBuilder().build());
}

/**
Expand All @@ -165,65 +105,6 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
return respStream;
}

/**
* Sends a message to the model and returns a stream of responses.
*
* @param content the content to be sent.
* @param generationConfig the generation config.
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
* stream by stream() method.
* @deprecated use {@link #sendMessageStream(Content, GenerateContentConfig)} instead
*/
@BetaApi
@Deprecated
public ResponseStream<GenerateContentResponse> sendMessageStream(
Content content, GenerationConfig generationConfig)
throws IOException, IllegalArgumentException {
return sendMessageStream(content, generationConfig, null);
}

/**
* Sends a message to the model and returns a stream of responses.
*
* @param content the content to be sent.
* @param safetySettings the safety settings.
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
* stream by stream() method.
* @deprecated use {@link #sendMessageStream(Content, GenerateContentConfig)} instead
*/
@BetaApi("safetySettings is a preview feature.")
@Deprecated
public ResponseStream<GenerateContentResponse> sendMessageStream(
Content content, List<SafetySetting> safetySettings)
throws IOException, IllegalArgumentException {
return sendMessageStream(content, null, safetySettings);
}

/**
* Sends a message to the model and returns a stream of responses.
*
* @param content the content to be sent.
* @param generationConfig the generation config.
* @param safetySettings the safety settings.
* @return an iterable in which each element is a GenerateContentResponse. Can be converted to
* stream by stream() method.
* @deprecated use {@link #sendMessageStream(Content, GenerateContentConfig)} instead
*/
@BetaApi("safetySettings is a preview feature.")
@Deprecated
public ResponseStream<GenerateContentResponse> sendMessageStream(
Content content, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
throws IOException {
checkLastResponseAndEditHistory();

history.add(content);
ResponseStream<GenerateContentResponse> respStream =
model.generateContentStream(history, generationConfig, safetySettings);
currentResponseStream = respStream;
currentResponse = null;
return respStream;
}

/**
* Sends a message to the model and returns a response.
*
Expand All @@ -232,7 +113,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
*/
@BetaApi
public GenerateContentResponse sendMessage(String text) throws IOException {
return sendMessage(text, null, null);
return sendMessage(text, GenerateContentConfig.newBuilder().build());
}

/**
Expand All @@ -249,60 +130,6 @@ public GenerateContentResponse sendMessage(String text, GenerateContentConfig co
return sendMessage(ContentMaker.fromString(text), config);
}

/**
* Sends a message to the model and returns a response.
*
* @param text the message to be sent.
* @param generationConfig the generation config.
* @return a response.
* @deprecated use {@link #sendMessage(Content, GenerateContentConfig)} instead
*/
@BetaApi
@Deprecated
public GenerateContentResponse sendMessage(String text, GenerationConfig generationConfig)
throws IOException {
return sendMessage(text, generationConfig, null);
}

/**
* Sends a message to the model and returns a response.
*
* @param text the message to be sent.
* @param safetySettings the safety settings.
* @return a response.
* @deprecated use {@link #sendMessage(String, GenerateContentConfig)} instead
*/
@BetaApi("safetySettings is a preview feature.")
@Deprecated
public GenerateContentResponse sendMessage(String text, List<SafetySetting> safetySettings)
throws IOException {
return sendMessage(text, null, safetySettings);
}

/**
* Sends a message to the model and returns a response.
*
* @param text the message to be sent.
* @param generationConfig the generation config.
* @param safetySettings the safety settings.
* @return a response.
* @deprecated use {@link #sendMessage(String, GenerateContentConfig)} instead
*/
@BetaApi("Both sendMessage and safetySettings are preview features.")
@Deprecated
public GenerateContentResponse sendMessage(
String text, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
throws IOException {

checkLastResponseAndEditHistory();
history.add(ContentMaker.fromString(text));
GenerateContentResponse response =
model.generateContent(history, generationConfig, safetySettings);
currentResponse = response;
currentResponseStream = null;
return response;
}

/**
* Sends a message to the model and returns a response.
*
Expand All @@ -311,7 +138,7 @@ public GenerateContentResponse sendMessage(
*/
@BetaApi
public GenerateContentResponse sendMessage(Content content) throws IOException {
return sendMessage(content, null, null);
return sendMessage(content, GenerateContentConfig.newBuilder().build());
}

/**
Expand All @@ -333,59 +160,6 @@ public GenerateContentResponse sendMessage(Content content, GenerateContentConfi
return response;
}

/**
* Sends a message to the model and returns a response.
*
* @param content the content to be sent.
* @param generationConfig the generation config.
* @return a response.
* @deprecated use {@link #sendMessage(Content, GenerateContentConfig)} instead
*/
@BetaApi
@Deprecated
public GenerateContentResponse sendMessage(Content content, GenerationConfig generationConfig)
throws IOException {
return sendMessage(content, generationConfig, null);
}

/**
* Sends a message to the model and returns a response.
*
* @param content the content to be sent.
* @param safetySettings the safety settings.
* @return a response.
* @deprecated use {@link #sendMessage(Content, GenerateContentConfig)} instead
*/
@BetaApi("Both sendMessage and safetySettings are preview features.")
@Deprecated
public GenerateContentResponse sendMessage(Content content, List<SafetySetting> safetySettings)
throws IOException {
return sendMessage(content, null, safetySettings);
}

/**
* Sends a message to the model and returns a response.
*
* @param content the content to be sent.
* @param generationConfig the generation config.
* @param safetySettings the safety settings.
* @return a response.
* @deprecated use {@link #sendMessage(Content, GenerateContentConfig)} instead
*/
@BetaApi("Both sendMessage and safetySettings are preview features.")
@Deprecated
public GenerateContentResponse sendMessage(
Content content, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
throws IOException {
checkLastResponseAndEditHistory();
history.add(content);
GenerateContentResponse response =
model.generateContent(history, generationConfig, safetySettings);
currentResponse = response;
currentResponseStream = null;
return response;
}

private void removeLastContent() {
int lastIndex = history.size() - 1;
history.remove(lastIndex);
Expand Down
Loading

0 comments on commit c54eaa9

Please sign in to comment.