MCPcopy Create free account
hub / github.com/Bitbox-Connect/Bitbox / Ai

Function Ai

client/src/component/AIReview.jsx:4–98  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { GoogleGenerativeAI } from "@google/generative-ai";
3
4const Ai = () => {
5 const [apiKey, setApiKey] = useState("");
6 const [codeInput, setCodeInput] = useState("");
7 const [projectType, setProjectType] = useState("");
8 const [reviewResult, setReviewResult] = useState("");
9 const [ideaResult, setIdeaResult] = useState("");
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">
42 {/* Heading */}
43 <h1 className="text-4xl font-semibold mb-4">AI Playground</h1>
44 {/* API Key Input */}
45 <div className="mb-4">
46 <input
47 type="text"
48 value={apiKey}
49 onChange={(e) => setApiKey(e.target.value)}
50 placeholder="Enter your Gemini API Key"
51 className="w-full p-2 border border-gray-300 rounded text-black"
52 />
53 </div>
54
55 {/* Code Review Section */}
56 <div className="mb-6">
57 <h3 className="text-xl font-semibold mb-2">AI Code Review</h3>
58 <textarea
59 value={codeInput}
60 onChange={(e) => setCodeInput(e.target.value)}
61 placeholder="Paste your code here..."

Callers

nothing calls this directly

Calls 1

handleInputFunction · 0.85

Tested by

no test coverage detected