From 5787421410e280bb590fc44d3d83a55c25067f45 Mon Sep 17 00:00:00 2001 From: rosariopf Date: Tue, 12 Dec 2023 22:29:42 +0000 Subject: [PATCH] feat(java): add getChatHistory() to ChatFutures --- generativeai/public.api | 1 + .../google/ai/client/generativeai/java/ChatFutures.kt | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/generativeai/public.api b/generativeai/public.api index 384f51c0..9c3f3d19 100644 --- a/generativeai/public.api +++ b/generativeai/public.api @@ -35,6 +35,7 @@ public final class com/google/ai/client/generativeai/GenerativeModel { public abstract class com/google/ai/client/generativeai/java/ChatFutures { public static final field Companion Lcom/google/ai/client/generativeai/java/ChatFutures$Companion; public static final fun from (Lcom/google/ai/client/generativeai/Chat;)Lcom/google/ai/client/generativeai/java/ChatFutures; + public abstract fun getHistory ()Ljava/util/ArrayList; public abstract fun sendMessage (Lcom/google/ai/client/generativeai/type/Content;)Lcom/google/common/util/concurrent/ListenableFuture; public abstract fun sendMessageStream (Lcom/google/ai/client/generativeai/type/Content;)Lorg/reactivestreams/Publisher; } diff --git a/generativeai/src/main/java/com/google/ai/client/generativeai/java/ChatFutures.kt b/generativeai/src/main/java/com/google/ai/client/generativeai/java/ChatFutures.kt index 615f9cbd..ef4b42e0 100644 --- a/generativeai/src/main/java/com/google/ai/client/generativeai/java/ChatFutures.kt +++ b/generativeai/src/main/java/com/google/ai/client/generativeai/java/ChatFutures.kt @@ -46,12 +46,21 @@ abstract class ChatFutures internal constructor() { */ abstract fun sendMessageStream(prompt: Content): Publisher + /** + * Returns the previous interactions with the model + */ + abstract fun getHistory(): ArrayList + private class FuturesImpl(val chat: Chat) : ChatFutures() { override fun sendMessage(prompt: Content): ListenableFuture = SuspendToFutureAdapter.launchFuture { chat.sendMessage(prompt) } override fun sendMessageStream(prompt: Content): Publisher = chat.sendMessageStream(prompt).asPublisher() + + override fun getHistory(): ArrayList { + return ArrayList(chat.history) + } } companion object {