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" },
});
}