diff --git a/ai-catalog/samples/gemini-live-todo/src/main/java/com/android/ai/samples/geminilivetodo/ui/TodoScreenViewModel.kt b/ai-catalog/samples/gemini-live-todo/src/main/java/com/android/ai/samples/geminilivetodo/ui/TodoScreenViewModel.kt index 1e0e83bd..8e05681d 100644 --- a/ai-catalog/samples/gemini-live-todo/src/main/java/com/android/ai/samples/geminilivetodo/ui/TodoScreenViewModel.kt +++ b/ai-catalog/samples/gemini-live-todo/src/main/java/com/android/ai/samples/geminilivetodo/ui/TodoScreenViewModel.kt @@ -94,10 +94,15 @@ class TodoScreenViewModel @Inject constructor(private val todoRepository: TodoRe Manifest.permission.RECORD_AUDIO, ) == PackageManager.PERMISSION_GRANTED ) { + Log.d(TAG, "Start audio conversation") + it.startAudioConversation(::handleFunctionCall) liveSessionState.value = LiveSessionState.Running } } else { + + Log.d(TAG, "Stop audio conversation") + it.stopAudioConversation() liveSessionState.value = LiveSessionState.Ready } @@ -158,8 +163,8 @@ class TodoScreenViewModel @Inject constructor(private val todoRepository: TodoRe emptyMap(), ) - val generativeModel = Firebase.ai(backend = GenerativeBackend.vertexAI()).liveModel( - "gemini-2.0-flash-live-preview-04-09", + val generativeModel = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel( + "gemini-live-2.5-flash-preview", generationConfig = liveGenerationConfig, systemInstruction = systemInstruction, tools = listOf( @@ -181,6 +186,8 @@ class TodoScreenViewModel @Inject constructor(private val todoRepository: TodoRe } private fun handleFunctionCall(functionCall: FunctionCallPart): FunctionResponsePart { + Log.d(TAG, "handleFunctionCall ${functionCall.name}") + return when (functionCall.name) { "getTodoList" -> { val todoList = todoRepository.getTodoList().reversed() @@ -190,7 +197,7 @@ class TodoScreenViewModel @Inject constructor(private val todoRepository: TodoRe "message" to JsonPrimitive("List of tasks in the todo list: $todoList"), ), ) - FunctionResponsePart(functionCall.name, response) + FunctionResponsePart(functionCall.name, response, functionCall.id) } "addTodo" -> { val taskDescription = functionCall.args["taskDescription"]!!.jsonPrimitive.content @@ -201,7 +208,7 @@ class TodoScreenViewModel @Inject constructor(private val todoRepository: TodoRe "message" to JsonPrimitive("Task $taskDescription added to the todo list"), ), ) - FunctionResponsePart(functionCall.name, response) + FunctionResponsePart(functionCall.name, response, functionCall.id) } "removeTodo" -> { val taskId = functionCall.args["todoId"]!!.jsonPrimitive.long @@ -212,7 +219,7 @@ class TodoScreenViewModel @Inject constructor(private val todoRepository: TodoRe "message" to JsonPrimitive("Task was removed from the todo list"), ), ) - FunctionResponsePart(functionCall.name, response) + FunctionResponsePart(functionCall.name, response, functionCall.id) } "toggleTodoStatus" -> { val taskId = functionCall.args["todoId"]!!.jsonPrimitive.long @@ -223,13 +230,13 @@ class TodoScreenViewModel @Inject constructor(private val todoRepository: TodoRe "message" to JsonPrimitive("Task was toggled in the todo list"), ), ) - FunctionResponsePart(functionCall.name, response) + FunctionResponsePart(functionCall.name, response, functionCall.id) } else -> { val response = JsonObject( mapOf("error" to JsonPrimitive("Unknown function: ${functionCall.name}")), ) - FunctionResponsePart(functionCall.name, response) + FunctionResponsePart(functionCall.name, response, functionCall.id) } } }