Skip to content

Add LiteRT-LM snippets for the litert-lm skill - #1340

Open
john-rocky wants to merge 4 commits into
android:mainfrom
john-rocky:litert-lm-skill-snippets
Open

john-rocky wants to merge 4 commits into
android:mainfrom
john-rocky:litert-lm-skill-snippets

Conversation

@john-rocky

Copy link
Copy Markdown

Adds Kotlin snippets for the litert-lm skill to the ai module.

Two regions hold code from the skill unchanged, with the imports of that code at the top of LiteRtLmSkillSnippets.kt:

  • android_litert_lm_skill_viewmodel: Step 5's block.
  • android_litert_lm_skill_screen: Step 6's block.

Two regions hold small functions for what the skill describes in its text:

  • android_litert_lm_skill_model_path: returns the absolute path of model.litertlm in the app's filesDir, where the skill's Step 3 puts the file with adb.
  • android_litert_lm_skill_sampler: builds a ConversationConfig with Step 5's system instruction and the SamplerConfig from the text after Step 5's block.

As suggested in the review of #1186, the imports and the dependency lines this PR adds have no region tags. Step 1's Gradle and manifest blocks stay in the skill.

This PR adds com.google.ai.edge.litertlm:litertlm-android 0.20.0 to gradle/libs.versions.toml and ai/build.gradle.kts. My other pull request, #1336, adds its LiteRT dependency lines at the same places in both files. A plain merge of the two branches conflicts in both files. Whichever of the two merges first, I'll update the other one.

Testing

ChatViewModelTest is the litert-lm skill's device test in google-ai-edge/litert-samples. I ported its 20 tests onto the ChatViewModel in LiteRtLmSkillSnippets.kt. I added two tests, one for each small function. On a Pixel 8a, all 22 passed with the CPU backend and again with the GPU backend, using Qwen3-0.6B.litertlm from litert-community/Qwen3-0.6B. The test code is not part of this pull request.

./gradlew :ai:assembleDebug also succeeds on a local merge of this PR and #1336's head commit bcf4a06, with both sets of dependency lines kept.

Two regions hold the code of Step 5 and Step 6 of the litert-lm skill,
unchanged from the skill's SKILL.md in android/skills at commit
7f7b2173, apart from the imports.

Another region holds a small function that returns the absolute path of
model.litertlm in the app's filesDir, where the skill's Step 3 puts the
file with adb.

A fourth region holds a small function that builds a ConversationConfig
with Step 5's system instruction and the SamplerConfig values from the
text after Step 5's block.
@john-rocky
john-rocky requested a review from a team as a code owner November 30, 2026 15:58
@snippet-bot

snippet-bot Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 4 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants