From 567eb7c215f30d924f30e9c1b14262ab513bdc58 Mon Sep 17 00:00:00 2001 From: marcus-daily <111281783+marcus-daily@users.noreply.github.com> Date: Fri, 4 Oct 2024 17:40:57 +0100 Subject: [PATCH 1/3] RTVI 0.2.0 --- .../java/co/daily/bots/demo/MainActivity.kt | 20 ++-- .../co/daily/bots/demo/VoiceClientManager.kt | 104 +++++++++--------- gradle/libs.versions.toml | 14 +-- 3 files changed, 72 insertions(+), 66 deletions(-) diff --git a/daily-bots-android-demo/src/main/java/co/daily/bots/demo/MainActivity.kt b/daily-bots-android-demo/src/main/java/co/daily/bots/demo/MainActivity.kt index d90e655..5bf50ae 100644 --- a/daily-bots-android-demo/src/main/java/co/daily/bots/demo/MainActivity.kt +++ b/daily-bots-android-demo/src/main/java/co/daily/bots/demo/MainActivity.kt @@ -1,13 +1,5 @@ package co.daily.bots.demo -import co.daily.bots.demo.ui.InCallLayout -import co.daily.bots.demo.ui.Logo -import co.daily.bots.demo.ui.PermissionScreen -import co.daily.bots.demo.ui.VoiceClientSettingsPanel -import co.daily.bots.demo.ui.theme.Colors -import co.daily.bots.demo.ui.theme.RTVIClientTheme -import co.daily.bots.demo.ui.theme.TextStyles -import co.daily.bots.demo.ui.theme.textFieldColors import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent @@ -58,9 +50,17 @@ import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import co.daily.bots.demo.ui.InCallLayout +import co.daily.bots.demo.ui.Logo +import co.daily.bots.demo.ui.PermissionScreen +import co.daily.bots.demo.ui.VoiceClientSettingsPanel +import co.daily.bots.demo.ui.theme.Colors +import co.daily.bots.demo.ui.theme.RTVIClientTheme +import co.daily.bots.demo.ui.theme.TextStyles +import co.daily.bots.demo.ui.theme.textFieldColors -private const val DEFAULT_BACKEND = "https://api.daily.co/v1/bots/start" +private const val DEFAULT_BACKEND = "https://api.daily.co/v1/bots" class MainActivity : ComponentActivity() { @@ -91,7 +91,7 @@ class MainActivity : ComponentActivity() { voiceClientManager.errors.firstOrNull()?.let { errorText -> - val dismiss: () -> Unit = { voiceClientManager.errors.removeFirst() } + val dismiss: () -> Unit = { voiceClientManager.errors.removeAt(0) } AlertDialog( onDismissRequest = dismiss, diff --git a/daily-bots-android-demo/src/main/java/co/daily/bots/demo/VoiceClientManager.kt b/daily-bots-android-demo/src/main/java/co/daily/bots/demo/VoiceClientManager.kt index 7aaa313..3147b37 100644 --- a/daily-bots-android-demo/src/main/java/co/daily/bots/demo/VoiceClientManager.kt +++ b/daily-bots-android-demo/src/main/java/co/daily/bots/demo/VoiceClientManager.kt @@ -1,17 +1,18 @@ package co.daily.bots.demo -import ai.rtvi.client.VoiceClient -import ai.rtvi.client.VoiceClientOptions -import ai.rtvi.client.VoiceEventCallbacks -import co.daily.bots.demo.utils.Timestamp +import ai.rtvi.client.RTVIClient +import ai.rtvi.client.RTVIClientOptions +import ai.rtvi.client.RTVIClientParams +import ai.rtvi.client.RTVIEventCallbacks import ai.rtvi.client.daily.DailyVoiceClient import ai.rtvi.client.result.Future +import ai.rtvi.client.result.RTVIError import ai.rtvi.client.result.Result -import ai.rtvi.client.result.VoiceError import ai.rtvi.client.types.ActionDescription import ai.rtvi.client.types.Option import ai.rtvi.client.types.Participant import ai.rtvi.client.types.PipecatMetrics +import ai.rtvi.client.types.RTVIURLEndpoints import ai.rtvi.client.types.ServiceConfig import ai.rtvi.client.types.ServiceRegistration import ai.rtvi.client.types.Tracks @@ -25,6 +26,7 @@ import androidx.compose.runtime.Stable import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateOf +import co.daily.bots.demo.utils.Timestamp @Immutable data class Error(val message: String) @@ -74,14 +76,14 @@ class VoiceClientManager(private val context: Context) { } } - private val client = mutableStateOf(null) + private val client = mutableStateOf(null) val state = mutableStateOf(null) val errors = mutableStateListOf() val actionDescriptions = - mutableStateOf, VoiceError>?>(null) + mutableStateOf, RTVIError>?>(null) val expiryTime = mutableStateOf(null) @@ -95,7 +97,7 @@ class VoiceClientManager(private val context: Context) { val camera = mutableStateOf(false) val tracks = mutableStateOf(null) - private fun Future.displayErrors() = withErrorCallback { + private fun Future.displayErrors() = withErrorCallback { Log.e(TAG, "Future resolved with error: ${it.description}", it.exception) errors.add(Error(it.description)) } @@ -111,54 +113,58 @@ class VoiceClientManager(private val context: Context) { return } - val options = VoiceClientOptions( - services = listOf( - ServiceRegistration("tts", initOptions.ttsProvider.id), - ServiceRegistration("llm", initOptions.llmProvider.id), - ServiceRegistration("stt", initOptions.sttProvider.id), - ), - config = listOf( - ServiceConfig( - "tts", listOf( - Option("voice", runtimeOptions.ttsVoice.id) - ) + val options = RTVIClientOptions( + params = RTVIClientParams( + baseUrl = baseUrl, + endpoints = RTVIURLEndpoints(connect = "/start"), + // Note: For security reasons, don't include your API key in a production + // client app. See: https://docs.dailybots.ai/architecture + headers = apiKey + ?.takeUnless { it.isEmpty() } + ?.let { listOf("Authorization" to "Bearer $it") } + ?: emptyList(), + requestData = listOf( + "bot_profile" to Value.Str(initOptions.botProfile.id), + "max_duration" to Value.Number(600.0) ), - ServiceConfig( - "llm", listOf( - Option("model", runtimeOptions.llmModel.id), - Option( - "initial_messages", Value.Array( - Value.Object( - "role" to Value.Str("system"), - "content" to Value.Str("You are a helpful voice assistant. Keep answers brief, and do not include markdown or other formatting in your responses, as they will be read out using TTS. Please greet the user and offer to assist them.") + config = listOf( + ServiceConfig( + "tts", listOf( + Option("voice", runtimeOptions.ttsVoice.id) + ) + ), + ServiceConfig( + "llm", listOf( + Option("model", runtimeOptions.llmModel.id), + Option( + "initial_messages", Value.Array( + Value.Object( + "role" to Value.Str("system"), + "content" to Value.Str("You are a helpful voice assistant. Keep answers brief, and do not include markdown or other formatting in your responses, as they will be read out using TTS. Please greet the user and offer to assist them.") + ) ) - ) - ), - Option("run_on_config", true), - ) - ), - ServiceConfig( - "stt", listOf( - Option("model", runtimeOptions.sttModel.id), - Option("language", runtimeOptions.sttLanguage.id), + ), + Option("run_on_config", true), + ) + ), + ServiceConfig( + "stt", listOf( + Option("model", runtimeOptions.sttModel.id), + Option("language", runtimeOptions.sttLanguage.id), + ) ) ) ), - // Note: For security reasons, don't include your API key in a production - // client app. See: https://docs.dailybots.ai/architecture - customHeaders = apiKey - ?.takeUnless { it.isEmpty() } - ?.let { listOf("Authorization" to "Bearer $it") } - ?: emptyList(), - customBodyParams = listOf( - "bot_profile" to Value.Str(initOptions.botProfile.id), - "max_duration" to Value.Number(600.0) + services = listOf( + ServiceRegistration("tts", initOptions.ttsProvider.id), + ServiceRegistration("llm", initOptions.llmProvider.id), + ServiceRegistration("stt", initOptions.sttProvider.id), ) ) - state.value = TransportState.Idle + state.value = TransportState.Disconnected - val callbacks = object : VoiceEventCallbacks() { + val callbacks = object : RTVIEventCallbacks() { override fun onTransportStateChanged(state: TransportState) { this@VoiceClientManager.state.value = state } @@ -249,9 +255,9 @@ class VoiceClientManager(private val context: Context) { } } - val client = DailyVoiceClient(context, baseUrl, callbacks, options) + val client = DailyVoiceClient(context, callbacks, options) - client.start().displayErrors().withErrorCallback { + client.connect().displayErrors().withErrorCallback { callbacks.onDisconnected() } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5e71ec4..65f99d4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,15 +1,15 @@ [versions] accompanistPermissions = "0.34.0" -agp = "8.5.1" +agp = "8.5.2" constraintlayoutCompose = "1.0.1" -rtviClientDaily = "0.1.5" -kotlin = "2.0.0" +rtviClientDaily = "0.2.0" +kotlin = "2.0.20" coreKtx = "1.13.1" -lifecycleRuntimeKtx = "2.8.4" -activityCompose = "1.9.1" -composeBom = "2024.06.00" +lifecycleRuntimeKtx = "2.8.6" +activityCompose = "1.9.2" +composeBom = "2024.09.03" kotlinxSerializationJson = "1.7.1" -kotlinxSerializationPlugin = "2.0.0" +kotlinxSerializationPlugin = "2.0.20" [libraries] accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanistPermissions" } From ab3771186ad454b8f2ff59a6c5a3cc6b6454c61d Mon Sep 17 00:00:00 2001 From: marcus-daily <111281783+marcus-daily@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:11:42 +0100 Subject: [PATCH 2/3] Update Daily client to 0.2.1 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 65f99d4..296bd80 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ accompanistPermissions = "0.34.0" agp = "8.5.2" constraintlayoutCompose = "1.0.1" -rtviClientDaily = "0.2.0" +rtviClientDaily = "0.2.1" kotlin = "2.0.20" coreKtx = "1.13.1" lifecycleRuntimeKtx = "2.8.6" From 51f65015576a42ab3e55a8edf0407535e08fcf8d Mon Sep 17 00:00:00 2001 From: marcus-daily <111281783+marcus-daily@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:16:48 +0100 Subject: [PATCH 3/3] Use new bot profile --- .../src/main/java/co/daily/bots/demo/ConfigConstants.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/daily-bots-android-demo/src/main/java/co/daily/bots/demo/ConfigConstants.kt b/daily-bots-android-demo/src/main/java/co/daily/bots/demo/ConfigConstants.kt index 1a90bf4..7c36477 100644 --- a/daily-bots-android-demo/src/main/java/co/daily/bots/demo/ConfigConstants.kt +++ b/daily-bots-android-demo/src/main/java/co/daily/bots/demo/ConfigConstants.kt @@ -127,14 +127,14 @@ object ConfigConstants { listOf( BotProfile( name = "Voice only", - id = "voice_2024_08", + id = "voice_2024_10", llmProviders = NamedOptionList(listOf(Anthropic, Together), default = Together), ttsProviders = NamedOptionList(listOf(Cartesia)), sttProviders = NamedOptionList(listOf(Deepgram)) ), BotProfile( name = "Voice and vision", - id = "vision_2024_08", + id = "vision_2024_10", llmProviders = NamedOptionList(listOf(Anthropic)), ttsProviders = NamedOptionList(listOf(Cartesia)), sttProviders = NamedOptionList(listOf(Deepgram))