[WIP] UI: replace the HuggingFace stub in Model Management screen with actual API call

This commit is contained in:
Han Yin 2025-04-21 23:13:35 -07:00
parent cfbd271c84
commit 0c7e1fc7a2
2 changed files with 36 additions and 2 deletions

View File

@ -221,6 +221,25 @@ fun ModelsManagementScreen(
is ModelManagementState.Idle -> { /* Idle state, nothing to show */ } is ModelManagementState.Idle -> { /* Idle state, nothing to show */ }
} }
} }
// TODO-han.yin: UI TO BE IMPLEMENTED
val huggingFaceModelsFlow = viewModel.huggingFaceModels
LaunchedEffect(Unit) {
huggingFaceModelsFlow.collect { models ->
val message = models.fold(
StringBuilder("Fetched ${models.size} models from HuggingFace")
) { builder, model ->
builder.append(model.id).append("\n")
}.toString()
onScaffoldEvent(
ScaffoldEvent.ShowSnackbar(
message = message,
duration = SnackbarDuration.Short
)
)
}
}
} }
@Composable @Composable

View File

@ -10,6 +10,7 @@ import com.example.llama.revamp.data.model.ModelInfo
import com.example.llama.revamp.data.model.ModelSortOrder import com.example.llama.revamp.data.model.ModelSortOrder
import com.example.llama.revamp.data.model.filterBy import com.example.llama.revamp.data.model.filterBy
import com.example.llama.revamp.data.model.sortByOrder import com.example.llama.revamp.data.model.sortByOrder
import com.example.llama.revamp.data.remote.HuggingFaceModel
import com.example.llama.revamp.data.repository.InsufficientStorageException import com.example.llama.revamp.data.repository.InsufficientStorageException
import com.example.llama.revamp.data.repository.ModelRepository import com.example.llama.revamp.data.repository.ModelRepository
import com.example.llama.revamp.util.getFileNameFromUri import com.example.llama.revamp.util.getFileNameFromUri
@ -19,7 +20,9 @@ import com.example.llama.revamp.viewmodel.ModelManagementState.Importation
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
@ -213,8 +216,20 @@ class ModelsManagementViewModel @Inject constructor(
} }
} }
// TODO-han.yin: Stub for now. Would need to investigate HuggingFace APIs // TODO-han.yin: UI TO BE IMPLEMENTED
fun importFromHuggingFace() {} private val _huggingFaceModels = MutableSharedFlow<List<HuggingFaceModel>>()
val huggingFaceModels: SharedFlow<List<HuggingFaceModel>> = _huggingFaceModels
fun importFromHuggingFace() = viewModelScope.launch {
modelRepository.searchHuggingFaceModels().let { models ->
_huggingFaceModels.emit(models)
Log.d(TAG, "Fetched ${models.size} models from HuggingFace:")
models.forEachIndexed { index, model ->
Log.d(TAG, "#$index: ${model.id}")
}
}
}
/** /**
* First show confirmation instead of starting deletion immediately * First show confirmation instead of starting deletion immediately