Skip to content
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
third_party/runtime/
!third_party/runtime/CMakeLists.txt
__pycache__/
.pytest_cache/
.pytest_cache/
.venv
32 changes: 26 additions & 6 deletions agents/examples/android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,36 @@ Example Android app demonstrating the Notifications Summarizer Agent integration

## Setup

1. **Add Credentials in Code**
Open `app/src/main/java/dev/deliteai/examples/App.kt` and replace the placeholder values in the `NimbleNetConfig` block (`YOUR_CLIENT_ID`, `YOUR_HOST`, `YOUR_CLIENT_SECRET`) with your own credentials.
1. **Run the following commands**

2. **Open in Android Studio**
**Change to repo root**
```bash
cd deliteAI/agents/examples/android
cd "$(git rev-parse --show-toplevel)"
```

2. **Download Llama ONNX assets**
```bash
python3 coreruntime/tests/utils/download_from_s3.py \
--default_bucket deliteai \
--prefix build-dependencies/llama-3.2-1B/onnx \
--output agents/examples/android/app/src/main/assets/llama-3 \
--archive_output True
```

3. **Generate Python AST and move it into your Android assets**
```bash
coreruntime/scripts/gen_python_ast.py \
agents/notifications_summarizer/delitepyAssets/main.py \
&& mv "${_%.py}.ast" agents/examples/android/app/src/main/assets/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, $_ here may make it difficult for the reader to understand what's going on.

```

4. **Open in Android Studio**
```bash
cd agents/examples/android
```
Open this directory in Android Studio.

3. **Sync and Build**
5. **Sync and Build**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the trailing space in this line intentional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If yes, you can replace the trailing (double space) with a \.

Let Gradle sync, then build the project.

## Running the App
Expand Down Expand Up @@ -54,4 +74,4 @@ App-Wise Summary:
com.whatsapp
Meeting reminder message.
Group chat has 2 new messages.
```
```
23 changes: 14 additions & 9 deletions agents/examples/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ if (propertiesFile.exists()) {
}

android {
signingConfigs {
create("release") {
storeFile = file(localProperties["storeFile"] as String)
storePassword = localProperties["storePassword"] as String
keyPassword = localProperties["keyPassword"] as String
keyAlias = localProperties["keyAlias"] as String
}
}
// TODO: uncomment when building for release
// signingConfigs {
// create("release") {
// storeFile = file(localProperties["storeFile"] as String)
// storePassword = localProperties["storePassword"] as String
// keyPassword = localProperties["keyPassword"] as String
// keyAlias = localProperties["keyAlias"] as String
// }
// }
lint {
disable += "NullSafeMutableLiveData"
}
Expand All @@ -42,6 +43,9 @@ android {
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

// Resolve NimbleNet external flavor for missing dimension
missingDimensionStrategy("default", "external")
}

buildTypes {
Expand All @@ -51,7 +55,8 @@ android {
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
signingConfig = signingConfigs.getByName("release")
// TODO: uncomment when building for release
// signingConfig = signingConfigs.getByName("release")
}
}
compileOptions {
Expand Down
16 changes: 15 additions & 1 deletion agents/examples/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
android:supportsRtl="true"
android:theme="@style/Theme.Examples"
tools:targetApi="31">

<activity
android:name=".MainActivity"
android:exported="true"
Expand All @@ -34,6 +34,20 @@
</intent-filter>
</activity>

<activity
android:name=".NotificationSummarizerActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Examples">
</activity>

<activity
android:name=".GmailActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Examples">
</activity>

<service
android:name="dev.deliteai.notifications_summarizer.impl.notification.NotificationListener"
android:label="Notification Listener"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@

package dev.deliteai.examples

import android.app.Application
import android.util.Log
import dev.deliteai.NimbleNet
import dev.deliteai.datamodels.NimbleNetConfig
import dev.deliteai.impl.common.NIMBLENET_VARIANTS
import dev.deliteai.notifications_summarizer.NotificationsSummarizerAgent
import dev.deliteai.notifications_summarizer.dataModels.NotificationSummarizerConfig
import dev.deliteai.utils.NIMBLENET_VARIANTS
import android.app.Application
import android.util.Log
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.json.JSONArray

class App : Application() {

override fun onCreate() {
super.onCreate()

//Init for notification summarizer must happen from the Application class
val res = initializeAgent(applicationContext as Application)
Log.i("TOP-LEVEL", "onCreate: $res")
}
Expand All @@ -29,23 +31,35 @@ class App : Application() {
return@runBlocking runCatching {
val config = NotificationSummarizerConfig(
onScheduledSummaryReady = { notificationSummary ->
Log.i(HOST_TAG, "initializeAgent: $notificationSummary")
Log.i("AGENTS-EXAMPLE", "initializeAgent: $notificationSummary")
}
)

copyEspeakDataIfNeeded(application, "espeak-ng-data")
val assets: List<Map<String, Any>> = listOf(
mapOf(
"name" to "llama-3",
"version" to "1.0.0",
"type" to "llm",
"location" to mapOf(
"path" to "llama-3"
)
),
mapOf(
"name" to "script",
"version" to "1.0.0",
"type" to "script",
"location" to mapOf(
"path" to "main.ast"
)
)
)

val nimbleConfig = NimbleNetConfig(
clientId = "YOUR_CLIENT_ID",
host = "YOUR_HOST",
deviceId = "test-device",
clientSecret = "YOUR_CLIENT_SECRET",
val nnConfig = NimbleNetConfig(
debug = true,
compatibilityTag = "agent_notification_summarizer",
libraryVariant = NIMBLENET_VARIANTS.STATIC
online = false
)

val res = NimbleNet.initialize(application, nimbleConfig)
val res = NimbleNet.initialize(application, nnConfig, JSONArray(assets))
check(res.status)

while (!NimbleNet.isReady().status) delay(1000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package dev.deliteai.examples.gmail_assistant
package dev.deliteai.examples

import android.accounts.AccountManager
import android.app.Application
Expand Down Expand Up @@ -52,9 +52,8 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext

const val HOST_TAG = "GMAIL_AGENT"

class GmailActivity : ComponentActivity() {
private val HOST_TAG = "GMAIL_AGENT"

private val RC_SIGN_IN = 1001
private val REQUEST_AUTHORIZATION = 1002
Expand Down
Loading