-
Notifications
You must be signed in to change notification settings - Fork 28
/
chat.html
83 lines (81 loc) · 2.35 KB
/
chat.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<html>
<head>
<title>ChatGPT Data Export</title>
<style>
body {
margin: 20px;
}
h4 {
font-family: sans-serif;
margin: 0;
}
#root {
display: flex;
flex-direction: column;
gap: 20px;
}
.conversation {
border: 1px solid black;
padding: 20px;
background-color: #f3f3f3;
}
.message {
white-space: pre-wrap;
margin: 20px 0;
}
.author {
font-weight: bold;
margin-bottom: 4px;
}
.author::first-letter {
text-transform: uppercase;
}
</style>
<script>
var jsonData = <insert data here>
function getConversationMessages(conversation) {
var messages = [];
var currentNode = conversation.current_node;
while (currentNode != null) {
var node = conversation.mapping[currentNode];
if (node.message &&
node.message.content &&
node.message.content.content_type == "text"
&& node.message.content.parts.length > 0 &&
node.message.content.parts[0].length > 0 &&
node.message.author.role != "system") {
author = node.message.author.role;
if (author === "assistant") {
author = "ChatGPT";
}
messages.push({ author, text: node.message.content.parts[0] });
}
currentNode = node.parent;
}
return messages.reverse();
}
// on load, add messages to the root div
window.onload = function() {
var root = document.getElementById("root");
for (var i = 0; i < jsonData.length; i++) {
var conversation = jsonData[i];
var messages = getConversationMessages(conversation);
var div = document.createElement("div");
div.className = "conversation";
div.innerHTML = "<h4>" + conversation.title + "</h4>";
for (var j = 0; j < messages.length; j++) {
var message = document.createElement("pre");
message.className = "message";
message.innerHTML = `<div class="author">${messages[j].author}</div><div>${messages[j].text}</div>`;
div.appendChild(message);
}
root.appendChild(div);
}
}
</script>
</head>
<body>
<div id="root">
</div>
</body>
</html>