Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AI and Automation Enhancements #296

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import NotFound from "./component/NotFound";
import ProgressBar from "./component/ProgressBar/ProgressBar";
import AOS from 'aos';
import 'aos/dist/aos.css';
import Ai from "./component/AI";
import FAQ from "./component/FAQ"; // Import the FAQ component

// Main Layout Component
Expand Down Expand Up @@ -137,6 +138,8 @@ function App() {
<Route exact path="/community" element={<Community mode={mode} setProgress={setProgress} showAlert={showAlert} />} />
<Route exact path="/about" element={<About mode={mode} setProgress={setProgress} showAlert={showAlert} />} />
<Route exact path='/blog' element={<BlogPage mode={mode} setProgress={setProgress} showAlert={showAlert} />} />
<Route exact path='/ai' element={<Ai mode={mode} setProgress={setProgress} showAlert={showAlert} />} />
{/* <Route exact path='/myprofile' element={<ProtectedRoute loggedin={islogged}><MyProfile mode={mode} setProgress={setProgress} showAlert={showAlert} /></ProtectedRoute>} /> */}
<Route exact path='/myprofile' element={<MyProfile mode={mode} setProgress={setProgress} showAlert={showAlert} />} />
<Route exact path='/editprofile' element={<EditProfile mode={mode} setProgress={setProgress} showAlert={showAlert} />} />
<Route exact path='/contributors' element={<Contributors mode={mode} setProgress={setProgress} showAlert={showAlert} />} />
Expand Down
98 changes: 98 additions & 0 deletions client/src/component/Ai.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { useState } from "react";
import { GoogleGenerativeAI } from "@google/generative-ai";

const Ai = () => {
const [apiKey, setApiKey] = useState("");
const [codeInput, setCodeInput] = useState("");
const [projectType, setProjectType] = useState("");
const [reviewResult, setReviewResult] = useState("");
const [ideaResult, setIdeaResult] = useState("");
const [error, setError] = useState("");

const handleInput = async (type) => {
if (!apiKey) {
setError("API Key is required");
return;
}

setError("");
try {
const genAI = new GoogleGenerativeAI(apiKey);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });

if (type === "review") {
const prompt =
"Review the following code and provide feedback. \n\n" + codeInput;

const result = await model.generateContent(prompt);
setReviewResult(result.response.text());
} else if (type === "ideas") {
const prompt =
"Generate project ideas for a " + projectType + " project.";
const result = await model.generateContent(prompt);
setIdeaResult(result.response.text());
}
} catch (err) {
setError("An error occurred while processing your request.");
}
};

return (
<div className="p-6 min-h-screen text-black overflow-auto main-content">
{/* API Key Input */}
<div className="mb-4">
<input
type="text"
value={apiKey}
onChange={(e) => setApiKey(e.target.value)}
placeholder="Enter your Gemini API Key"
className="w-full p-2 border border-gray-300 rounded text-black"
/>
</div>

{/* Code Review Section */}
<div className="mb-6">
<h3 className="text-xl font-semibold mb-2">AI Code Review</h3>
<textarea
value={codeInput}
onChange={(e) => setCodeInput(e.target.value)}
placeholder="Paste your code here..."
className="w-full p-2 border rounded mb-2 text-black"
/>
<button
onClick={() => handleInput("review")}
className="px-4 py-2 rounded bg-blue-400 hover:bg-blue-600"
>
Review Code
</button>
{reviewResult && <pre className="mt-4 p-2 rounded">{reviewResult}</pre>}
</div>

{/* Project Ideas Section */}
<div className="mb-6">
<h3 className="text-xl font-semibold mb-2">AI Project Ideas</h3>
<input
type="text"
value={projectType}
onChange={(e) => setProjectType(e.target.value)}
placeholder="Enter project type (e.g., web app, mobile app)"
className="w-full p-2 border rounded mb-2 text-black"
/>
<button
onClick={() => handleInput("ideas")}
className="px-4 py-2 bg-green-500 rounded hover:bg-green-600"
>
Generate Ideas
</button>
{ideaResult && (
<pre className="mt-4 p-2 border rounded">{ideaResult}</pre>
)}
</div>

{/* Error Message */}
{error && <p className="text-red-500">{error}</p>}
</div>
);
};

export default Ai;
4 changes: 4 additions & 0 deletions client/src/css/Navbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -535,4 +535,8 @@

.rnav {
display: flex;
}

.main-content {
margin-top: 10vh;
}
Loading