Skip to content

Commit

Permalink
Allow selection of bot profile
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-daily committed Aug 30, 2024
1 parent f84df8b commit ed449a9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,22 @@ object ConfigConstants {
val llmProviders = NamedOptionList<LLMProvider>(listOf(Anthropic, Together), default = Together)

val ttsProviders = NamedOptionList<TTSProvider>(listOf(Cartesia))

val botProfiles = NamedOptionList(
listOf(
"Voice only" isProfile "voice_2024_08",
"Voice and vision" isProfile "vision_2024_08"
)
)
}

@Immutable
data class NamedOptionList<E : NamedOption>(
val options: List<E>,
val default: E = options.first()
) {
fun byIdOrDefault(id: String) = options.firstOrNull { it.id == id } ?: default
fun byIdOrDefault(id: String?) =
id?.let { idNonNull -> options.firstOrNull { it.id == idNonNull } } ?: default
}

interface NamedOption {
Expand All @@ -76,6 +84,11 @@ interface LLMProvider : NamedOption {
val models: NamedOptionList<LLMOptionModel>
}

data class BotProfile(
override val name: String,
override val id: String,
) : NamedOption

data class LLMOptionModel(
override val name: String,
override val id: String,
Expand All @@ -87,4 +100,5 @@ data class TTSOptionVoice(
) : NamedOption

private infix fun String.isModel(id: String) = LLMOptionModel(name = this, id = id)
private infix fun String.isVoice(id: String) = TTSOptionVoice(name = this, id = id)
private infix fun String.isVoice(id: String) = TTSOptionVoice(name = this, id = id)
private infix fun String.isProfile(id: String) = BotProfile(name = this, id = id)
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ object Preferences {

@Serializable
data class LastInitOptions(
val ttsProvider: String,
val ttsVoice: String,
val llmProvider: String,
val llmModel: String,
val botProfile: String? = null,
val ttsProvider: String? = null,
val ttsVoice: String? = null,
val llmProvider: String? = null,
val llmModel: String? = null,
) {
companion object {
fun from(initOptions: VoiceClientManager.InitOptions, runtimeOptions: VoiceClientManager.RuntimeOptions) = LastInitOptions(
botProfile = initOptions.botProfile.id,
ttsProvider = initOptions.ttsProvider.id,
ttsVoice = runtimeOptions.ttsVoice.id,
llmProvider = initOptions.llmProvider.id,
Expand All @@ -96,6 +98,7 @@ data class LastInitOptions(
}

fun inflateInit() = VoiceClientManager.InitOptions(
botProfile = ConfigConstants.botProfiles.byIdOrDefault(botProfile),
ttsProvider = ConfigConstants.ttsProviders.byIdOrDefault(ttsProvider),
llmProvider = ConfigConstants.llmProviders.byIdOrDefault(llmProvider),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ class VoiceClientManager(private val context: Context) {

@Immutable
data class InitOptions(
val botProfile: BotProfile,
val ttsProvider: TTSProvider,
val llmProvider: LLMProvider,
) {
companion object {
fun default() = InitOptions(
botProfile = ConfigConstants.botProfiles.default,
ttsProvider = ConfigConstants.ttsProviders.default,
llmProvider = ConfigConstants.llmProviders.default,
)
Expand Down Expand Up @@ -117,7 +119,7 @@ class VoiceClientManager(private val context: Context) {
"initial_messages", Value.Array(
Value.Object(
"role" to Value.Str("system"),
"content" to Value.Str("You are a helpful voice assistant. 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.")
"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.")
)
)
),
Expand All @@ -132,7 +134,7 @@ class VoiceClientManager(private val context: Context) {
?.let { listOf("Authorization" to "Bearer $it") }
?: emptyList(),
customBodyParams = listOf(
"bot_profile" to Value.Str("voice_2024_08"),
"bot_profile" to Value.Str(initOptions.botProfile.id),
"max_duration" to Value.Number(600.0)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ fun VoiceClientSettingsPanel(
.verticalScroll(scrollState)
.padding(horizontal = 20.dp)
) {
RadioGroup(
label = "Bot Profile",
onSelect = { updatePref { copy(botProfile = it.id) } },
selected = initOptions.botProfile,
options = ConfigConstants.botProfiles,
)

Header("Text to Speech")

Expand Down

0 comments on commit ed449a9

Please sign in to comment.