Commit 30a644d

Ansari <ping@ansari.wtf>
2026-05-12 15:15:23
adding cache
1 parent 225935c
Changed files (2)
ai/client.go
@@ -15,6 +15,10 @@ var client = &http.Client{
 }
 
 func Ask(prompt string) (string, error) {
+	if cached, ok := getCached(prompt); ok {
+		return cached, nil
+	}
+
 	payload := map[string]any{
 		"model":  "llama3-chatqa:8b",
 		"prompt": prompt,
@@ -49,6 +53,7 @@ func Ask(prompt string) (string, error) {
 	if err := json.Unmarshal(respBody, &result); err != nil {
 		return "", fmt.Errorf("unmarshal: %w", err)
 	}
-
-	return strings.TrimSpace(result.Response), nil
+	answer := strings.TrimSpace(result.Response)
+	setCached(prompt, answer)
+	return answer, nil
 }
handlers/commands.go
@@ -21,7 +21,7 @@ var commands = map[string]command{
 		prompt: "Define '%s' in one sentence like a dictionary. Max 200 characters. No markdown.",
 	},
 	"ask": {
-		prompt: "Answer this question factually and concisely in 2-3 sentences. No markdown. No preamble. Question: '%s'",
+		prompt: "Answer this question factually and concisely in 2-3 sentences. Be precise. No markdown. No preamble. Question: '%s'",
 	},
 }