Skip to content

Implement Context Window Content Modification in UI #1

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 1 commit 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
50 changes: 50 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ const displayMessages = (data: any): string => {
} break-words whitespace-pre-wrap font-mono" >
${msg.content}
</div>
<form action="/context/${data.meta.id}/update" method="POST">
<textarea name="content" class="w-full h-32">${msg.content}</textarea>
<input type="hidden" name="index" value="${index}" />
<button type="submit" class="bg-blue-500 text-white p-2 rounded-md">Submit</button>
</form>
`,
)
.join("")
Expand Down Expand Up @@ -171,6 +176,51 @@ ${window.meta.final_state.content}
},
)

app.post("/context/:id/update", async (c) => {
const id = c.req.param("id")
const body = await c.req.parseBody()

const index = parseInt(body.index)
const content = body.content

const windows = await getMetadata()

const data: any[] = []

await new Promise((resolve) => {
fs.createReadStream("./context_windows.jsonl")
.pipe(ndjson.parse())
.on("data", async (obj) => {
data.push(obj)
})
.on("end", () => {
resolve(data)
})
})

const window = data.find((w) => w.meta.id === id)

if (!window) {
return c.text("Not found", 404)
}

window.messages[index].content = content

await new Promise((resolve) => {
const stream = fs.createWriteStream("./context_windows.jsonl")

data.forEach((obj) => {
stream.write(JSON.stringify(obj) + "\n")
})

stream.end(() => {
resolve(null)
})
})

return c.redirect(`/context/${id}/`)
})

app.get(
"/context/:id/json/",
ssgParams(async () => {
Expand Down