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
// This val renders the output of "janpaul123/getValsContextWindow" as HTML
// It uses React for rendering and includes a <select> for the "model" option
// The approach is to fetch the context window data, then render it as an interactive HTML page
/** @jsxImportSource https://esm.sh/react */
import { renderToString } from "npm:react-dom/server";
import getValsContextWindow from "https://esm.town/v/janpaul123/getValsContextWindow";
import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
const { owner, name } = extractValInfo(import.meta.url);
export default async function(req: Request): Promise<Response> {
const url = new URL(req.url);
const model = url.searchParams.get('model') || 'gpt-4o';
const contextWindow = await getValsContextWindow(model);
const App = () => (
<html>
<head>
<title>Val Context Window</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>{`
body { font-size: 12px; }
pre { font-size: 11px; }
`}</style>
</head>
<body className="bg-gray-100 p-4">
<h1 className="text-xl font-bold mb-2">Val Context Window</h1>
<form className="mb-2">
<label htmlFor="model" className="mr-2">Model:</label>
<select
id="model"
name="model"
value={model}
onChange="this.form.submit()"
className="p-1 border rounded text-xs"
>
<option value="gpt-4o">GPT-4</option>
<option value="gpt-3.5-turbo">GPT-3.5 Turbo</option>
</select>
</form>
<div className="space-y-2">
{contextWindow.map((message, index) => (
<div key={index} className="bg-white p-2 rounded shadow">
<h2 className="font-bold mb-1 text-xs">{message.role}</h2>
<pre className="whitespace-pre-wrap text-xs">{message.content}</pre>
</div>
))}
</div>
</body>
</html>
);
return new Response(renderToString(<App />), {
headers: { "Content-Type": "text/html" },
});
}