diff --git a/src/features/gemini/gemini.js b/src/features/gemini/gemini.js new file mode 100644 index 0000000..60ab8c1 --- /dev/null +++ b/src/features/gemini/gemini.js @@ -0,0 +1,4 @@ +import { createPartFromUri, GoogleGenAI } from "@google/genai" +import 'dotenv/config' + +const ai = new GoogleGenAI({ apiKey: ${} }) \ No newline at end of file diff --git a/web-app/package.json b/web-app/package.json index 91388fc..7027cf2 100644 --- a/web-app/package.json +++ b/web-app/package.json @@ -1,5 +1,6 @@ { "name": "codered-astra", + "type": "module", "private": true, "scripts": { "build": "vite build", diff --git a/web-app/public/pdfs/SRHB.pdf b/web-app/public/pdfs/SRHB.pdf new file mode 100644 index 0000000..5bb4f78 Binary files /dev/null and b/web-app/public/pdfs/SRHB.pdf differ diff --git a/web-app/public/pdfs/falcon-users-guide-2025-05-09.pdf b/web-app/public/pdfs/falcon-users-guide-2025-05-09.pdf new file mode 100644 index 0000000..4d835a6 Binary files /dev/null and b/web-app/public/pdfs/falcon-users-guide-2025-05-09.pdf differ diff --git a/web-app/public/pdfs/spacex-falcon-9-data-sheet.pdf b/web-app/public/pdfs/spacex-falcon-9-data-sheet.pdf new file mode 100644 index 0000000..d6ce2ae Binary files /dev/null and b/web-app/public/pdfs/spacex-falcon-9-data-sheet.pdf differ diff --git a/web-app/public/pdfs/system-safety-handbook.pdf b/web-app/public/pdfs/system-safety-handbook.pdf new file mode 100644 index 0000000..7d076f2 Binary files /dev/null and b/web-app/public/pdfs/system-safety-handbook.pdf differ diff --git a/web-app/src/features/gemini/gemini.js b/web-app/src/features/gemini/gemini.js new file mode 100644 index 0000000..4e2d761 --- /dev/null +++ b/web-app/src/features/gemini/gemini.js @@ -0,0 +1,65 @@ +import { createPartFromUri, GoogleGenAI } from "@google/genai" +import 'dotenv/config' +import fs from "fs" + +const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY }) + +async function uploadLocalPDFs() { + var pdfList = fs.readdirSync("public/pdfs") + + // Upload each file in /public + pdfList.forEach(async (path) => { + console.log("file names: " + path) + console.log("file names: " + path.slice(0, path.length - 4)) + + console.log("UPLOADING") + const file = await ai.files.upload({ + file: "public/pdfs/" + path, + config: { + displayName: path.slice(0, path.length - 4) + } + }) + + console.log("FETCHING: public/pdfs/" + path) + + // Wait for the file to be processed + let getFile = await ai.files.get({ + name: file.name + }) + + while (getFile.state === "PROCESSING") { + let getFile = await ai.files.get({ + name: file.name + }) + console.log(`Current file status: ${getFile.state}`) + console.log("File is currently processing, retrying in 5 seconds") + + await new Promise((resolve) => { + setTimeout(resolve, 5000) // Checks every 5 seconds + }) + + // Error handling + if (getFile.state === "FAILED") { + throw new Error("File has failed to process!") + } + 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() +