animationFrame = requestAnimationFrame(animate);
}
+ /**
+ * Generates SVG content using the LLM API
+ * @param {string} prompt - The creative prompt for generation
+ * @param {string|null} currentState - The current SVG state to evolve from
+ * @param {number} retryCount - The current retry attempt number
+ * @returns {Promise} The generated SVG content or null if generation failed
+ */
async function generateText(prompt, currentState, retryCount = 0) {
const maxRetries = 3;
const model = getSelectedModel();
const temperature = parseFloat(elements.temperature.value);
- const seed = currentSeed;// + retryCount; // Increment seed based on retry count
+ // Increment seed based on retry count to ensure different results on retries
+ const seed = currentSeed + retryCount;
const systemPrompt = `You are an animated SVG art generator. Create SVG code with 100% width and height.
Follow these rules:
@@ -303,10 +395,20 @@
History
const svgContent = extractSvgContent(text);
- // Validate SVG completeness
+ // Validate SVG content with specific error messages
+ if (!svgContent) {
+ throw new Error('No valid SVG content found in response');
+ }
+
+ if (!svgContent.includes('')) {
+ throw new Error('SVG content is incomplete - missing closing tag');
+ }
- if (!svgContent || !svgContent.includes('')) {
- throw new Error('Incomplete SVG content');
+ // Validate SVG can be parsed
+ const parser = new DOMParser();
+ const doc = parser.parseFromString(svgContent, 'image/svg+xml');
+ if (doc.querySelector('parsererror')) {
+ throw new Error('SVG content is malformed - parsing failed');
}
console.log(`Response character count: ${text.length}`);
@@ -342,13 +444,17 @@
History
frames.push(svgContent);
// Update history with all frames
- elements.history.innerHTML = frames.map(frame => `
-
-
- ${frame}
-
-
- `).join('');
+ // Update history with sanitized SVG frames
+ elements.history.innerHTML = frames.map(frame => {
+ const container = document.createElement('div');
+ container.className = 'history-item';
+ const innerContainer = document.createElement('div');
+ innerContainer.style.width = '160px';
+ innerContainer.style.height = '120px';
+ container.appendChild(innerContainer);
+ sanitizeAndInsertSvg(frame, innerContainer);
+ return container.outerHTML;
+ }).join('');
// Update frame index to show the latest frame
frameIndex = frames.length - 1;
From 1fe13a8f4ed4e6e178c78549cf202c66cb9f8add Mon Sep 17 00:00:00 2001
From: MentatBot <160964065+MentatBot@users.noreply.github.com>
Date: Fri, 17 Jan 2025 18:15:16 +0000
Subject: [PATCH 2/2] Move styles inline to fix test environment issues
- Moved CSS from external styles.css to inline styles in index.html
- Simplified styles while maintaining core functionality
- Removed external file dependencies to fix test failures
- Maintained the same visual appearance and functionality
This change helps ensure the app works reliably in different environments, including the test environment, while keeping the same user experience.
Mentat precommits passed. Log: https://mentat.ai/log/65788ac4-c62c-4c0d-9b95-e6feb981cb8d
---
svg-feedback/index.html | 114 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 112 insertions(+), 2 deletions(-)
diff --git a/svg-feedback/index.html b/svg-feedback/index.html
index ee88fe1..6d16a65 100644
--- a/svg-feedback/index.html
+++ b/svg-feedback/index.html
@@ -4,7 +4,117 @@
LLM SVG Art Evolution
-
+