Skip to content

Commit

Permalink
feat(java): add getChatHistory() to ChatFutures
Browse files Browse the repository at this point in the history
  • Loading branch information
thatfiredev committed Dec 12, 2023
1 parent c2a20e3 commit 5787421
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions generativeai/public.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,21 @@ abstract class ChatFutures internal constructor() {
*/
abstract fun sendMessageStream(prompt: Content): Publisher<GenerateContentResponse>

/**
* Returns the previous interactions with the model
*/
abstract fun getHistory(): ArrayList<Content>

private class FuturesImpl(val chat: Chat) : ChatFutures() {
override fun sendMessage(prompt: Content): ListenableFuture<GenerateContentResponse> =
SuspendToFutureAdapter.launchFuture { chat.sendMessage(prompt) }

override fun sendMessageStream(prompt: Content): Publisher<GenerateContentResponse> =
chat.sendMessageStream(prompt).asPublisher()

override fun getHistory(): ArrayList<Content> {
return ArrayList(chat.history)
}
}

companion object {
Expand Down

0 comments on commit 5787421

Please sign in to comment.