This article will walk you through the process of effortlessly integrating Google Gemini into the SharePoint Framework (SPFx), so you can use its strong features within your SharePoint environment. Whether you want to optimize content management, or increase overall user engagement, this step-by-step tutorial will provide you with the information and resources you need to get started with Google Gemini in SPFx.
These steps will also be useful for integrating Google Gemini Pro AI with React application.
Get the API key:
Initially, you'll require an API key. This key serves as your identification to Google Gemini, enabling authentication on your behalf. Create a API Key from Google AI Studio Click here
Now follow the steps mentioned below:
- Create a SPFx web part.
- Installing the "GoogleGenerativeAI" package for Node.js is necessary in order to utilize the Gemini API in your SPFx Webpart
npm install @google/generative-ai - Now we need to initialize the generative model, add this line after our other imports in SPFx
const { GoogleGenerativeAI } = require("@google/generative-ai"); - Now assign the key which you have created from the Google AI Studio
const genAIModal = new GoogleGenerativeAI("API Key");
use the key generated from the studio to replace the API key.
const geminiModel = genAIModal.getGenerativeModel({ model: "gemini-pro" });
I'm using the "gemini-pro" model for my blog, but you can modify it to suit your needs. - Now give the prompt to Google Gemini and generate content.
private async generateContentFromLLM()
{
let promptToAnswerQuery =`Generate quotes for the friendship`;
try
{
const result = await geminiModel.generateContent(promptToAnswerQuery);
const response = await result.response;
const text = response.text();
}
catch(error)
{
console.log("Error while getting answer from LLM" + error);
}
}
Source : https://ai.google.dev/gemini-api/docs/quickstart
How to handle special characters in Rest API
SPFx interview questions
Comments
Post a Comment