Skip to content

Instantly share code, notes, and snippets.

@skydoves
Last active February 5, 2024 02:08
Show Gist options
  • Save skydoves/2c58561dd92a0c8408506d804ec595cc to your computer and use it in GitHub Desktop.
Save skydoves/2c58561dd92a0c8408506d804ec595cc to your computer and use it in GitHub Desktop.
chat_viewmodel
@HiltViewModel
class ChatViewModel @Inject constructor(
repository: ChatRepository,
chatClient: ChatClient,
) : ViewModel() {
private suspend fun sendTextMessage(text: String): String? {
val response = generativeChat.sendMessage(text)
val responseText = response.text
if (responseText != null) {
channelClient.sendMessage(
message = Message(
id = UUID.randomUUID().toString(),
cid = channelClient.cid,
text = responseText,
extraData = mutableMapOf(STREAM_CHANNEL_GEMINI_FLAG to true)
)
).await()
}
return responseText
}
..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment