From bed882c6632acb9795f06ecf1763610018464e05 Mon Sep 17 00:00:00 2001 From: skydoves Date: Thu, 7 Nov 2024 15:50:46 +0900 Subject: [PATCH] Align the properties of the vm --- .../feature/messages/MessagesViewModel.kt | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/feature/messages/src/main/kotlin/io/getstream/ai/chat/feature/messages/MessagesViewModel.kt b/feature/messages/src/main/kotlin/io/getstream/ai/chat/feature/messages/MessagesViewModel.kt index 45e5d56..1f5b399 100644 --- a/feature/messages/src/main/kotlin/io/getstream/ai/chat/feature/messages/MessagesViewModel.kt +++ b/feature/messages/src/main/kotlin/io/getstream/ai/chat/feature/messages/MessagesViewModel.kt @@ -78,19 +78,6 @@ class MessagesViewModel @AssistedInject constructor( }, ) - private val events: MutableStateFlow = MutableStateFlow(MessagesEvent.Nothing) - val latestResponse: StateFlow = 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 = messages.mapLatest { messageList -> model.startChat( history = messageList.map { singleMessage -> @@ -105,6 +92,19 @@ class MessagesViewModel @AssistedInject constructor( initialValue = model.startChat(), ) + private val events: MutableStateFlow = MutableStateFlow(MessagesEvent.Nothing) + val latestResponse: StateFlow = 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 } } }