Skip to content

Add Editable Context Windows in UI #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ const displayMessages = (data: any): string => {
</div>
<div class="px-6 pb-6 rounded-md ${
msg.role === "assistant" ? "bg-gray-200" : msg.role === "system" ? "bg-pink-400 text-white" : "bg-blue-500 text-white"
} break-words whitespace-pre-wrap font-mono" >
<textarea id="message-content-${index}" class="w-full bg-transparent border-none focus:outline-none focus:ring-0">${msg.content}</textarea>
<button onclick="saveMessage(${index})" class="bg-pink-300 rounded-md p-2 hover:bg-pink-500 hover:text-white">Save</button>
${msg.content}
</div>
`,
Expand All @@ -129,6 +130,23 @@ app.get(
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${id} | Context Viewer</title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
const saveMessage = async (index) => {
const content = document.getElementById('message-content-' + index).value
const res = await fetch('/context/${id}/save/', {
method: 'POST',
body: JSON.stringify({
index,
content,
})
})
if (res.ok) {
alert('Saved!')
} else {
alert('Failed to save')
}
}
</script>
</head>
<body class="bg-gray-100 flex flex-row">
<div id="top" class="sticky top-5 mt-2 m-auto w-full text-center">
Expand Down Expand Up @@ -171,6 +189,28 @@ ${window.meta.final_state.content}
},
)

app.post(
"/context/:id/save/",
ssgParams(async () => {
const windows = await getMetadata()
return windows.map((w) => ({ id: w.id }))
}),
async (c) => {
const id = c.req.param("id")
const { index, content } = await c.req.json()

try {
const window = await getData(id)
window.messages[index].content = content

const outStream = fs.createWriteStream("./context_windows.jsonl", { flags: "w" })
outStream.write(JSON.stringify(window) + "\n")
outStream.end()

return c.text("Saved!")
} catch (e: any) {
if (e instanceof Error) {
return c.text(e.message, 500)
app.get(
"/context/:id/json/",
ssgParams(async () => {
Expand Down