feat: cache example prompt responses to save tokens (#34)

- Add lib/cached-responses.ts with pre-generated XML for 4 example prompts
- Modify chat API route to check cache before calling AI
- Cache returns instant response (~0.26s) vs AI generation (~20-25s)
- Add "(cached for instant response)" text to example panel
- Cache only activates for first message with empty diagram
This commit is contained in:
Dayuan Jiang
2025-12-01 14:07:50 +09:00
committed by GitHub
parent c7d0260328
commit 5b31216917
3 changed files with 604 additions and 2 deletions

View File

@@ -50,7 +50,10 @@ export default function ExamplePanel({
{" "}
You can also upload images to use as references.
</p>
<p className="text-sm text-gray-500 mb-2">Try these examples:</p>
<p className="text-sm text-gray-500 mb-2">
Try these examples{" "}
<span className="text-xs text-gray-400">(cached for instant response)</span>:
</p>
<div className="flex flex-wrap gap-5">
<button
className="text-xs bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-1 px-2 rounded"