AI edit: return only changes, not full document

- Edit prompt asks for APPEND/PREPEND/REPLACE + only new content
- Frontend applies the edit surgically (append/prepend/replace)
- Much faster: AI only generates the new text, not the whole doc
- Chat mode still streams response progressively
This commit is contained in:
2026-05-27 11:08:25 +02:00
parent b020d2e193
commit da1194e8a5
2 changed files with 19 additions and 5 deletions
+5 -2
View File
@@ -158,8 +158,11 @@ func (s *Server) handleAIChat(w http.ResponseWriter, r *http.Request) {
var systemPrompt, userMsg string
if req.Mode == "edit" {
systemPrompt = "You are a document editor. The user will give you a markdown document and an instruction. " +
"Apply the instruction and return the COMPLETE updated document. " +
"Do not add explanations or wrap in code fences. Return raw markdown only."
"Return ONLY the new or changed text that should be inserted/replaced. " +
"Do not return the entire document. Do not add explanations or wrap in code fences. " +
"If adding content, return only the addition. If modifying, return only the modified section. " +
"Start your response with a location hint on the first line: APPEND (add to end), PREPEND (add to start), or REPLACE (replace entire document). " +
"Then the content on the next line."
userMsg = "Document:\n\n" + req.Content + "\n\nInstruction: " + req.Message
} else {
systemPrompt = "You are a helpful writing assistant. The user has a markdown document open. Answer concisely in markdown."