Add timeout + lower temperature for AI calls

This commit is contained in:
2026-05-27 10:58:12 +02:00
parent b2b454c563
commit 63f3c0dec8
+6 -5
View File
@@ -7,6 +7,7 @@ import (
"net/http"
"os"
"strings"
"time"
"markdownhub/internal/files"
)
@@ -158,10 +159,8 @@ func (s *Server) handleAIChat(w http.ResponseWriter, r *http.Request) {
if req.Mode == "edit" {
systemPrompt = "You are a document editor. The user will give you a markdown document and an instruction. " +
"Apply the instruction to the document and return ONLY the complete updated document. " +
"Do not add explanations, comments, or wrap the output in code fences. " +
"Do not prefix with any markers. Preserve the document's existing style and formatting. " +
"Return the raw markdown content only."
"Apply the instruction and return the COMPLETE updated document. " +
"Do not add explanations or wrap in code fences. Return raw markdown only."
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 and is asking a question about it.
@@ -201,6 +200,7 @@ func callLLM(endpoint, apiKey, model, systemPrompt, userContent string) (string,
{"role": "system", "content": systemPrompt},
{"role": "user", "content": userContent},
},
"temperature": 0.3,
}
body, _ := json.Marshal(payload)
@@ -214,7 +214,8 @@ func callLLM(endpoint, apiKey, model, systemPrompt, userContent string) (string,
req.Header.Set("Authorization", "Bearer "+apiKey)
}
resp, err := http.DefaultClient.Do(req)
client := &http.Client{Timeout: 120 * time.Second}
resp, err := client.Do(req)
if err != nil {
return "", err
}