-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from Sid-80/gemini-model
feat: gemini model
- Loading branch information
Showing
5 changed files
with
174 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { motion } from 'framer-motion' | ||
|
||
export default function PromptLoader() { | ||
return ( | ||
<div className="flex items-center justify-center"> | ||
<div className="flex space-x-2"> | ||
<motion.div | ||
className="h-3 w-3 rounded-full bg-red-500" | ||
animate={{ | ||
scale: [1, 1.5, 1], | ||
opacity: [0.5, 1, 0.5], | ||
}} | ||
transition={{ | ||
duration: 1, | ||
ease: 'easeInOut', | ||
repeat: Infinity, | ||
}} | ||
/> | ||
<motion.div | ||
className="h-3 w-3 rounded-full bg-red-500" | ||
animate={{ | ||
scale: [1, 1.5, 1], | ||
opacity: [0.5, 1, 0.5], | ||
}} | ||
transition={{ | ||
duration: 1, | ||
ease: 'easeInOut', | ||
repeat: Infinity, | ||
delay: 0.3, | ||
}} | ||
/> | ||
<motion.div | ||
className="h-3 w-3 rounded-full bg-red-500" | ||
animate={{ | ||
scale: [1, 1.5, 1], | ||
opacity: [0.5, 1, 0.5], | ||
}} | ||
transition={{ | ||
duration: 1, | ||
ease: 'easeInOut', | ||
repeat: Infinity, | ||
delay: 0.6, | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { GoogleGenerativeAI } from "@google/generative-ai"; | ||
|
||
const MODEL_NAME = "gemini-1.0-pro"; | ||
const API_KEY = process.env.NEXT_PUBLIC_GEMINI_API_KEY; | ||
|
||
async function runChat( | ||
prompt: string, | ||
generateDocs: boolean, | ||
generateFlowchart: boolean | ||
) { | ||
if (!API_KEY || API_KEY === "your-gemini-api-key") | ||
throw new Error("Invalid Api Key!"); | ||
|
||
const genAI = new GoogleGenerativeAI(API_KEY); | ||
const model = genAI.getGenerativeModel({ model: MODEL_NAME }); | ||
|
||
model.generationConfig = { | ||
temperature: 0.9, | ||
topK: 1, | ||
topP: 1, | ||
}; | ||
|
||
const chat = model.startChat({ | ||
history: [ | ||
{ | ||
role: "user", | ||
parts: [ | ||
{ | ||
text: `You are expert in generating documentation and flowcharts. While generating documentation add detailed working of given prompt and generate the flowcharts in mermaid code format. Generate the flowchart in the mermaid code format.`, | ||
}, | ||
], | ||
}, | ||
{ | ||
role: "model", | ||
parts: [{ text: "How can I help you ?" }], | ||
}, | ||
], | ||
}); | ||
|
||
let newPrompt; | ||
|
||
if (generateDocs && generateFlowchart) { | ||
newPrompt = `Generate documentation as well as flowchart for following problem statement. Problem Statement : ${prompt}`; | ||
} else if (generateDocs) { | ||
newPrompt = `Generate documentation for following problem statement. Problem Statement : ${prompt}`; | ||
} else if (generateFlowchart) { | ||
newPrompt = `Generate flowchart for following problem statement. Problem Statement : ${prompt}`; | ||
} | ||
|
||
if(!generateDocs && !generateFlowchart) throw new Error("No options selected!"); | ||
|
||
const result = await chat.sendMessage(newPrompt!); | ||
const response = result.response; | ||
console.log(response.text()); | ||
return response.text(); | ||
} | ||
|
||
export default runChat; |