Skip to content

Commit f191eda

Browse files
committed
Fix offline proofreading crash, update docs, and improve API settings
1 parent 996274e commit f191eda

5 files changed

Lines changed: 36 additions & 37 deletions

File tree

app/proguard-rules.pro

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@
2121

2222
# Keep Gemini API classes
2323
-keep class com.google.ai.client.generativeai.** { *; }
24-
-keep class helium314.keyboard.latin.utils.GeminiProofreadService { *; }
24+
2525
-keep class helium314.keyboard.latin.utils.ProofreadHelper { *; }
2626
-keep class helium314.keyboard.latin.utils.ProofreadHelper$* { *; }
2727

2828
# Keep java-llama.cpp classes
2929
-keep class de.kherud.llama.** { *; }
30+
31+
# ONNX Runtime configurations
32+
-dontwarn com.google.protobuf.**
33+
-keep class ai.onnxruntime.** { *; }
34+
35+
# Fix correct service name
36+
-keep class helium314.keyboard.latin.utils.ProofreadService { *; }

app/src/main/java/helium314/keyboard/settings/screens/AdvancedScreen.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ fun createAdvancedSettings(context: Context) = listOfNotNull(
285285
val service = remember { helium314.keyboard.latin.utils.ProofreadService(ctx) }
286286
Preference(
287287
name = setting.title,
288-
description = setting.description,
288+
description = if (service.hasApiKey()) "Key set" else stringResource(R.string.gemini_api_key_summary),
289289
onClick = { showDialog = true }
290290
)
291291
if (showDialog) {
@@ -356,20 +356,28 @@ fun createAdvancedSettings(context: Context) = listOfNotNull(
356356
var showDialog by rememberSaveable { mutableStateOf(false) }
357357
val ctx = LocalContext.current
358358
val service = remember { helium314.keyboard.latin.utils.ProofreadService(ctx) }
359+
var hasToken by remember { mutableStateOf(service.getGroqToken() != null) }
360+
359361
Preference(
360362
name = setting.title,
361-
description = setting.description,
363+
description = if (hasToken) "Key set" else "Not set",
362364
onClick = { showDialog = true }
363365
)
364366
if (showDialog) {
365367
TextInputDialog(
366368
onDismissRequest = { showDialog = false },
367369
textInputLabel = { Text(stringResource(R.string.groq_token_hint)) },
368370
initialText = service.getGroqToken() ?: "",
369-
onConfirmed = { service.setGroqToken(it) },
371+
onConfirmed = {
372+
service.setGroqToken(it)
373+
hasToken = true
374+
},
370375
title = { Text(stringResource(R.string.groq_token_title)) },
371-
neutralButtonText = if (service.getGroqToken() != null) stringResource(R.string.delete) else null,
372-
onNeutral = { service.setGroqToken(null) },
376+
neutralButtonText = if (hasToken) stringResource(R.string.delete) else null,
377+
onNeutral = {
378+
service.setGroqToken(null)
379+
hasToken = false
380+
},
373381
extraContent = {
374382
val uriHandler = androidx.compose.ui.platform.LocalUriHandler.current
375383
TextButton(
@@ -387,7 +395,7 @@ fun createAdvancedSettings(context: Context) = listOfNotNull(
387395
val service = remember { helium314.keyboard.latin.utils.ProofreadService(ctx) }
388396
Preference(
389397
name = setting.title,
390-
description = setting.description,
398+
description = if (service.getHuggingFaceToken() != null) "Key set" else "Not set",
391399
onClick = { showDialog = true }
392400
)
393401
if (showDialog) {

app/src/offline/java/helium314/keyboard/latin/utils/GeminiProofreadService.kt

Lines changed: 0 additions & 27 deletions
This file was deleted.

app/src/standard/java/helium314/keyboard/latin/utils/ProofreadHelper.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,18 @@ object ProofreadHelper {
7373
return
7474
}
7575
}
76-
ProofreadService.AIProvider.GROQ, ProofreadService.AIProvider.OPENAI -> {
76+
ProofreadService.AIProvider.GROQ -> {
77+
if (service.getGroqToken() == null) {
78+
mainHandler.post {
79+
KeyboardSwitcher.getInstance().showToast(
80+
context.getString(R.string.huggingface_no_token),
81+
true
82+
)
83+
}
84+
return
85+
}
86+
}
87+
ProofreadService.AIProvider.OPENAI -> {
7788
if (service.getHuggingFaceToken() == null) {
7889
mainHandler.post {
7990
KeyboardSwitcher.getInstance().showToast(

docs/FEATURES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Offline proofreading runs entirely on your device using the ONNX Runtime engine.
124124

125125
| Model & Purpose | Performance / Size | System Instruction | Download Links (Direct) |
126126
| :--- | :--- | :--- | :--- |
127-
| **Visheratin T5 Tiny**<br>*(Grammar Correction Only)* |**Fastest**<br>~35 MB<br>Low RAM usage | **Empty**<br>(Leave blank) |[Encoder](https://huggingface.co/visheratin/t5-efficient-tiny-grammar-correction/resolve/main/encoder_model_quant.onnx)<br>• [Decoder](https://huggingface.co/visheratin/t5-efficient-tiny-grammar-correction/resolve/main/init_decoder_quant.onnx)<br>• [Tokenizer](https://huggingface.co/visheratin/t5-efficient-tiny-grammar-correction/resolve/main/tokenizer.json) |
128-
| **Flan-T5 Small**<br>*(Translation & General)* | 🐢 **Slower**<br>~300 MB<br>Higher accuracy | **Required**<br>`fix grammar: `<br>or<br>`translate English to Spanish: ` |[Encoder](https://huggingface.co/Xenova/flan-t5-small/resolve/main/onnx/encoder_model_quantized.onnx)<br>• [Decoder](https://huggingface.co/Xenova/flan-t5-small/resolve/main/onnx/decoder_model_quantized.onnx)<br>• [Tokenizer](https://huggingface.co/Xenova/flan-t5-small/resolve/main/tokenizer.json) |
127+
| **Visheratin T5 Tiny**<br>*(Grammar Correction Only)* |**Fastest**<br>~35 MB<br>Low RAM usage | **Empty**<br>(Leave blank) |[Encoder](https://huggingface.co/visheratin/t5-efficient-tiny-grammar-correction/resolve/main/encoder_model_quant.onnx)<br>• [Decoder](https://huggingface.co/visheratin/t5-efficient-tiny-grammar-correction/resolve/main/init_decoder_quant.onnx)<br>• [Tokenizer](https://huggingface.co/visheratin/t5-efficient-tiny-grammar-correction/tree/main) |
128+
| **Flan-T5 Small**<br>*(Translation & General)* | 🐢 **Slower**<br>~300 MB<br>Higher accuracy | **Required**<br>`fix grammar: `<br>or<br>`translate English to Spanish: ` |[Encoder](https://huggingface.co/Xenova/flan-t5-small/resolve/main/onnx/encoder_model_quantized.onnx)<br>• [Decoder](https://huggingface.co/Xenova/flan-t5-small/resolve/main/onnx/decoder_model_quantized.onnx)<br>• [Tokenizer](https://huggingface.co/Xenova/flan-t5-small/tree/main) |
129129

130130
*Note: For Flan-T5, the quantized models linked above are standard recommendations. Users have also reported success with `bnb4` quantized variants if available.*

0 commit comments

Comments
 (0)