DI: abstract the protocol of SystemPromptRepository; update AppModule
This commit is contained in:
parent
eebc05b559
commit
b6cc8f0c01
|
|
@ -13,15 +13,24 @@ import javax.inject.Singleton
|
||||||
/**
|
/**
|
||||||
* Repository for managing system prompts.
|
* Repository for managing system prompts.
|
||||||
*/
|
*/
|
||||||
|
interface SystemPromptRepository {
|
||||||
|
fun getPresetPrompts(): Flow<List<SystemPrompt>>
|
||||||
|
fun getRecentPrompts(): Flow<List<SystemPrompt>>
|
||||||
|
suspend fun savePromptToRecents(prompt: SystemPrompt)
|
||||||
|
suspend fun saveCustomPrompt(content: String): SystemPrompt
|
||||||
|
suspend fun deletePrompt(id: String)
|
||||||
|
suspend fun deleteAllPrompts()
|
||||||
|
}
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class SystemPromptRepository @Inject constructor(
|
class SystemPromptRepositoryImpl @Inject constructor(
|
||||||
private val systemPromptDao: SystemPromptDao,
|
private val systemPromptDao: SystemPromptDao,
|
||||||
) {
|
) : SystemPromptRepository {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all preset prompts.
|
* Get all preset prompts.
|
||||||
*/
|
*/
|
||||||
fun getPresetPrompts(): Flow<List<SystemPrompt>> {
|
override fun getPresetPrompts(): Flow<List<SystemPrompt>> {
|
||||||
// For now, we'll just return the static list since we don't store presets in the database
|
// For now, we'll just return the static list since we don't store presets in the database
|
||||||
return kotlinx.coroutines.flow.flowOf(SystemPrompt.STUB_PRESETS)
|
return kotlinx.coroutines.flow.flowOf(SystemPrompt.STUB_PRESETS)
|
||||||
}
|
}
|
||||||
|
|
@ -29,7 +38,7 @@ class SystemPromptRepository @Inject constructor(
|
||||||
/**
|
/**
|
||||||
* Get recent prompts from the database.
|
* Get recent prompts from the database.
|
||||||
*/
|
*/
|
||||||
fun getRecentPrompts(): Flow<List<SystemPrompt>> {
|
override fun getRecentPrompts(): Flow<List<SystemPrompt>> {
|
||||||
return systemPromptDao.getRecentPrompts(MAX_RECENT_PROMPTS)
|
return systemPromptDao.getRecentPrompts(MAX_RECENT_PROMPTS)
|
||||||
.map { entities ->
|
.map { entities ->
|
||||||
entities.map { it.toDomainModel() }
|
entities.map { it.toDomainModel() }
|
||||||
|
|
@ -40,7 +49,7 @@ class SystemPromptRepository @Inject constructor(
|
||||||
* Save a prompt to the recents list.
|
* Save a prompt to the recents list.
|
||||||
* If it's already in recents, just update the timestamp.
|
* If it's already in recents, just update the timestamp.
|
||||||
*/
|
*/
|
||||||
suspend fun savePromptToRecents(prompt: SystemPrompt) {
|
override suspend fun savePromptToRecents(prompt: SystemPrompt) {
|
||||||
// Check if this prompt already exists
|
// Check if this prompt already exists
|
||||||
val existingPrompt = systemPromptDao.getPromptById(prompt.id)
|
val existingPrompt = systemPromptDao.getPromptById(prompt.id)
|
||||||
|
|
||||||
|
|
@ -59,7 +68,7 @@ class SystemPromptRepository @Inject constructor(
|
||||||
/**
|
/**
|
||||||
* Create and save a custom prompt.
|
* Create and save a custom prompt.
|
||||||
*/
|
*/
|
||||||
suspend fun saveCustomPrompt(content: String): SystemPrompt {
|
override suspend fun saveCustomPrompt(content: String): SystemPrompt {
|
||||||
val customPrompt = SystemPrompt.Custom(
|
val customPrompt = SystemPrompt.Custom(
|
||||||
id = UUID.randomUUID().toString(),
|
id = UUID.randomUUID().toString(),
|
||||||
content = content
|
content = content
|
||||||
|
|
@ -94,16 +103,12 @@ class SystemPromptRepository @Inject constructor(
|
||||||
/**
|
/**
|
||||||
* Delete a prompt by ID.
|
* Delete a prompt by ID.
|
||||||
*/
|
*/
|
||||||
suspend fun deletePrompt(id: String) {
|
override suspend fun deletePrompt(id: String) = systemPromptDao.deletePromptById(id)
|
||||||
systemPromptDao.deletePromptById(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete all prompts.
|
* Delete all prompts.
|
||||||
*/
|
*/
|
||||||
suspend fun deleteAllPrompts() {
|
override suspend fun deleteAllPrompts() = systemPromptDao.deleteAllPrompts()
|
||||||
systemPromptDao.deleteAllPrompts()
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
// Maximum number of recent prompts to keep
|
// Maximum number of recent prompts to keep
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import android.content.Context
|
||||||
import com.example.llama.revamp.data.local.AppDatabase
|
import com.example.llama.revamp.data.local.AppDatabase
|
||||||
import com.example.llama.revamp.data.repository.ModelRepository
|
import com.example.llama.revamp.data.repository.ModelRepository
|
||||||
import com.example.llama.revamp.data.repository.ModelRepositoryImpl
|
import com.example.llama.revamp.data.repository.ModelRepositoryImpl
|
||||||
|
import com.example.llama.revamp.data.repository.SystemPromptRepository
|
||||||
|
import com.example.llama.revamp.data.repository.SystemPromptRepositoryImpl
|
||||||
import com.example.llama.revamp.engine.InferenceEngine
|
import com.example.llama.revamp.engine.InferenceEngine
|
||||||
import com.example.llama.revamp.monitoring.PerformanceMonitor
|
import com.example.llama.revamp.monitoring.PerformanceMonitor
|
||||||
import dagger.Binds
|
import dagger.Binds
|
||||||
|
|
@ -21,6 +23,9 @@ abstract class AppModule {
|
||||||
@Binds
|
@Binds
|
||||||
abstract fun bindsModelsRepository(impl: ModelRepositoryImpl): ModelRepository
|
abstract fun bindsModelsRepository(impl: ModelRepositoryImpl): ModelRepository
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
abstract fun bindsSystemPromptRepository(impl: SystemPromptRepositoryImpl): SystemPromptRepository
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue