data: code polish

This commit is contained in:
Han Yin 2025-04-12 17:51:20 -07:00
parent 3b499ac7e4
commit fddf060d92
3 changed files with 31 additions and 53 deletions

View File

@ -24,7 +24,7 @@ abstract class AppDatabase : RoomDatabase() {
AppDatabase::class.java, AppDatabase::class.java,
"llama_app_database" "llama_app_database"
) )
.fallbackToDestructiveMigration() .fallbackToDestructiveMigration(false)
.build() .build()
INSTANCE = instance INSTANCE = instance
instance instance

View File

@ -36,60 +36,36 @@ sealed class SystemPrompt {
override val timestamp: Long = System.currentTimeMillis() override val timestamp: Long = System.currentTimeMillis()
) : SystemPrompt() { ) : SystemPrompt() {
override val title: String override val title: String
get() = if (timestamp != null) { get() = dataFormat.format(Date(timestamp))
val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault())
dateFormat.format(Date(timestamp))
} else {
"Custom Prompt"
}
} }
companion object { companion object {
private val dataFormat by lazy { SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()) }
/** /**
* Creates a list of sample presets. * Creates a list of sample presets.
*/ */
fun getStaffPickedPrompts(): List<SystemPrompt> { val STUB_PRESETS = listOf(
return listOf( Preset(
Preset( id = "assistant",
id = "assistant", name = "Helpful Assistant",
name = "Helpful Assistant", content = "You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should be informative and engaging. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information."
content = "You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should be informative and engaging. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information." ),
), Preset(
Preset( id = "coder",
id = "coder", name = "Coding Assistant",
name = "Coding Assistant", content = "You are a helpful programming assistant. When asked coding questions, provide clear and functional code examples when applicable. If a question is ambiguous, ask for clarification. Focus on providing accurate solutions with good coding practices and explain your solutions."
content = "You are a helpful programming assistant. When asked coding questions, provide clear and functional code examples when applicable. If a question is ambiguous, ask for clarification. Focus on providing accurate solutions with good coding practices and explain your solutions." ),
), Preset(
Preset( id = "summarizer",
id = "summarizer", name = "Text Summarizer",
name = "Text Summarizer", content = "You are a helpful assistant that specializes in summarizing text. When provided with a text, create a concise summary that captures the main points, key details, and overall message. Adjust summary length based on original content length. Maintain factual accuracy and avoid adding information not present in the original text."
content = "You are a helpful assistant that specializes in summarizing text. When provided with a text, create a concise summary that captures the main points, key details, and overall message. Adjust summary length based on original content length. Maintain factual accuracy and avoid adding information not present in the original text." ),
), Preset(
Preset( id = "creative",
id = "creative", name = "Creative Writer",
name = "Creative Writer", content = "You are a creative writing assistant with a vivid imagination. Help users draft stories, poems, scripts, and other creative content. Provide imaginative ideas while following the user's specifications. When responding, focus on being original, engaging, and matching the requested tone and style."
content = "You are a creative writing assistant with a vivid imagination. Help users draft stories, poems, scripts, and other creative content. Provide imaginative ideas while following the user's specifications. When responding, focus on being original, engaging, and matching the requested tone and style."
)
) )
} )
/**
* Creates a placeholder list of recent prompts.
* In a real implementation, this would be loaded from the database.
*/
fun getRecentPrompts(): List<SystemPrompt> {
return listOf(
Custom(
id = "custom-1",
content = "You are a technical documentation specialist. When responding, focus on clarity, precision, and structure. Use appropriate technical terminology based on the context, but avoid jargon when simpler terms would suffice. Include examples where helpful, and organize information in a logical manner.",
timestamp = System.currentTimeMillis() - 3600000 // 1 hour ago
),
Custom(
id = "custom-2",
content = "You are a science educator with expertise in explaining complex concepts in accessible ways. Provide accurate, informative responses that help users understand scientific topics. Use analogies, examples, and clear explanations to make difficult concepts understandable. Cite established scientific consensus and explain levels of certainty when appropriate.",
timestamp = System.currentTimeMillis() - 86400000 // 1 day ago
)
)
}
} }
} }

View File

@ -16,15 +16,12 @@ class SystemPromptRepository(context: Context) {
private val systemPromptDao = AppDatabase.getDatabase(context).systemPromptDao() private val systemPromptDao = AppDatabase.getDatabase(context).systemPromptDao()
// Maximum number of recent prompts to keep
private val MAX_RECENT_PROMPTS = 10
/** /**
* Get all preset prompts. * Get all preset prompts.
*/ */
fun getPresetPrompts(): Flow<List<SystemPrompt>> { 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.getStaffPickedPrompts()) return kotlinx.coroutines.flow.flowOf(SystemPrompt.STUB_PRESETS)
} }
/** /**
@ -105,4 +102,9 @@ class SystemPromptRepository(context: Context) {
suspend fun deleteAllPrompts() { suspend fun deleteAllPrompts() {
systemPromptDao.deleteAllPrompts() systemPromptDao.deleteAllPrompts()
} }
companion object {
// Maximum number of recent prompts to keep
private const val MAX_RECENT_PROMPTS = 10
}
} }