-
Notifications
You must be signed in to change notification settings - Fork 19
Create workflow to build Android LeapChat #26
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
Merged
linmx0130
merged 6 commits into
main
from
mengxiaolin/lea-458-prototype-e2e-tests-on-leapsdk-example-apps
Sep 11, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8511282
Create workflow to build Android LeapChat
linmx0130 98650e3
Update Android LeapChat to use new SDK and control tool use
linmx0130 7168285
Add E2E test on Android LeapChat to have two turns of chat
linmx0130 f7cea68
Update LeapChat E2E test and set up CI
linmx0130 8b7dcaf
Update workflow config
linmx0130 29d815e
Fix workflow yml
linmx0130 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| name: Android LeapChat Build | ||
| on: | ||
| push: | ||
| branches: [ main ] | ||
| paths: | ||
| - 'Android/LeapChat/**' | ||
| - '.github/workflows/android-leap-chat-test.yml' | ||
| pull_request: | ||
| branches: [ main ] | ||
| paths: | ||
| - 'Android/LeapChat/**' | ||
| - '.github/workflows/android-leap-chat-test.yml' | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build-and-e2e-test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up JDK 21 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: '21' | ||
| distribution: 'temurin' | ||
| cache: 'gradle' | ||
| - name: Build LeapChat | ||
| run: cd Android/LeapChat && ./gradlew :app:assemble | ||
| - name: Build E2E test | ||
| run: cd Android/LeapChat && ./gradlew :app:assembleAndroidTest | ||
| - name: Run E2E test on Firebase Test Lab | ||
| run: | | ||
| echo "$SERVICE_ACCOUNT" > /tmp/service_account.json | ||
| gcloud auth activate-service-account --key-file=/tmp/service_account.json | ||
| gcloud firebase test android run --type instrumentation \ | ||
| --app Android/LeapChat/app/build/outputs/apk/debug/app-debug.apk \ | ||
| --test Android/LeapChat/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk \ | ||
| --device model=MediumPhone.arm,version=36,locale=en,orientation=portrait \ | ||
| --project liquid-leap | ||
| env: | ||
| SERVICE_ACCOUNT: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }} | ||
|
|
||
66 changes: 66 additions & 0 deletions
66
Android/LeapChat/app/src/androidTest/java/ai/liquid/leapchat/MainActivityTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package ai.liquid.leapchat | ||
|
|
||
| import androidx.compose.ui.test.ExperimentalTestApi | ||
| import androidx.compose.ui.test.assertIsDisplayed | ||
| import androidx.compose.ui.test.assertTextContains | ||
| import androidx.compose.ui.test.hasTestTag | ||
| import androidx.compose.ui.test.hasText | ||
| import androidx.compose.ui.test.isDisplayed | ||
| import androidx.compose.ui.test.junit4.createAndroidComposeRule | ||
| import androidx.compose.ui.test.onAllNodesWithTag | ||
| import androidx.compose.ui.test.performClick | ||
| import androidx.compose.ui.test.performTextInput | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class MainActivityE2EAssetTests { | ||
|
|
||
| @get:Rule | ||
| val composeTestRule = createAndroidComposeRule<MainActivity>() | ||
|
|
||
|
|
||
| @OptIn(ExperimentalTestApi::class) | ||
| @Test | ||
| fun testEndToEndChat() { | ||
| val modelLoadingIndicatorMatcher = hasTestTag("ModelLoadingIndicator") | ||
| val inputBoxMatcher = hasTestTag("InputBox") | ||
| val sendButtonMatcher = hasText("Send") | ||
|
|
||
| // Wait for the model to be downloaded and loaded | ||
| composeTestRule.onNode(modelLoadingIndicatorMatcher).assertIsDisplayed() | ||
| composeTestRule.waitUntilDoesNotExist( | ||
| modelLoadingIndicatorMatcher, | ||
| timeoutMillis = MODEL_LOADING_TIMEOUT | ||
| ) | ||
| composeTestRule.waitUntilAtLeastOneExists(sendButtonMatcher, timeoutMillis = 5000L) | ||
|
|
||
| // Send an input to the model | ||
| composeTestRule.onNode(inputBoxMatcher) | ||
| .performTextInput("How many 'r' are there in the word 'strawberry'?") | ||
| composeTestRule.onNode(sendButtonMatcher).performClick() | ||
| composeTestRule.waitUntilAtLeastOneExists( | ||
| hasTestTag("AssistantMessageView"), | ||
| timeoutMillis = 5000L | ||
| ) | ||
| composeTestRule.waitUntil(timeoutMillis = 5000L) { | ||
| composeTestRule.onNode(hasTestTag("AssistantMessageViewText").and(hasText("strawberry", substring = true))) | ||
| .isDisplayed() | ||
| } | ||
|
|
||
|
|
||
| // Continue the chat with a second prompt | ||
| composeTestRule.onNode(inputBoxMatcher).performTextInput("What about letter 'a'?") | ||
| composeTestRule.onNode(sendButtonMatcher).performClick() | ||
| composeTestRule.waitUntil(timeoutMillis = 5000L) { | ||
| composeTestRule.onAllNodesWithTag("AssistantMessageView") | ||
| .fetchSemanticsNodes().size == 2 | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| const val MODEL_LOADING_TIMEOUT = 5L * 60L * 1000L | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,7 +17,6 @@ import ai.liquid.leap.message.ChatMessageContent | |||||||||||||||||||||||||||||
| import ai.liquid.leap.message.MessageResponse | ||||||||||||||||||||||||||||||
| import ai.liquid.leapchat.models.ChatMessageDisplayItem | ||||||||||||||||||||||||||||||
| import ai.liquid.leapchat.views.ChatHistory | ||||||||||||||||||||||||||||||
| import android.annotation.SuppressLint | ||||||||||||||||||||||||||||||
| import android.os.Bundle | ||||||||||||||||||||||||||||||
| import android.util.Log | ||||||||||||||||||||||||||||||
| import androidx.activity.ComponentActivity | ||||||||||||||||||||||||||||||
|
|
@@ -53,6 +52,7 @@ import androidx.compose.ui.Modifier | |||||||||||||||||||||||||||||
| import androidx.compose.ui.focus.FocusRequester | ||||||||||||||||||||||||||||||
| import androidx.compose.ui.focus.focusRequester | ||||||||||||||||||||||||||||||
| import androidx.compose.ui.platform.LocalContext | ||||||||||||||||||||||||||||||
| import androidx.compose.ui.platform.testTag | ||||||||||||||||||||||||||||||
| import androidx.compose.ui.unit.dp | ||||||||||||||||||||||||||||||
| import androidx.lifecycle.MutableLiveData | ||||||||||||||||||||||||||||||
| import androidx.lifecycle.lifecycleScope | ||||||||||||||||||||||||||||||
|
|
@@ -93,6 +93,10 @@ class MainActivity : ComponentActivity() { | |||||||||||||||||||||||||||||
| MutableLiveData<Boolean>(false) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| private val isToolEnabled: MutableLiveData<Boolean> by lazy { | ||||||||||||||||||||||||||||||
| MutableLiveData<Boolean>(false) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| private val gson = GsonBuilder().registerLeapAdapters().create() | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| override fun onCreate(savedInstanceState: Bundle?) { | ||||||||||||||||||||||||||||||
|
|
@@ -149,23 +153,22 @@ class MainActivity : ComponentActivity() { | |||||||||||||||||||||||||||||
| onValueChange = { userInputFieldText = it }, | ||||||||||||||||||||||||||||||
| modifier = Modifier | ||||||||||||||||||||||||||||||
| .padding(4.dp) | ||||||||||||||||||||||||||||||
| .fillMaxWidth(1.0f), | ||||||||||||||||||||||||||||||
| .fillMaxWidth(1.0f).testTag("InputBox"), | ||||||||||||||||||||||||||||||
| enabled = !isInGeneration.value | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| Row( | ||||||||||||||||||||||||||||||
| horizontalArrangement = Arrangement.End, | ||||||||||||||||||||||||||||||
| modifier = Modifier.fillMaxWidth(1.0f) | ||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||
| Button( | ||||||||||||||||||||||||||||||
| onClick = { | ||||||||||||||||||||||||||||||
| this@MainActivity.isInGeneration.value = true | ||||||||||||||||||||||||||||||
| sendText(userInputFieldText) | ||||||||||||||||||||||||||||||
| userInputFieldText = "" | ||||||||||||||||||||||||||||||
| chatHistoryFocusRequester.requestFocus() | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| enabled = !isInGeneration.value | ||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||
| Text(getString(R.string.send_message_button_label)) | ||||||||||||||||||||||||||||||
| val isToolEnabledState by isToolEnabled.observeAsState(false) | ||||||||||||||||||||||||||||||
| Button(onClick = { | ||||||||||||||||||||||||||||||
| isToolEnabled.value = !isToolEnabledState | ||||||||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||||||||
| if (isToolEnabledState) { | ||||||||||||||||||||||||||||||
| Text(getString(R.string.tool_on_button_label)) | ||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||
| Text(getString(R.string.tool_off_button_label)) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| Button( | ||||||||||||||||||||||||||||||
| onClick = { | ||||||||||||||||||||||||||||||
|
|
@@ -184,6 +187,17 @@ class MainActivity : ComponentActivity() { | |||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||
| Text(getString(R.string.clean_history_button_label)) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| Button( | ||||||||||||||||||||||||||||||
| onClick = { | ||||||||||||||||||||||||||||||
| this@MainActivity.isInGeneration.value = true | ||||||||||||||||||||||||||||||
| sendText(userInputFieldText) | ||||||||||||||||||||||||||||||
| userInputFieldText = "" | ||||||||||||||||||||||||||||||
| chatHistoryFocusRequester.requestFocus() | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| enabled = !isInGeneration.value | ||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||
| Text(getString(R.string.send_message_button_label)) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
@@ -359,20 +373,21 @@ class MainActivity : ComponentActivity() { | |||||||||||||||||||||||||||||
| conversationInstance | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| conversation.registerFunction( | ||||||||||||||||||||||||||||||
| LeapFunction( | ||||||||||||||||||||||||||||||
| "compute_sum", "Compute sum of a series of numbers", listOf( | ||||||||||||||||||||||||||||||
| LeapFunctionParameter( | ||||||||||||||||||||||||||||||
| name = "values", | ||||||||||||||||||||||||||||||
| type = LeapFunctionParameterType.Array( | ||||||||||||||||||||||||||||||
| itemType = LeapFunctionParameterType.String() | ||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||
| description = "Numbers to compute sum. Values should be represented in string." | ||||||||||||||||||||||||||||||
| if (isToolEnabled.value == true) { | ||||||||||||||||||||||||||||||
| conversation.registerFunction( | ||||||||||||||||||||||||||||||
| LeapFunction( | ||||||||||||||||||||||||||||||
| "compute_sum", "Compute sum of a series of numbers", listOf( | ||||||||||||||||||||||||||||||
| LeapFunctionParameter( | ||||||||||||||||||||||||||||||
| name = "values", | ||||||||||||||||||||||||||||||
| type = LeapFunctionParameterType.Array( | ||||||||||||||||||||||||||||||
| itemType = LeapFunctionParameterType.String() | ||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||
| description = "Numbers to compute sum. Values should be represented in string." | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| return conversation | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
@@ -455,8 +470,8 @@ class MainActivity : ComponentActivity() { | |||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| companion object { | ||||||||||||||||||||||||||||||
| const val MODEL_SLUG = "lfm2-1.2b" | ||||||||||||||||||||||||||||||
| const val QUANTIZATION_SLUG = "lfm2-1.2b-20250710-8da4w" | ||||||||||||||||||||||||||||||
| const val MODEL_SLUG = "lfm2-350m" | ||||||||||||||||||||||||||||||
| const val QUANTIZATION_SLUG = "lfm2-350m-20250710-8da4w" | ||||||||||||||||||||||||||||||
|
Comment on lines
+473
to
+474
|
||||||||||||||||||||||||||||||
| const val MODEL_SLUG = "lfm2-350m" | |
| const val QUANTIZATION_SLUG = "lfm2-350m-20250710-8da4w" | |
| /** | |
| * Model slug for LeapChat. Default is "lfm2-350m" (350M parameters). | |
| * Note: Switching from a larger model (e.g., "lfm2-1.2b") to "lfm2-350m" reduces resource usage | |
| * but may impact language understanding and generation quality. Ensure this aligns with your application's needs. | |
| * To use a different model, set the value via configuration or environment variable if supported. | |
| */ | |
| val MODEL_SLUG: String = System.getenv("LEAPCHAT_MODEL_SLUG") ?: "lfm2-350m" | |
| /** | |
| * Quantization slug for the selected model. | |
| * Update this value if you change the model slug. | |
| */ | |
| val QUANTIZATION_SLUG: String = System.getenv("LEAPCHAT_QUANTIZATION_SLUG") ?: "lfm2-350m-20250710-8da4w" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The service account key is written to a temporary file without proper cleanup. Consider using stdin for authentication or ensure the file is securely deleted after use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary as the environment will be cleaned up by Github Action runners.