Skip to content

Demo updates: add sendCustomMessage(), log onGenericMessage, use gpt-4o-transcribe model #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
accompanistPermissions = "0.34.0"
agp = "8.5.2"
constraintlayoutCompose = "1.0.1"
pipecatClient = "0.3.3"
pipecatClient = "0.3.5"
kotlin = "2.0.20"
coreKtx = "1.13.1"
lifecycleRuntimeKtx = "2.8.6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import ai.pipecat.client.RTVIClient
import ai.pipecat.client.RTVIClientOptions
import ai.pipecat.client.RTVIClientParams
import ai.pipecat.client.RTVIEventCallbacks
import ai.pipecat.client.helper.LLMFunctionCall
import ai.pipecat.client.helper.LLMHelper
import ai.pipecat.client.openai_realtime_webrtc.OpenAIRealtimeSessionConfig
import ai.pipecat.client.openai_realtime_webrtc.OpenAIRealtimeWebRTCTransport
import ai.pipecat.client.result.Future
import ai.pipecat.client.result.RTVIError
import ai.pipecat.client.result.Result
import ai.pipecat.client.transport.MsgClientToServer
import ai.pipecat.client.transport.MsgServerToClient
import ai.pipecat.client.types.ActionDescription
import ai.pipecat.client.types.Participant
Expand All @@ -26,6 +29,7 @@ import androidx.compose.runtime.Stable
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import kotlinx.serialization.json.JsonElement

@Immutable
data class Error(val message: String)
Expand Down Expand Up @@ -65,6 +69,8 @@ class VoiceClientManager(private val context: Context) {

fun start() {

infix fun String.toStr(rhs: String) = this to Value.Str(rhs)

if (client.value != null) {
return
}
Expand All @@ -91,14 +97,26 @@ class VoiceClientManager(private val context: Context) {
)
),*/
initialConfig = OpenAIRealtimeSessionConfig(
turnDetection = Value.Object(
"type" to Value.Str("semantic_vad")
),
inputAudioNoiseReduction = Value.Object(
"type" to Value.Str("near_field")
),
inputAudioTranscription = Value.Object(
"model" to Value.Str("whisper-1")
voice = "ballad",
turnDetection = Value.Object("type" toStr "semantic_vad"),
inputAudioNoiseReduction = Value.Object("type" toStr "near_field"),
inputAudioTranscription = Value.Object("model" toStr "gpt-4o-transcribe"),
tools = Value.Array(
Value.Object(
"type" toStr "function",
"name" toStr "get_current_weather",
"description" toStr "Get the current weather for a given location",
"parameters" to Value.Object(
"type" toStr "object",
"properties" to Value.Object(
"location" to Value.Object(
"type" toStr "string",
"description" toStr "The city and country, eg. San Francisco, USA",
)
),
"required" to Value.Array(Value.Str("location"))
)
)
)
)
)
Expand Down Expand Up @@ -196,10 +214,26 @@ class VoiceClientManager(private val context: Context) {
override fun onRemoteAudioLevel(level: Float, participant: Participant) {
botAudioLevel.floatValue = level
}

override fun onGenericMessage(msg: MsgServerToClient) {
Log.i(TAG, "onGenericMessage: $msg")
}
}

val client = RTVIClient(OpenAIRealtimeWebRTCTransport.Factory(context), callbacks, options)

val llmHelper = LLMHelper(object : LLMHelper.Callbacks() {
override fun onLLMFunctionCall(
func: LLMFunctionCall,
onResult: (Value) -> Unit
) {
Log.i(TAG, "Function call from bot: $func")
onResult(Value.Str("27 degrees celsius, rainy"))
}
})

client.registerHelper("llm", llmHelper)

client.connect().displayErrors().withErrorCallback {
callbacks.onDisconnected()
}
Expand All @@ -216,4 +250,13 @@ class VoiceClientManager(private val context: Context) {
fun stop() {
client.value?.disconnect()?.displayErrors()
}

fun sendCustomMessage(msg: JsonElement) =
client.value?.sendMessage(
MsgClientToServer(
type = "custom-request",
data = msg
)
)

}
Loading