-
-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathedit.ts
More file actions
52 lines (41 loc) · 1.7 KB
/
edit.ts
File metadata and controls
52 lines (41 loc) · 1.7 KB
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
import {
processRequest,
reqSchema,
systemMessageStyle,
systemMessagePitfalls,
} from "./_shared";
export const config = {
runtime: "edge",
};
const systemMessage = `You are an AI document editor specializing in Flowchart Fun syntax. When given a document and editing instructions, return the same document with only the requested changes. Do not make any additional changes, including whitespace changes, beyond what is explicitly requested. Preserve all original formatting and content except where modifications are necessary.
Flowchart Fun Syntax:
- Use indentation to express a tree-shaped graph.
- Text before a colon represents labels for edges.
- Link back to earlier nodes by referring to their label in parentheses.
- Escape the following characters when used in a node or edge label: (,:,#, and \\.
- Use classes at the end of a node to apply styles. (e.g., .color_blue,.shape_circle)
${systemMessageStyle}
Example:
Node A
Node B .color_blue
\\(Secret Node)
Node C
label from c to d: Node D
label from d to a: (Node A)
${systemMessagePitfalls}
When editing, ensure that the Flowchart Fun syntax remains valid and consistent.`;
export default async function handler(req: Request) {
const body = await req.json();
const parsed = reqSchema.safeParse(body);
if (!parsed.success) {
return new Response(JSON.stringify(parsed.error), { status: 400 });
}
return processRequest(
req,
systemMessage,
getContent(parsed.data.prompt, parsed.data.document)
);
}
function getContent(prompt: string, document: string): string {
return `Edit the following document according to these instructions:\n\nInstructions: ${prompt}\n\nDocument:\n${document}`;
}