Replies: 4 comments
-
Similar with #127, but I'm thinking of implementing this. Thanks |
Beta Was this translation helpful? Give feedback.
0 replies
-
thanks a lot |
Beta Was this translation helpful? Give feedback.
0 replies
-
I'm testing similar functionality for
ChatViewModel.kt fun exportChat() {
val context = getApplication<Application>().applicationContext
// Build the chat history in Markdown format
val chatHistoryMarkdown = buildString {
appendLine("# Chat Export: \"${chatRoom.value.title}\"")
appendLine()
appendLine("**Exported on:** ${formatCurrentDateTime()}")
appendLine()
appendLine("---")
appendLine()
appendLine("## Chat History")
appendLine()
messages.value.forEach { message ->
val sender = if (message.platformType == null) "User" else "Assistant"
appendLine("**$sender:**")
appendLine(message.content)
appendLine()
}
}
// Save the Markdown file
val fileName = "chat_export_${System.currentTimeMillis()}.md"
val file = java.io.File(context.getExternalFilesDir(null), fileName)
file.writeText(chatHistoryMarkdown)
// Share the file
val uri = androidx.core.content.FileProvider.getUriForFile(context, "com.hoshisato.eva", file)
val shareIntent = Intent(Intent.ACTION_SEND).apply {
type = "text/markdown"
putExtra(Intent.EXTRA_STREAM, uri)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
context.startActivity(Intent.createChooser(shareIntent, "Share Chat Export").apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
})
}
private fun formatCurrentDateTime(): String {
val currentDate = java.util.Date()
val format = java.text.SimpleDateFormat("yyyy-MM-dd hh:mm a", java.util.Locale.getDefault())
return format.format(currentDate)
} ChatScreen.kttopBar = { ChatTopBar(chatRoom.title, chatRoom.id > 0, onBackAction, scrollBehavior, chatViewModel::openChatTitleDialog, onExportChatItemClick = chatViewModel::exportChat) }, isChatTitleUpdateEnabled: Boolean,
onBackAction: () -> Unit,
scrollBehavior: TopAppBarScrollBehavior,
onChatTitleItemClick: () -> Unit,
onExportChatItemClick: () -> Unit onChatTitleItemClick = {
onChatTitleItemClick.invoke()
isDropDownMenuExpanded = false
},
onExportChatItemClick = onExportChatItemClick
)
}, isDropDownMenuExpanded: Boolean,
isChatTitleUpdateEnabled: Boolean,
onDismissRequest: () -> Unit,
onChatTitleItemClick: () -> Unit,
onExportChatItemClick: () -> Unit /* Export Chat */
DropdownMenuItem(
text = { Text(text = stringResource(R.string.export_chat)) },
onClick = {
onExportChatItemClick()
onDismissRequest()
}
) AndroidManifest.xml <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.hoshisato.eva"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application> Edit |
Beta Was this translation helpful? Give feedback.
0 replies
-
This is now implemented in v0.6.3 |
Beta Was this translation helpful? Give feedback.
0 replies
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
-
It would be nice to have a feature to export a whole chat session not only copy one prompt and answere.
Maybe a share conversation button to share the whole text and an export all button that creates a folder at on the device storage and a file for every conversation in it...
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions