Skip loading LM if it has not existed once

This commit is contained in:
Aleksandras Kostarevas 2024-05-26 13:39:34 +03:00
parent 43c46da519
commit 0d7d6b816e

View File

@ -181,11 +181,13 @@ public class LanguageModelFacilitator(
} }
} }
private var skipLanguage: String? = null
private suspend fun runLanguageModel(values: PredictionInputValues): ArrayList<SuggestedWordInfo>? { private suspend fun runLanguageModel(values: PredictionInputValues): ArrayList<SuggestedWordInfo>? {
if(transformerDisabled) return null if(transformerDisabled) return null
val locale = dictionaryFacilitator.locale ?: return null val locale = dictionaryFacilitator.locale ?: return null
if (languageModel == null || (languageModel?.locale?.language != locale.language)) { if ((languageModel == null && locale.language != skipLanguage) || (languageModel?.locale?.language != locale.language)) {
skipLanguage = null
Log.d( Log.d(
"LanguageModelFacilitator", "LanguageModelFacilitator",
"Calling closeInternalLocked on model due to seeming locale change" "Calling closeInternalLocked on model due to seeming locale change"
@ -200,6 +202,7 @@ public class LanguageModelFacilitator(
languageModel = LanguageModel(context, lifecycleScope, model, locale) languageModel = LanguageModel(context, lifecycleScope, model, locale)
} else { } else {
Log.d("LanguageModelFacilitator", "no model for ${locale.language}") Log.d("LanguageModelFacilitator", "no model for ${locale.language}")
skipLanguage = locale.language
return null return null
} }
} }
@ -448,6 +451,7 @@ public class LanguageModelFacilitator(
withContext(Dispatchers.Default) { withContext(Dispatchers.Default) {
ModelPaths.modelOptionsUpdated.collect { ModelPaths.modelOptionsUpdated.collect {
Log.d("LanguageModelFacilitator", "ModelPaths options updated, destroying model") Log.d("LanguageModelFacilitator", "ModelPaths options updated, destroying model")
skipLanguage = null
destroyModel() destroyModel()
} }
} }