Skip to content

Commit

Permalink
refactor(java): expose chat and generativeModel
Browse files Browse the repository at this point in the history
  • Loading branch information
thatfiredev committed Dec 13, 2023
1 parent e891e0b commit e0d2499
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ abstract class ChatFutures internal constructor() {
*/
abstract fun sendMessageStream(prompt: Content): Publisher<GenerateContentResponse>

/** Returns the previous interactions with the model */
abstract fun getHistory(): ArrayList<Content>
/** Returns the [Chat] instance that was used to create this instance */
abstract fun getChat(): Chat

private class FuturesImpl(val chat: Chat) : ChatFutures() {
private class FuturesImpl(private 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)
override fun getChat(): Chat {
return chat
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ abstract class GenerativeModelFutures internal constructor() {
*/
abstract fun startChat(history: List<Content>): ChatFutures

private class FuturesImpl(val model: GenerativeModel) : GenerativeModelFutures() {
/** Returns the [GenerativeModel] instance that was used to create this object */
abstract fun getGenerativeModel(): GenerativeModel

private class FuturesImpl(private val model: GenerativeModel) : GenerativeModelFutures() {
override fun generateContent(
vararg prompt: Content
): ListenableFuture<GenerateContentResponse> =
Expand All @@ -79,6 +82,10 @@ abstract class GenerativeModelFutures internal constructor() {
override fun startChat(): ChatFutures = startChat(emptyList())

override fun startChat(history: List<Content>): ChatFutures = from(model.startChat(history))

override fun getGenerativeModel(): GenerativeModel {
return model
}
}

companion object {
Expand Down

0 comments on commit e0d2499

Please sign in to comment.