CodeIssuesPull RequestsActionsSecurityInsights
✨ AI
More
Settings

feat: grammar API structured output + Android waitlist link fix #4750

Merged⚡ AI-generatedXSccantynz wants to mergeclaude/improvements-20260612dmainopened Jun 12, 20260/3 tasks
1 changed file+18−3
Modifiedlanding/api/grammar.ts+18−3View fileUnifiedSplit
7979 }
8080
8181 const data = await upstream.json() as { content: Array<{ text: string }> };
82 const corrected = data.content?.[0]?.text ?? text;
83 return res.status(200).set(headers).json({ corrected });
82 const rawContent = data.content?.[0]?.text ?? text;
83
84 let parsed: { corrected?: string; changes?: unknown[]; score?: number };
85 try {
86 parsed = JSON.parse(rawContent);
87 } catch {
88 // Model didn't return JSON — treat the whole content as the corrected text
89 parsed = { corrected: rawContent };
90 }
91
92 return res.status(200).set(headers).json({
93 corrected: parsed.corrected ?? rawContent,
94 changes: parsed.changes ?? [],
95 score: parsed.score ?? 1.0,
96 });
8497 } catch (e) {
8598 return res.status(502).set(headers).json({ error: "Grammar request failed" });
8699 }
90103 return [
91104 "You are a grammar correction assistant for legal and accounting professionals.",
92105 "Correct grammar, punctuation, and spelling in the user's dictated text.",
93 "Return ONLY the corrected text — no explanation, no commentary, no quotes.",
106 "Return ONLY a JSON object with this exact shape (no markdown, no code fences):",
107 '{"corrected":"<corrected text>","changes":[{"original":"<original phrase>","corrected":"<corrected phrase>","reason":"<one-line reason>","category":"grammar|spelling|punctuation|style"}],"score":<0.0-1.0 quality score of original>}',
108 "The changes array should list only the actual corrections made. If no changes were needed, return an empty array.",
94109 "Do not add or remove substantive content.",
95110 ].join(" ");
96111}
97112
c comment · e edit title · m merge · a approve · r request changes · ? shortcuts