diff --git a/CHANGELOG.md b/CHANGELOG.md index fcc889e..ec80ebc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# 1.0.2 + +- Added new `sendText()` method to support the new RTVI `send-text` event. The method + takes a string, along with an optional set of options to control whether the bot + should respond immediately and/or whether the bot should respond with audio (vs. text only). + Note: This is a replacement for the current `appendToContext()` method. + +- `appendToContext()` has been deprecated in favor of the new `sendText()` method. + # 1.0.1 - Changed content type `startBot()` POST request for compatibility reasons diff --git a/pipecat-client-android/build.gradle.kts b/pipecat-client-android/build.gradle.kts index 4147c77..ae6acd2 100644 --- a/pipecat-client-android/build.gradle.kts +++ b/pipecat-client-android/build.gradle.kts @@ -60,7 +60,7 @@ publishing { register("release") { groupId = "ai.pipecat" artifactId = "client" - version = "1.0.1" + version = "1.0.2" pom { name.set("Pipecat Client") diff --git a/pipecat-client-android/src/main/java/ai/pipecat/client/PipecatClient.kt b/pipecat-client-android/src/main/java/ai/pipecat/client/PipecatClient.kt index bdb4031..199610c 100644 --- a/pipecat-client-android/src/main/java/ai/pipecat/client/PipecatClient.kt +++ b/pipecat-client-android/src/main/java/ai/pipecat/client/PipecatClient.kt @@ -19,6 +19,7 @@ import ai.pipecat.client.types.LLMFunctionCallData import ai.pipecat.client.types.LLMFunctionCallHandler import ai.pipecat.client.types.LLMFunctionCallResult import ai.pipecat.client.types.MediaDeviceId +import ai.pipecat.client.types.SendTextOptions import ai.pipecat.client.types.Transcript import ai.pipecat.client.types.TransportState import ai.pipecat.client.types.Value @@ -393,7 +394,10 @@ open class PipecatClient, ConnectParams * * The context message becomes part of the LLM's memory for the current session and will be * considered when generating future responses. + * + * Note: this method is deprecated. Use sendText() instead. */ + @Deprecated("appendToContext() is deprecated. Use sendText() instead.") fun appendToContext( message: LLMContextMessage ): Future = thread.runOnThreadReturningFuture { @@ -408,6 +412,21 @@ open class PipecatClient, ConnectParams .mapToResult { catchExceptions { JSON_INSTANCE.decodeFromJsonElement(it) } } } + /** + * Appends the specified message to the active conversation with the bot. + * + * The bot's response may be controlled using the values in `SendTextOptions`. + */ + fun sendText( + content: String, + options: SendTextOptions = SendTextOptions() + ): Future { + return sendMessage(MsgClientToServer.SendText( + content = content, + options = options + )) + } + /** * Registers a function call handler for a specific function name. * diff --git a/pipecat-client-android/src/main/java/ai/pipecat/client/transport/MsgClientToServer.kt b/pipecat-client-android/src/main/java/ai/pipecat/client/transport/MsgClientToServer.kt index 97f7b5e..3ad80de 100644 --- a/pipecat-client-android/src/main/java/ai/pipecat/client/transport/MsgClientToServer.kt +++ b/pipecat-client-android/src/main/java/ai/pipecat/client/transport/MsgClientToServer.kt @@ -3,6 +3,7 @@ package ai.pipecat.client.transport import ai.pipecat.client.types.DataMessage import ai.pipecat.client.types.LLMContextMessage import ai.pipecat.client.types.LLMFunctionCallResult +import ai.pipecat.client.types.SendTextOptions import ai.pipecat.client.utils.JSON_INSTANCE import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -39,6 +40,7 @@ data class MsgClientToServer private constructor( const val DisconnectBot = "disconnect-bot" const val ClientMessage = "client-message" const val AppendToContext = "append-to-context" + const val SendText = "send-text" const val LlmFunctionCallResult = "llm-function-call-result" } @@ -58,6 +60,12 @@ data class MsgClientToServer private constructor( @SerialName("platform_version") val platformVersion: String ) + + @Serializable + data class SendText( + val content: String, + val options: SendTextOptions + ) } companion object { @@ -106,6 +114,17 @@ data class MsgClientToServer private constructor( data = JSON_INSTANCE.encodeToJsonElement(LLMContextMessage.serializer(), msg) ) + fun SendText( + content: String, + options: SendTextOptions + ) = MsgClientToServer( + type = Type.SendText, + data = JSON_INSTANCE.encodeToJsonElement(Data.SendText.serializer(), Data.SendText( + content = content, + options = options + )) + ) + fun DisconnectBot() = MsgClientToServer( type = Type.DisconnectBot, data = null diff --git a/pipecat-client-android/src/main/java/ai/pipecat/client/types/SendTextOptions.kt b/pipecat-client-android/src/main/java/ai/pipecat/client/types/SendTextOptions.kt new file mode 100644 index 0000000..6088720 --- /dev/null +++ b/pipecat-client-android/src/main/java/ai/pipecat/client/types/SendTextOptions.kt @@ -0,0 +1,12 @@ +package ai.pipecat.client.types + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class SendTextOptions( + @SerialName("run_immediately") + val runImmediately: Boolean? = null, + @SerialName("audio_response") + val audioResponse: Boolean? = null, +)