-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheval.html
255 lines (233 loc) · 9.1 KB
/
eval.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LarryGPT Evaluation</title>
<style>
body {
font-family: 'Consolas', 'Monaco', 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace;
max-width: 1200px;
margin: 0 auto;
padding: 10px;
background-color: #1e1e1e;
color: #d4d4d4;
font-size: 14px;
line-height: 1.4;
}
.container {
display: flex;
flex-direction: column;
height: 98vh;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 5px 0;
border-bottom: 1px solid #3e3e3e;
}
h1 {
font-size: 18px;
margin: 0;
color: #569cd6;
}
.navigation {
display: flex;
}
button {
background-color: #3e3e3e;
color: #d4d4d4;
border: none;
padding: 5px 10px;
margin-left: 5px;
cursor: pointer;
font-family: inherit;
font-size: 12px;
}
button:hover {
background-color: #505050;
}
button:disabled {
background-color: #2d2d2d;
color: #6d6d6d;
cursor: not-allowed;
}
#prompt {
background-color: #252526;
padding: 10px;
margin: 5px 0;
border-left: 3px solid #569cd6;
overflow-y: auto;
flex-shrink: 0;
}
#outputContainer {
overflow-y: auto;
flex-grow: 1;
}
.model-output {
margin: 5px 0;
background-color: #252526;
padding: 10px;
border-left: 3px solid #4ec9b0;
}
.model-pair {
display: flex;
margin: 5px 0;
}
.model-pair .model-output {
flex: 1;
margin: 0 5px;
}
pre {
white-space: pre-wrap;
word-wrap: break-word;
margin: 0;
}
.model-name {
color: #4ec9b0;
font-weight: bold;
margin-bottom: 5px;
}
.error-message {
color: #f44747;
}
#status {
color: #ce9178;
font-style: italic;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>LarryGPT Evaluation</h1>
<div class="navigation">
<button id="prevBtn" onclick="navigate(-1)">◀ Prev</button>
<button id="nextBtn" onclick="navigate(1)">Next ▶</button>
</div>
</div>
<div id="status">Loading model data...</div>
<div id="prompt"></div>
<div id="outputContainer"></div>
</div>
<script>
const modelConfigs = [
{ path: 'data/larry_david_valid.jsonl', name: 'GPT-4o' },
{ path: 'data/gpt-3.5-turbo_scrape.jsonl', name: 'GPT-3.5' },
{ path: 'data/scrape_gpt-3.5-ft.jsonl', name: 'GPT-3.5-Finetuned' },
{ path: 'data/llama_3.1_scrape.jsonl', name: 'Llama-3.1-8B' },
{ path: 'data/llama_3.1_ft_scrape.jsonl', name: 'Llama-3.1-8B-Finetuned' }
];
let modelData = [];
let currentIndex = 0;
function loadModelData(config) {
return fetch(config.path)
.then(response => response.text())
.then(contents => {
const lines = contents.split('\n').filter(line => line.trim() !== '');
return lines.map(line => {
try {
return JSON.parse(line);
} catch (error) {
console.error('Error parsing JSON:', error);
return { error: 'Invalid JSON', rawData: line };
}
});
})
.catch(error => {
console.error('Error loading file:', error);
return [{ error: 'Failed to load file', rawData: '' }];
});
}
function initializeUI() {
Promise.all(modelConfigs.map(loadModelData))
.then(results => {
modelData = results;
currentIndex = parseInt(new URLSearchParams(window.location.search).get('index')) || 0;
updateUI();
});
}
function updateUI() {
const outputContainer = document.getElementById('outputContainer');
const promptContainer = document.getElementById('prompt');
outputContainer.innerHTML = '';
promptContainer.innerHTML = '';
if (modelData.filter(Boolean).length === 0) {
document.getElementById('status').textContent = 'No model data available';
return;
}
document.getElementById('status').textContent = '';
const firstModelData = modelData.find(Boolean);
if (!firstModelData || !firstModelData[currentIndex]) {
document.getElementById('status').textContent = 'No data available for the current index';
return;
}
const userPrompt = firstModelData[currentIndex].messages?.find(msg => msg.role === "user")?.content || "Unable to retrieve user prompt";
promptContainer.innerHTML = `<strong>User Prompt:</strong><pre>${userPrompt}</pre>`;
// GPT-4 output
if (modelData[0] && currentIndex < modelData[0].length) {
const gpt4Output = document.createElement('div');
gpt4Output.className = 'model-output';
gpt4Output.innerHTML = `<div class="model-name">${modelConfigs[0].name}</div>${formatOutput(modelData[0][currentIndex])}`;
outputContainer.appendChild(gpt4Output);
}
// GPT-3.5 and Llama side-by-side
for (let i = 1; i < modelData.length; i += 2) {
if (i + 1 < modelData.length) {
const modelPair = document.createElement('div');
modelPair.className = 'model-pair';
const baseModel = document.createElement('div');
baseModel.className = 'model-output';
baseModel.innerHTML = `<div class="model-name">${modelConfigs[i].name}</div>${formatOutput(modelData[i][currentIndex])}`;
const fineTunedModel = document.createElement('div');
fineTunedModel.className = 'model-output';
fineTunedModel.innerHTML = `<div class="model-name">${modelConfigs[i+1].name}</div>${formatOutput(modelData[i+1][currentIndex])}`;
modelPair.appendChild(baseModel);
modelPair.appendChild(fineTunedModel);
outputContainer.appendChild(modelPair);
}
}
document.getElementById('prevBtn').disabled = currentIndex === 0;
document.getElementById('nextBtn').disabled = currentIndex === Math.min(...modelData.filter(Boolean).map(d => d.length - 1));
// Update URL
const url = new URL(window.location);
url.searchParams.set('index', currentIndex);
window.history.pushState({}, '', url);
}
function formatOutput(data) {
if (data.error) {
return `<p class="error-message">Error: Model output does not comply with the expected format.</p><pre>${escapeHtml(data.rawData)}</pre>`;
}
const assistantMessage = data.messages?.find(msg => msg.role === "assistant");
if (assistantMessage) {
try {
const content = JSON.parse(assistantMessage.content);
return `<pre>${content.map(item => `${item.text} (${item.emotion})`).join('\n')}</pre>`;
} catch (error) {
console.error('Error parsing assistant message:', error);
return `<p class="error-message">Error: Unable to parse model output.</p><pre>${escapeHtml(assistantMessage.content)}</pre>`;
}
}
return "<p>No assistant message found.</p>";
}
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
function navigate(direction) {
currentIndex += direction;
updateUI();
}
window.addEventListener('popstate', function(event) {
currentIndex = parseInt(new URLSearchParams(window.location.search).get('index')) || 0;
updateUI();
});
initializeUI();
</script>
</body>
</html>