From 3e3e35a5c1184a486f904858f3647c9313bd5b23 Mon Sep 17 00:00:00 2001 From: "copybara-service[bot]" <56741989+copybara-service[bot]@users.noreply.github.com> Date: Fri, 22 Mar 2024 12:16:11 -0700 Subject: [PATCH] fix: [vertexai] make a copy of the list in `ChatSession.setHistory()` (#10608) PiperOrigin-RevId: 618209294 Co-authored-by: Jaycee Li --- .../com/google/cloud/vertexai/generativeai/ChatSession.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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. */