feat: adding gemini stuff
This commit is contained in:
parent
af7a246e77
commit
76cb0e0536
4 changed files with 44 additions and 24 deletions
|
|
@ -3,6 +3,20 @@ import ChatHeader from "src/components/ui/chat/chat-header";
|
|||
import ChatWindow from "src/components/ui/chat/chat-window";
|
||||
import MessageInput from "src/components/ui/chat/message-input";
|
||||
|
||||
import { GoogleGenAI } from "@google/genai"
|
||||
|
||||
const ai = new GoogleGenAI({ apiKey: import.meta.env.GEMINI_API_KEY })
|
||||
|
||||
async function AIRepsponse(userInputArray) {
|
||||
const response = await ai.models.generateContent({
|
||||
model: "gemini-2.5-flash",
|
||||
contents: userInputArray
|
||||
})
|
||||
return response.text
|
||||
}
|
||||
|
||||
let userInput = []
|
||||
|
||||
export default function ChatLayout() {
|
||||
const [messages, setMessages] = useState([
|
||||
{
|
||||
|
|
@ -11,15 +25,17 @@ export default function ChatLayout() {
|
|||
},
|
||||
]);
|
||||
|
||||
function handleSend(text) {
|
||||
async function handleSend(text) {
|
||||
userInput.push(text)
|
||||
const res = await AIRepsponse(userInput)
|
||||
|
||||
const userMsg = { role: "user", content: text };
|
||||
setMessages((s) => [...s, userMsg]);
|
||||
|
||||
// fake assistant reply after short delay
|
||||
setTimeout(() => {
|
||||
setMessages((s) => [
|
||||
...s,
|
||||
{ role: "assistant", content: `You said: ${text}` },
|
||||
{ role: "assistant", content: res },
|
||||
]);
|
||||
}, 600);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import { createPartFromUri, GoogleGenAI } from "@google/genai"
|
||||
import 'dotenv/config'
|
||||
import { GoogleGenAI } from "@google/genai"
|
||||
import fs from "fs"
|
||||
|
||||
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY })
|
||||
const ai = new GoogleGenAI({ apiKey: import.meta.env.GEMINI_API_KEY })
|
||||
|
||||
async function uploadLocalPDFs() {
|
||||
var pdfList = fs.readdirSync("public/pdfs")
|
||||
|
|
@ -45,21 +44,4 @@ async function uploadLocalPDFs() {
|
|||
return file
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const prompts = [
|
||||
"If possible, using Gemini's Javascript API, how would you grab an image from a PDF sent to the API?"
|
||||
]
|
||||
|
||||
const response = await ai.models.generateContent({
|
||||
model: "gemini-2.5-flash",
|
||||
contents: prompts
|
||||
})
|
||||
|
||||
console.log(response.text)
|
||||
}
|
||||
|
||||
uploadLocalPDFs()
|
||||
main()
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue