di: add a stub TierDetection; provide both actual impl and stub in AppModule

This commit is contained in:
Han Yin 2025-06-27 11:58:29 -07:00
parent 21e61281fa
commit 70ec1f7de7
3 changed files with 36 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package com.example.llama.di
import android.content.Context import android.content.Context
import android.llama.cpp.InferenceEngine import android.llama.cpp.InferenceEngine
import android.llama.cpp.KleidiLlama import android.llama.cpp.KleidiLlama
import android.llama.cpp.TierDetection
import android.llama.cpp.gguf.GgufMetadataReader import android.llama.cpp.gguf.GgufMetadataReader
import com.example.llama.data.local.AppDatabase import com.example.llama.data.local.AppDatabase
import com.example.llama.data.remote.HuggingFaceApiService import com.example.llama.data.remote.HuggingFaceApiService
@ -18,6 +19,7 @@ import com.example.llama.engine.InferenceService
import com.example.llama.engine.InferenceServiceImpl import com.example.llama.engine.InferenceServiceImpl
import com.example.llama.engine.ModelLoadingService import com.example.llama.engine.ModelLoadingService
import com.example.llama.engine.StubInferenceEngine import com.example.llama.engine.StubInferenceEngine
import com.example.llama.engine.StubTierDetection
import com.example.llama.monitoring.PerformanceMonitor import com.example.llama.monitoring.PerformanceMonitor
import dagger.Binds import dagger.Binds
import dagger.Module import dagger.Module
@ -71,6 +73,15 @@ internal abstract class AppModule {
} }
} }
@Provides
fun provideTierDetection(@ApplicationContext context: Context): TierDetection {
return if (USE_STUB_ENGINE) {
StubTierDetection
} else {
KleidiLlama.getTierDetection(context)
}
}
@Provides @Provides
fun providePerformanceMonitor(@ApplicationContext context: Context) = PerformanceMonitor(context) fun providePerformanceMonitor(@ApplicationContext context: Context) = PerformanceMonitor(context)

View File

@ -0,0 +1,19 @@
package com.example.llama.engine
import android.llama.cpp.LLamaTier
import android.llama.cpp.TierDetection
import android.util.Log
/**
* A stub [TierDetection] for agile development & testing
*/
object StubTierDetection : TierDetection {
private val tag = StubTierDetection::class.java.simpleName
override val detectedTier: LLamaTier?
get() = LLamaTier.T2
override fun clearCache() {
Log.d(tag, "Cache cleared")
}
}

View File

@ -1,5 +1,7 @@
package com.example.llama.viewmodel package com.example.llama.viewmodel
import android.llama.cpp.LLamaTier
import android.llama.cpp.TierDetection
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.example.llama.data.preferences.UserPreferences import com.example.llama.data.preferences.UserPreferences
@ -26,6 +28,7 @@ class SettingsViewModel @Inject constructor(
private val userPreferences: UserPreferences, private val userPreferences: UserPreferences,
private val performanceMonitor: PerformanceMonitor, private val performanceMonitor: PerformanceMonitor,
private val modelRepository: ModelRepository, private val modelRepository: ModelRepository,
private val tierDetection: TierDetection,
) : ViewModel() { ) : ViewModel() {
// Storage usage metrics // Storage usage metrics
@ -57,6 +60,9 @@ class SettingsViewModel @Inject constructor(
private val _themeMode = MutableStateFlow(UserPreferences.THEME_MODE_AUTO) private val _themeMode = MutableStateFlow(UserPreferences.THEME_MODE_AUTO)
val themeMode: StateFlow<Int> = _themeMode.asStateFlow() val themeMode: StateFlow<Int> = _themeMode.asStateFlow()
val detectedTier: LLamaTier?
get() = tierDetection.detectedTier
init { init {
viewModelScope.launch { viewModelScope.launch {
// Load user preferences // Load user preferences