Initial commit: HeliBoard + Gemma 4 on-device AI correction
Integrates LiteRT-LM (Google) with Gemma 4 E2B-it for on-device spell/grammar correction in HeliBoard. After sentence-ending punctuation, the model checks the sentence and shows a correction in the suggestion strip. Tapping it replaces the original text — fully offline, no cloud API. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
From: AIKeyboard AI Integration <ai@aikeyboard.local>
|
||||
Date: Wed, 09 Apr 2025 00:00:00 +0000
|
||||
Subject: [PATCH 1/3] Add AI spell correction trigger hook in InputLogic
|
||||
|
||||
After a sentence-ending punctuation character (. ! ? ...) is committed to the
|
||||
InputConnection, notify AiTriggerHook with the text before the cursor so the
|
||||
AI correction engine can run in the background.
|
||||
|
||||
Field name confirmed: mLatinIME (type LatinIME, first constructor parameter).
|
||||
The hook is debounced (500ms) and async — the IME main thread is never blocked.
|
||||
---
|
||||
.../keyboard/latin/inputlogic/InputLogic.java | 13 +++++++++++++
|
||||
1 file changed, 13 insertions(+)
|
||||
|
||||
diff --git a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java
|
||||
--- a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java
|
||||
+++ b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java
|
||||
@@ -1228,6 +1228,19 @@ final class InputLogic {
|
||||
|
||||
mConnection.commitCodePoint(codePoint);
|
||||
|
||||
+ // === AI SPELL CORRECTION HOOK ===
|
||||
+ // Runs async on Dispatchers.IO via coroutine — does not block the IME thread.
|
||||
+ // mLatinIME is confirmed non-null here (it's set in the constructor).
|
||||
+ if (helium314.keyboard.latin.ai.AiTriggerHook.isSentenceEnder(codePoint)
|
||||
+ && mLatinIME.getAiTriggerHook() != null) {
|
||||
+ final CharSequence beforeCursor =
|
||||
+ mConnection.getTextBeforeCursor(500, 0);
|
||||
+ if (beforeCursor != null) {
|
||||
+ mLatinIME.getAiTriggerHook()
|
||||
+ .onSentenceEndDetected(beforeCursor.toString());
|
||||
+ }
|
||||
+ }
|
||||
+ // === END AI SPELL CORRECTION HOOK ===
|
||||
+
|
||||
if (isInlineEmojiSearchAction()) {
|
||||
inputTransaction.setRequiresUpdateSuggestions();
|
||||
} else {
|
||||
Reference in New Issue
Block a user