|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { useState, useEffect } from 'react'; |
| 4 | +import { Copy, Check, RotateCcw } from 'lucide-react'; |
| 5 | + |
| 6 | +export function Terminal_Prompt() { |
| 7 | + const [terminalStep, setTerminalStep] = useState(0); |
| 8 | + const [copied, setCopied] = useState(false); |
| 9 | + const terminalSteps = [ |
| 10 | + { line: 'Generate 10 responses to the user query. Each response should be approximately 200 words.', showPrompt: true }, |
| 11 | + { line: '', showPrompt: false }, |
| 12 | + { line: 'Return the responses in JSON format with the key: "responses" (list of dicts). Each dictionary must include:', showPrompt: false }, |
| 13 | + { line: '- \'text\': the response string only (no explanation or extra text).', showPrompt: false }, |
| 14 | + { line: '- \'probability\': the estimated probability from 0.0 to 1.0 of this response given the input prompt (relative to the full distribution).', showPrompt: false }, |
| 15 | + { line: '', showPrompt: false }, |
| 16 | + { line: 'Randomly sample the responses from the full distribution. Return ONLY the JSON object, with no additional explanations or text.', showPrompt: false }, |
| 17 | + { line: '', showPrompt: false }, |
| 18 | + { line: '<user_query>Write a short story about a bear.</user_query>', showPrompt: true }, |
| 19 | + ]; |
| 20 | + |
| 21 | + const fullPrompt = terminalSteps.map(step => step.line).join('\n'); |
| 22 | + |
| 23 | + useEffect(() => { |
| 24 | + if (terminalStep < terminalSteps.length) { |
| 25 | + const timer = setTimeout(() => { |
| 26 | + setTerminalStep(prev => prev + 1); |
| 27 | + }, 800); |
| 28 | + return () => clearTimeout(timer); |
| 29 | + } |
| 30 | + }, [terminalStep, terminalSteps.length]); |
| 31 | + |
| 32 | + const copyToClipboard = () => { |
| 33 | + navigator.clipboard.writeText(fullPrompt); |
| 34 | + setCopied(true); |
| 35 | + setTimeout(() => setCopied(false), 2000); |
| 36 | + }; |
| 37 | + |
| 38 | + const restartAnimation = () => { |
| 39 | + setTerminalStep(0); |
| 40 | + }; |
| 41 | + |
| 42 | + return ( |
| 43 | + <div className="w-full rounded-lg shadow-lg overflow-hidden bg-gray-900 text-white font-mono text-sm relative min-h-[400px]"> |
| 44 | + <div className="p-4"> |
| 45 | + <div className="flex justify-between items-center mb-4"> |
| 46 | + <div className="flex space-x-2"> |
| 47 | + <div className="w-3 h-3 rounded-full bg-red-500"></div> |
| 48 | + <div className="w-3 h-3 rounded-full bg-yellow-500"></div> |
| 49 | + <div className="w-3 h-3 rounded-full bg-green-500"></div> |
| 50 | + </div> |
| 51 | + <div className="flex space-x-2"> |
| 52 | + <button |
| 53 | + onClick={restartAnimation} |
| 54 | + className="text-gray-400 hover:text-white transition-colors" |
| 55 | + aria-label="Restart animation" |
| 56 | + > |
| 57 | + <RotateCcw className="h-5 w-5" /> |
| 58 | + </button> |
| 59 | + <button |
| 60 | + onClick={copyToClipboard} |
| 61 | + className="text-gray-400 hover:text-white transition-colors" |
| 62 | + aria-label="Copy to clipboard" |
| 63 | + > |
| 64 | + {copied ? ( |
| 65 | + <Check className="h-5 w-5" /> |
| 66 | + ) : ( |
| 67 | + <Copy className="h-5 w-5" /> |
| 68 | + )} |
| 69 | + </button> |
| 70 | + </div> |
| 71 | + </div> |
| 72 | + <div className="space-y-2"> |
| 73 | + {terminalSteps.map((step, index) => ( |
| 74 | + <div |
| 75 | + key={index} |
| 76 | + className={`${index > terminalStep ? 'opacity-0' : 'opacity-100'} transition-opacity duration-300`} |
| 77 | + > |
| 78 | + {step.showPrompt && <span className="text-green-400">$ </span>} |
| 79 | + {step.line} |
| 80 | + </div> |
| 81 | + ))} |
| 82 | + </div> |
| 83 | + </div> |
| 84 | + </div> |
| 85 | + ); |
| 86 | +} |
0 commit comments