diff --git a/java-vertexai/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/generativeai/ChatSession.java b/java-vertexai/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/generativeai/ChatSession.java index 41df20360c2b..3f4ad24702b6 100644 --- a/java-vertexai/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/generativeai/ChatSession.java +++ b/java-vertexai/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/generativeai/ChatSession.java @@ -92,7 +92,7 @@ public ChatSession withSafetySettings(List safetySettings) { ChatSession rootChat = rootChatSession.orElse(this); ChatSession newChatSession = new ChatSession(model.withSafetySettings(safetySettings), Optional.of(rootChat)); - newChatSession.setHistory(history); + newChatSession.history = history; return newChatSession; } @@ -106,7 +106,7 @@ public ChatSession withSafetySettings(List safetySettings) { public ChatSession withTools(List tools) { ChatSession rootChat = rootChatSession.orElse(this); ChatSession newChatSession = new ChatSession(model.withTools(tools), Optional.of(rootChat)); - newChatSession.setHistory(history); + newChatSession.history = history; return newChatSession; } @@ -253,7 +253,7 @@ private Optional> getCurrentResponseStre /** Set the history to a list of Content */ public void setHistory(List history) { - this.history = history; + this.history = new ArrayList<>(history); } /** Sets the current response of the root chat session (if exists) or the current chat session. */