Skip to content

Commit

Permalink
Align the properties of the vm
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed Nov 7, 2024
1 parent 9e4028d commit bed882c
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,6 @@ class MessagesViewModel @AssistedInject constructor(
},
)

private val events: MutableStateFlow<MessagesEvent> = MutableStateFlow(MessagesEvent.Nothing)
val latestResponse: StateFlow<String?> = events.flatMapLatest { event ->
if (event is MessagesEvent.SendMessage) {
generativeChat.value.sendMessageStream(event.message).map { it.text }
} else {
flowOf("")
}
}.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5000),
initialValue = null,
)

private val generativeChat: StateFlow<Chat> = messages.mapLatest { messageList ->
model.startChat(
history = messageList.map { singleMessage ->
Expand All @@ -105,6 +92,19 @@ class MessagesViewModel @AssistedInject constructor(
initialValue = model.startChat(),
)

private val events: MutableStateFlow<MessagesEvent> = MutableStateFlow(MessagesEvent.Nothing)
val latestResponse: StateFlow<String?> = events.flatMapLatest { event ->
if (event is MessagesEvent.SendMessage) {
generativeChat.value.sendMessageStream(event.message).map { it.text }
} else {
flowOf("")
}
}.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5000),
initialValue = null,
)

fun isCompleted(text: String?): Boolean {
return generativeChat.value.history.any { it.parts.any { it.asTextOrNull() == text } }
}
Expand Down

0 comments on commit bed882c

Please sign in to comment.