GemAI organizes your interactions with Gemini AI into conversations. Each conversation maintains its own message history and context, allowing you to have multiple distinct chat sessions.
// Inject the use caseval createConversation: CreateConversationUseCase// Create with initial titleval result = createConversation.perform("My First Chat")when (result) { is Result.Success -> { val conversation = result.data println("Created conversation: ${conversation.id}") } is Result.Error -> { println("Failed: ${result.error}") }}
The title parameter is used as the initial conversation title, but it can be updated later using AI-generated titles based on the first message.
The application can automatically generate descriptive titles based on the first message:
UpdateChatTitleUseCase.kt
data class UpdateChatTitleParams( val prompt: String, val conversationId: Long)class UpdateChatTitleUseCase @Inject constructor( private val chatRepository: ChatRepository, @Dispatcher(GemAIDispatchers.IO) private val dispatcher: CoroutineDispatcher) : BaseUseCase<UpdateChatTitleParams, Result<Unit, RequestError>> { override suspend fun perform(params: UpdateChatTitleParams): Result<Unit, RequestError> = withContext(dispatcher) { chatRepository.updateChatTitle( conversationId = params.conversationId, prompt = params.prompt ) }}
How AI title generation works
The updateChatTitle method in the repository uses the Gemini AI model to analyze your first prompt and generate a concise, descriptive title. This happens automatically after you send the first message in a new conversation.
suspend fun updateChatTitle( conversationId: Long, prompt: String): Result<Unit, RequestError>
val conversationId = 123Lval result = deleteChatUseCase.perform(conversationId)when (result) { is Result.Success -> println("Conversation deleted") is Result.Error -> println("Delete failed: ${result.error}")}
Due to cascade deletion constraints in the database, deleting a conversation automatically removes all its associated messages.