Skip to content

Commit 03dff58

Browse files
committed
lint ?
1 parent 737c180 commit 03dff58

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/feature/hybrid/HybridInferenceViewModel.kt

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ object HybridInferenceRoute
2828

2929
@OptIn(PublicPreviewAPI::class)
3030
class HybridInferenceViewModel : ViewModel() {
31-
private val _uiState = MutableStateFlow(HybridInferenceUiState(
32-
expenses = listOf(
33-
Expense(UUID.randomUUID().toString(), "Lunch", 15.50),
34-
Expense(UUID.randomUUID().toString(), "Coffee", 4.75)
31+
private val _uiState = MutableStateFlow(
32+
HybridInferenceUiState(
33+
expenses = listOf(
34+
Expense(UUID.randomUUID().toString(), "Lunch", 15.50),
35+
Expense(UUID.randomUUID().toString(), "Coffee", 4.75)
36+
)
3537
)
36-
))
38+
)
3739
val uiState: StateFlow<HybridInferenceUiState> = _uiState.asStateFlow()
3840

39-
private val model = Firebase.ai(backend = GenerativeBackend.googleAI())
40-
.generativeModel(
41+
private val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
4142
modelName = "gemini-3.1-flash-lite-preview",
4243
onDeviceConfig = OnDeviceConfig(mode = InferenceMode.PREFER_ON_DEVICE)
4344
)
@@ -58,15 +59,22 @@ class HybridInferenceViewModel : ViewModel() {
5859
is DownloadStatus.DownloadStarted -> {
5960
_uiState.update { it.copy(modelStatus = "Downloading model...") }
6061
}
62+
6163
is DownloadStatus.DownloadInProgress -> {
6264
val progress = downloadStatus.totalBytesDownloaded
6365
_uiState.update { it.copy(modelStatus = "Downloading: $progress bytes downloaded") }
6466
}
67+
6568
is DownloadStatus.DownloadCompleted -> {
6669
_uiState.update { it.copy(modelStatus = "Model ready") }
6770
}
71+
6872
is DownloadStatus.DownloadFailed -> {
69-
_uiState.update { it.copy(modelStatus = "Download failed", errorMessage = "Model download failed") }
73+
_uiState.update {
74+
it.copy(
75+
modelStatus = "Download failed", errorMessage = "Model download failed"
76+
)
77+
}
7078
}
7179
}
7280
}
@@ -119,15 +127,12 @@ class HybridInferenceViewModel : ViewModel() {
119127
// Simple parsing: "Store, Price"
120128
val parts = text
121129
// Sometimes the output contains single quotes
122-
.replace("'", "")
123-
.split(",", limit = 2)
130+
.replace("'", "").split(",", limit = 2)
124131
if (parts.size >= 2) {
125132
val name = parts[0].trim()
126-
val priceStr = parts[1].trim()
127-
.replace("$", "")
128-
.replace(",", "")
133+
val priceStr = parts[1].trim().replace("$", "").replace(",", "")
129134
val price = priceStr.toDoubleOrNull() ?: 0.0
130-
135+
131136
val newExpense = Expense(UUID.randomUUID().toString(), name, price)
132137
_uiState.update { it.copy(expenses = it.expenses + newExpense) }
133138
} else {

0 commit comments

Comments
 (0)