|
| 1 | +import { useState } from 'react'; |
| 2 | + |
| 3 | +export const AskAI = () => { |
| 4 | + const [question, setQuestion] = useState(''); |
| 5 | + |
| 6 | + const basePrompt = 'Search https://docs.bytez.com and answer: '; |
| 7 | + const encodedPrompt = encodeURIComponent(basePrompt + question); |
| 8 | + |
| 9 | + const links = [ |
| 10 | + { name: 'ChatGPT', url: `https://chatgpt.com/?q=${encodedPrompt}` }, |
| 11 | + { name: 'Claude', url: `https://claude.ai/new?q=${encodedPrompt}` }, |
| 12 | + { name: 'Perplexity', url: `https://www.perplexity.ai/search?q=${encodedPrompt}` }, |
| 13 | + ]; |
| 14 | + const handleKeyDown = (e) => { |
| 15 | + if (e.key === 'Enter' && question) { |
| 16 | + window.open(`https://chatgpt.com/?q=${encodeURIComponent(basePrompt + question)}`, '_blank'); |
| 17 | + } |
| 18 | + }; |
| 19 | + |
| 20 | + return ( |
| 21 | + <div |
| 22 | + style={{ |
| 23 | + background: 'rgba(30, 32, 44, 0.6)', |
| 24 | + border: '1px solid rgba(96, 115, 191, 0.3)', |
| 25 | + borderRadius: '12px', |
| 26 | + padding: '24px', |
| 27 | + marginBottom: '24px', |
| 28 | + }} |
| 29 | + > |
| 30 | + <h3 style={{ margin: '0 0 8px 0', fontSize: '1.25rem', color: '#D0BCFF' }}> |
| 31 | + Ask AI about Bytez |
| 32 | + </h3> |
| 33 | + <p style={{ margin: '0 0 16px 0', opacity: 0.7, fontSize: '0.9rem' }}> |
| 34 | + Get instant answers from our docs |
| 35 | + </p> |
| 36 | + |
| 37 | + <input |
| 38 | + type="text" |
| 39 | + placeholder="How do I run a model?" |
| 40 | + value={question} |
| 41 | + onChange={(e) => setQuestion(e.target.value)} |
| 42 | + onKeyDown={handleKeyDown} |
| 43 | + style={{ |
| 44 | + width: '100%', |
| 45 | + padding: '12px 16px', |
| 46 | + fontSize: '1rem', |
| 47 | + marginTop: 8, |
| 48 | + border: '1px solid rgba(96, 115, 191, 0.3)', |
| 49 | + borderRadius: '8px', |
| 50 | + background: 'rgba(0,0,0,0.3)', |
| 51 | + color: 'inherit', |
| 52 | + marginBottom: '16px', |
| 53 | + boxSizing: 'border-box', |
| 54 | + }} |
| 55 | + /> |
| 56 | + |
| 57 | + <div style={{ display: 'flex', gap: '12px', flexWrap: 'wrap' }}> |
| 58 | + {links.map(({ name, url }) => ( |
| 59 | + <a |
| 60 | + key={name} |
| 61 | + href={question ? url : '#'} |
| 62 | + target="_blank" |
| 63 | + rel="noopener noreferrer" |
| 64 | + onClick={(e) => !question && e.preventDefault()} |
| 65 | + style={{ |
| 66 | + display: 'inline-flex', |
| 67 | + alignItems: 'center', |
| 68 | + gap: '8px', |
| 69 | + padding: '10px 20px', |
| 70 | + background: question ? '#E8DEF8' : 'rgba(96, 115, 191, 0.3)', |
| 71 | + color: question ? '#332D41' : 'white', |
| 72 | + borderRadius: '8px', |
| 73 | + textDecoration: 'none', |
| 74 | + fontWeight: 500, |
| 75 | + fontSize: '0.9rem', |
| 76 | + opacity: question ? 1 : 0.5, |
| 77 | + cursor: question ? 'pointer' : 'not-allowed', |
| 78 | + transition: 'all 0.2s', |
| 79 | + }} |
| 80 | + > |
| 81 | + {name} |
| 82 | + </a> |
| 83 | + ))} |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + ); |
| 87 | +}; |
0 commit comments