Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
365 lines (342 loc) · 21.7 KB
/
Copy pathindex.html
File metadata and controls
365 lines (342 loc) · 21.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Prompt Optimizer | Improve Your Prompts with AI</title>
<meta name="description" content="Use our AI Prompt Optimizer to get expert suggestions on how to improve your prompts. Get better results from your AI models with our free prompt improver tool.">
<meta name="keywords" content="ai prompt optimizer, ai prompt improver, ai to improve my prompt, prompt engineering, prompt suggestions, improve prompt">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dompurify@3.0.6/dist/purify.min.js"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<!-- Chosen Palette: "Cool Focus" - A professional palette using a light gray (#F3F4F6) background, dark text (#1F2937), and a primary accent of blue (#3B82F6) for interactive elements and highlights. -->
<!-- Application Structure Plan: The SPA is a full-fledged landing page with the optimizer tool as the central feature. A header provides navigation to the 'How to Use' and 'FAQ' sections. The core tool remains a two-panel layout for intuitive interaction. This structure supports both new user discovery (through the guide and FAQ) and returning user engagement with the tool itself, while being optimized for SEO. -->
<!-- Visualization & Content Choices: The core logic remains card-based suggestions. The main addition is the new loading animation, which provides better visual feedback during the API call. The new content sections (Guide, FAQ) use standard text and list formats for clarity and SEO-friendliness, supported by structured data. -->
<!-- CONFIRMATION: NO SVG graphics used. NO Mermaid JS used. -->
<style>
body {
font-family: 'Inter', sans-serif;
background-color: #F3F4F6;
color: #1F2937;
}
.custom-radio input:checked + .custom-radio-label {
background-color: #3B82F6;
color: white;
border-color: #3B82F6;
}
.custom-radio-label {
transition: all 0.2s ease-in-out;
}
#output-container {
min-height: 400px;
}
.suggestion-card h3 {
font-size: 1.125rem;
font-weight: 600;
color: #111827;
}
.suggestion-card p {
color: #4B5563;
}
.suggestion-card code {
background-color: #E5E7EB;
padding: 0.1rem 0.3rem;
border-radius: 0.25rem;
font-family: monospace;
font-size: 0.9em;
}
/* Loading Animation */
.dots-loader {
display: flex;
align-items: center;
justify-content: center;
}
.dots-loader div {
width: 12px;
height: 12px;
background-color: #3B82F6;
border-radius: 100%;
margin: 0 5px;
animation: bounce 1.4s infinite ease-in-out both;
}
.dots-loader .dot1 { animation-delay: -0.32s; }
.dots-loader .dot2 { animation-delay: -0.16s; }
@keyframes bounce {
0%, 80%, 100% { transform: scale(0); }
40% { transform: scale(1.0); }
}
html { scroll-behavior: smooth; }
</style>
<!-- SEO Structured Data -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebApplication",
"name": "AI Prompt Optimizer",
"description": "A free tool that uses AI to analyze and improve your prompts based on expert research in prompt engineering. Get suggestions for Novice and Expert levels, or let the AI rewrite your prompt for you.",
"applicationCategory": "DeveloperApplication",
"operatingSystem": "All",
"url": "https://your-app-url.netlify.app",
"offers": {
"@type": "Offer",
"price": "0"
}
}
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [{
"@type": "Question",
"name": "What is an AI Prompt Optimizer?",
"acceptedAnswer": {
"@type": "Answer",
"text": "An AI Prompt Optimizer is a tool that analyzes your existing prompt and suggests improvements based on established principles of prompt engineering. Our tool uses AI to provide specific, actionable feedback to help you get better, more accurate, and more reliable results from large language models (LLMs)."
}
},{
"@type": "Question",
"name": "How does this prompt improver work?",
"acceptedAnswer": {
"@type": "Answer",
"text": "You enter your prompt and optional notes about your goal. Our tool then sends this information to an advanced AI model (Gemini), which has been instructed with a framework based on 'The Prompt Report'. The AI analyzes your input and generates suggestions tailored to your selected expertise level, or even rewrites the prompt for you."
}
},{
"@type": "Question",
"name": "Is this AI prompt optimizer free to use?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Yes, this tool is completely free to use. Our goal is to help developers, writers, and students learn how to craft better prompts."
}
},{
"@type": "Question",
"name": "Why are notes important for improving my prompt?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Notes provide crucial context about your *intent*. A prompt like 'Explain photosynthesis' can be answered in many ways. By adding a note like 'for a 5th-grade class,' you guide the AI to optimize the prompt for simplicity and clarity, resulting in a much more useful output."
}
}]
}
</script>
</head>
<body class="min-h-screen">
<!-- Header -->
<header class="bg-white shadow-sm sticky top-0 z-50">
<div class="container mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between items-center py-4">
<div class="flex items-center space-x-2">
<span class="text-2xl">🧠</span>
<span class="text-xl font-bold text-gray-800">Prompt Optimizer</span>
</div>
<nav class="hidden md:flex space-x-8">
<a href="#tool" class="text-gray-600 hover:text-blue-600 transition">Optimizer Tool</a>
<a href="#guide" class="text-gray-600 hover:text-blue-600 transition">How to Use</a>
<a href="#faq" class="text-gray-600 hover:text-blue-600 transition">FAQ</a>
</nav>
</div>
</div>
</header>
<main id="tool" class="container mx-auto p-4 sm:p-6 lg:p-8">
<header class="text-center mb-12">
<h1 class="text-4xl font-bold text-gray-800">AI-Powered Prompt Optimizer</h1>
<p class="text-lg text-gray-600 mt-2">Improve your prompts using AI-driven analysis based on expert research.</p>
</header>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
<!-- Left Panel: Workspace -->
<div class="bg-white p-6 rounded-xl shadow-md">
<h2 class="text-2xl font-bold mb-4">Your Workspace</h2>
<div class="space-y-6">
<div>
<label for="user-prompt" class="block text-sm font-medium text-gray-700 mb-1">1. Enter your prompt to analyze:</label>
<textarea id="user-prompt" rows="8" class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition" placeholder="e.g., Explain quantum computing."></textarea>
</div>
<div>
<label for="user-notes" class="block text-sm font-medium text-gray-700 mb-1">2. Add notes to clarify your goal (optional):</label>
<textarea id="user-notes" rows="4" class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition" placeholder="e.g., The target audience is high school students. The output should be a short, engaging paragraph."></textarea>
</div>
</div>
<div class="mt-6">
<h3 class="text-sm font-medium text-gray-700 mb-2">3. Select your expertise level:</h3>
<div class="flex flex-wrap gap-3">
<div class="custom-radio"><input type="radio" id="level-novice" name="level" value="Novice" class="sr-only" checked><label for="level-novice" class="custom-radio-label cursor-pointer px-4 py-2 border border-gray-300 rounded-lg text-center">👶 Novice Prompter</label></div>
<div class="custom-radio"><input type="radio" id="level-expert" name="level" value="Expert" class="sr-only"><label for="level-expert" class="custom-radio-label cursor-pointer px-4 py-2 border border-gray-300 rounded-lg text-center">🧑‍🔬 Expert Prompter</label></div>
<div class="custom-radio"><input type="radio" id="level-auto" name="level" value="Do it for Me" class="sr-only"><label for="level-auto" class="custom-radio-label cursor-pointer px-4 py-2 border border-gray-300 rounded-lg text-center">🤖 Do it for Me</label></div>
</div>
</div>
<div class="mt-8">
<button id="analyze-btn" class="w-full bg-blue-600 text-white font-bold py-3 px-4 rounded-lg hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition flex items-center justify-center">Analyze & Improve Prompt</button>
</div>
</div>
<!-- Right Panel: Suggestions -->
<div id="output-container" class="bg-white p-6 rounded-xl shadow-md flex items-center justify-center">
<div id="placeholder" class="text-center text-gray-500">
<svg class="mx-auto h-12 w-12 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" /></svg>
<h3 class="mt-2 text-sm font-medium text-gray-900">Analysis will appear here</h3>
<p class="mt-1 text-sm text-gray-500">Enter your prompt and click the button to get started.</p>
</div>
<div id="loader" class="hidden">
<div class="dots-loader">
<div class="dot1"></div><div class="dot2"></div><div class="dot3"></div>
</div>
<p class="text-center text-gray-500 mt-4">AI is analyzing your prompt...</p>
</div>
<div id="results" class="w-full hidden"><h2 class="text-2xl font-bold mb-4">Analysis & Suggestions</h2><div id="suggestions-list" class="space-y-4"></div></div>
<div id="error-message" class="hidden text-center text-red-600"><p>Sorry, an error occurred while analyzing the prompt. Please try again.</p></div>
</div>
</div>
</main>
<!-- How to Use Section -->
<section id="guide" class="py-16 bg-white">
<div class="container mx-auto px-4 sm:px-6 lg:px-8">
<h2 class="text-3xl font-bold text-center text-gray-800 mb-8">How to Use This Tool</h2>
<div class="max-w-4xl mx-auto grid md:grid-cols-3 gap-8 text-center">
<div>
<div class="flex items-center justify-center h-16 w-16 rounded-full bg-blue-100 text-blue-600 mx-auto mb-4 text-2xl font-bold">1</div>
<h3 class="text-xl font-semibold mb-2">Enter Your Prompt</h3>
<p class="text-gray-600">Start by typing or pasting the prompt you want to improve into the main text area. Be as specific as you can.</p>
</div>
<div>
<div class="flex items-center justify-center h-16 w-16 rounded-full bg-blue-100 text-blue-600 mx-auto mb-4 text-2xl font-bold">2</div>
<h3 class="text-xl font-semibold mb-2">Add Contextual Notes</h3>
<p class="text-gray-600">Use the optional 'Notes' field to clarify your goal. Who is the audience? What format do you want? This context is key to getting relevant suggestions.</p>
</div>
<div>
<div class="flex items-center justify-center h-16 w-16 rounded-full bg-blue-100 text-blue-600 mx-auto mb-4 text-2xl font-bold">3</div>
<h3 class="text-xl font-semibold mb-2">Get AI Suggestions</h3>
<p class="text-gray-600">Choose your expertise level and click 'Analyze'. The AI will provide tailored suggestions or even rewrite the prompt for you instantly.</p>
</div>
</div>
</div>
</section>
<!-- FAQ Section -->
<section id="faq" class="py-16">
<div class="container mx-auto px-4 sm:px-6 lg:px-8">
<h2 class="text-3xl font-bold text-center text-gray-800 mb-8">Frequently Asked Questions</h2>
<div class="max-w-3xl mx-auto space-y-6">
<div class="bg-white p-4 rounded-lg shadow-sm">
<h3 class="font-semibold text-lg">What is an AI Prompt Optimizer?</h3>
<p class="text-gray-600 mt-1">An AI Prompt Optimizer is a tool that analyzes your existing prompt and suggests improvements based on established principles of prompt engineering. Our tool uses AI to provide specific, actionable feedback to help you get better, more accurate, and more reliable results from large language models (LLMs).</p>
</div>
<div class="bg-white p-4 rounded-lg shadow-sm">
<h3 class="font-semibold text-lg">How does this prompt improver work?</h3>
<p class="text-gray-600 mt-1">You enter your prompt and optional notes about your goal. Our tool then securely calls an advanced AI model (Gemini) via a serverless function. The AI has been instructed with a framework based on 'The Prompt Report' to analyze your input and generate suggestions tailored to your selected expertise level, or even rewrite the prompt for you.</p>
</div>
<div class="bg-white p-4 rounded-lg shadow-sm">
<h3 class="font-semibold text-lg">Is this AI prompt optimizer free to use?</h3>
<p class="text-gray-600 mt-1">Yes, this tool is completely free to use. Our goal is to help developers, writers, and students learn how to craft better prompts.</p>
</div>
<div class="bg-white p-4 rounded-lg shadow-sm">
<h3 class="font-semibold text-lg">Why are notes important for improving my prompt?</h3>
<p class="text-gray-600 mt-1">Notes provide crucial context about your *intent*. A prompt like 'Explain photosynthesis' can be answered in many ways. By adding a note like 'for a 5th-grade class,' you guide the AI to optimize the prompt for simplicity and clarity, resulting in a much more useful output.</p>
</div>
</div>
</div>
</section>
<!-- Footer -->
<footer class="bg-gray-800 text-white">
<div class="container mx-auto px-4 sm:px-6 lg:px-8 py-6 text-center">
<p>© 2024 AI Prompt Optimizer. All Rights Reserved.</p>
<p class="text-sm text-gray-400 mt-1">Powered by research and AI.</p>
</div>
</footer>
<script>
document.addEventListener('DOMContentLoaded', function () {
const analyzeBtn = document.getElementById('analyze-btn');
const userPromptEl = document.getElementById('user-prompt');
const userNotesEl = document.getElementById('user-notes');
const outputContainer = document.getElementById('output-container');
const placeholder = document.getElementById('placeholder');
const loader = document.getElementById('loader');
const resultsContainer = document.getElementById('results');
const suggestionsList = document.getElementById('suggestions-list');
const errorMessage = document.getElementById('error-message');
const analyzePrompt = async () => {
const userPrompt = userPromptEl.value.trim();
if (!userPrompt) {
alert('Please enter a prompt to analyze.');
return;
}
const userNotes = userNotesEl.value.trim();
const selectedLevel = document.querySelector('input[name="level"]:checked').value;
placeholder.classList.add('hidden');
resultsContainer.classList.add('hidden');
errorMessage.classList.add('hidden');
loader.classList.remove('hidden');
analyzeBtn.disabled = true;
analyzeBtn.classList.add('opacity-50', 'cursor-not-allowed');
try {
// The API endpoint now points to our new rate-limited route.
const apiUrl = '/api/getpromptsuggestions';
const response = await fetch(apiUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
userPrompt,
userNotes,
level: selectedLevel
})
});
if (!response.ok) {
throw new Error(`API request failed with status ${response.status}`);
}
const parsedData = await response.json();
renderResults(parsedData, selectedLevel);
} catch (error) {
console.error('Error:', error);
errorMessage.classList.remove('hidden');
} finally {
loader.classList.add('hidden');
analyzeBtn.disabled = false;
analyzeBtn.classList.remove('opacity-50', 'cursor-not-allowed');
}
};
const renderResults = (data, level) => {
suggestionsList.innerHTML = '';
if (level === 'Do it for Me') {
const card = document.createElement('div');
card.className = 'suggestion-card bg-gray-50 p-4 rounded-lg border border-gray-200';
card.innerHTML = `
<h3>Improved Prompt</h3>
<div class="mt-2 p-3 bg-gray-200 text-gray-800 rounded-md whitespace-pre-wrap font-mono text-sm">${data.improved_prompt}</div>
<h3 class="mt-4">Explanation of Changes</h3>
<div class="prose prose-sm mt-2 max-w-none">${DOMPurify.sanitize(marked.parse(data.explanation))}</div>
<button onclick="copyToClipboard(this.previousElementSibling.previousElementSibling.innerText)" class="mt-4 bg-blue-100 text-blue-800 text-xs font-semibold px-2.5 py-1.5 rounded hover:bg-blue-200">Copy Prompt</button>
`;
suggestionsList.appendChild(card);
} else {
data.suggestions.forEach(suggestion => {
const card = document.createElement('div');
card.className = 'suggestion-card bg-gray-50 p-4 rounded-lg border border-gray-200';
let techniqueTag = '';
if (suggestion.technique) {
techniqueTag = `<span class="bg-blue-100 text-blue-800 text-xs font-semibold mr-2 px-2.5 py-0.5 rounded">${suggestion.technique}</span>`;
}
card.innerHTML = `
<div class="flex items-center mb-2">
${techniqueTag}
<h3>${suggestion.title}</h3>
</div>
<div class="prose prose-sm max-w-none">${DOMPurify.sanitize(marked.parse(suggestion.description))}</div>
`;
suggestionsList.appendChild(card);
});
}
resultsContainer.classList.remove('hidden');
};
window.copyToClipboard = async (text) => {
try {
await navigator.clipboard.writeText(text);
alert('Prompt copied to clipboard!');
} catch (err) {
console.error('Failed to copy text: ', err);
alert('Failed to copy prompt to clipboard.');
}
};
analyzeBtn.addEventListener('click', analyzePrompt);
});
</script>
</body>
</html>