STEM-E-Youth-Career-Development-Program / app-7

MIT License
1 stars 11 forks source link

Implement Gemini API #18

Closed MenlyCSE closed 3 months ago

MenlyCSE commented 3 months ago

Use Google's API to generate or summarize text in our HTML, CSS, and JavaScript webpage.

Do whatever you'd like as long as you are using Google's API

SachchitBalamurugan commented 3 months ago

Image

Implemented a better UI for the Gemini API website, and everything other then the input and summarize button are placeholders for now. Using the API and uses User input to generate AI responses

randompotato0112 commented 3 months ago
const {VertexAI} = require('@google-cloud/vertexai');

/**
 * TODO(developer): Update these variables before running the sample.
 */
async function analyze_pdf(projectId = 'PROJECT_ID') {
  const vertexAI = new VertexAI({project: projectId, location: 'us-central1'});

  const generativeModel = vertexAI.getGenerativeModel({
    model: 'gemini-1.5-flash-001',
  });

  const filePart = {
    file_data: {
      file_uri: 'gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf',
      mime_type: 'application/pdf',
    },
  };
  const textPart = {
    text: `
    You are a very professional document summarization specialist.
    Please summarize the given document.`,
  };

  const request = {
    contents: [{role: 'user', parts: [filePart, textPart]}],
  };

  const resp = await generativeModel.generateContent(request);
  const contentResponse = await resp.response;
  console.log(JSON.stringify(contentResponse));
}

It's hard to find a pure JavaScript approach for PDF uploads, but I found this Node.js approach that seems to work pretty well. This one logs the response to the console but it easy to update the website with it. A similar approach can be used to upload the regular prompts too.