| 10 | const [error, setError] = useState(""); |
| 11 | |
| 12 | const handleInput = async (type) => { |
| 13 | if (!apiKey) { |
| 14 | setError("API Key is required"); |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | setError(""); |
| 19 | try { |
| 20 | const genAI = new GoogleGenerativeAI(apiKey); |
| 21 | const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" }); |
| 22 | |
| 23 | if (type === "review") { |
| 24 | const prompt = |
| 25 | "Review the following code and provide feedback. \n\n" + codeInput; |
| 26 | |
| 27 | const result = await model.generateContent(prompt); |
| 28 | setReviewResult(result.response.text()); |
| 29 | } else if (type === "ideas") { |
| 30 | const prompt = |
| 31 | "Generate project ideas for a " + projectType + " project."; |
| 32 | const result = await model.generateContent(prompt); |
| 33 | setIdeaResult(result.response.text()); |
| 34 | } |
| 35 | } catch (err) { |
| 36 | setError("An error occurred while processing your request."); |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | return ( |
| 41 | <div className="p-6 min-h-screen flex flex-col justify-center text-black overflow-auto main-content"> |