1. शुरू करने से पहले
इस कोडलैब में, आपको Gemini API की फ़ंक्शन-कॉलिंग और मल्टी-मॉडल सुविधाओं का इस्तेमाल करके, Google Workspace के टास्क को ऑटोमेट करने का तरीका बताया गया है.
ज़रूरी शर्तें
- Apps Script, JavaScript या इसी तरह की किसी प्रोग्रामिंग भाषा की बुनियादी जानकारी
आपको ये सब सीखने को मिलेगा
- Gemini API की फ़ंक्शन कॉलिंग और मल्टी-मॉडल सुविधाओं का इस्तेमाल कैसे करें.
- Gemini API के कई कॉल को एक साथ कैसे जोड़ें.
- Gemini API की मदद से, Google Workspace के टास्क को ऑटोमेट करने का तरीका.
आपको इन चीज़ों की ज़रूरत पड़ेगी
- वेब ब्राउज़र.
- एक Gmail खाता. इसके अलावा, ऐसा Google Workspace खाता जिसमें Gemini API का खास सेटअप लागू किया गया हो.
- Gemini API के लिए, उन देशों या इलाकों में से किसी एक से कनेक्शन होना चाहिए जहाँ यह सुविधा उपलब्ध है.
- वैकल्पिक: डायरेक्ट एपीआई अनुरोधों की जांच करने के लिए,
curlप्रोग्राम के साथ कमांड-लाइन इंटरफ़ेस.
इस कोडलैब का पूरा कोड, GitHub पर Gemini API की कुकबुक में उपलब्ध है. अगर आपको पूरा कोड चाहिए, तो इसे देखें.
2. Gemini API सेट अप करना
Gemini के बारे में जानकारी
Gemini मॉडल, Google के सबसे बड़े और सबसे बेहतरीन एआई मॉडल हैं. अपने ऐप्लिकेशन में इन मॉडल का फ़ायदा पाने के लिए, Gemini API का इस्तेमाल किया जा सकता है. Gemini API को Google AI Studio में भी आज़माया जा सकता है. यह एपीआई के लिए एक वेब इंटरफ़ेस है. इसमें प्रॉम्प्ट आज़माए जा सकते हैं, मॉडल की सेटिंग में बदलाव किया जा सकता है, और कस्टम मॉडल को बिना कोई कोड लिखे ट्यून किया जा सकता है.
कुंजी पाना
- Gemini API का इस्तेमाल करने के लिए, Google AI Studio में एपीआई पासकोड बनाएं.
ज़रूरी नहीं: कार के डिजिटल बटन की जांच करना
अगर आपके पास curl के साथ कमांड-लाइन का ऐक्सेस है, तो नीचे दिए गए ब्लॉक की पहली लाइन में अपनी कुंजी जोड़ें. इसके बाद, एपीआई कुंजी की जांच करने के लिए, इसे अपने टर्मिनल में चलाएं.
export GOOGLE_API_KEY=Paste_your_API_key_here
curl "https://generativelanguage.googleapis.com/v1beta/models?key=${GOOGLE_API_KEY}"
आपको JSON फ़ॉर्मैट में मॉडल की सूची दिखेगी. जैसे, models/gemini-1.0-pro. इसका मतलब है कि यह काम कर गया.
3. ज़रूरी नहीं: Gemini API से अनुरोध करना
इस वैकल्पिक चरण में, Gemini API से अनुरोध किया जाता है, ताकि Apps Script ऐप्लिकेशन में कॉन्टेंट जोड़ने से पहले, यह बेहतर तरीके से समझा जा सके कि कॉन्टेंट जनरेट करने की सुविधा कैसे काम करती है.
मॉडल के बारे में जानकारी
Gemini API में कई मॉडल उपलब्ध हैं. इनकी क्षमताएं और सीमाएं अलग-अलग होती हैं. हर मॉडल को उसकी क्षमताओं के साथ, Gemini मॉडल पेज पर लिस्ट किया गया है.
पहला अनुरोध करना
Gemini API से टेक्स्ट प्रॉम्प्ट पूरा कराने के लिए, एक JSON अनुरोध बनाया जाता है. इसके बाद, इसे REST API के एंडपॉइंट पर भेजा जाता है.
ऐसा करने के लिए, इन चरणों का अनुसरण करें:
- नई फ़ाइल में, यह JSON अनुरोध डालें:
{
contents: [
{
parts: [
{ text: 'The most important aspects of a persuasive presentation are:' }
]
}
]
}
JSON अनुरोध में यह प्रॉम्प्ट शामिल है: The most important aspects of a persuasive presentation are:. मॉडल इस निर्देश को पूरा करेगा और आपको सीधे तौर पर नतीजा देगा.
JSON अनुरोध में, टॉप लेवल के तीन फ़ील्ड होते हैं: contents, generationConfig, और safetySettings. सिर्फ़ contents की ज़रूरत होती है. अन्य कुकी, आउटपुट को कंट्रोल करने के तरीके उपलब्ध कराती हैं.
- इस JSON को
presentation.txtफ़ाइल में सेव करें. इसके बाद, इसे सीधेcurlको इस तरह पास करें:
curl -H 'Content-Type: application/json' -X POST -d @presentation.txt \
'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.0-pro-latest:generateContent?key='${GOOGLE_API_KEY}
इस उदाहरण में, यूआरएल में ये वैल्यू सेट की गई हैं:
v1betaएपीआई वर्शन के बारे में बताता है.gemini-1.0-pro-latestमें Gemini 1.0 Pro को मॉडल के तौर पर चुना गया है और इसमें नए स्नैपशॉट का इस्तेमाल किया गया है.generateContentसे उस एपीआई तरीके के बारे में पता चलता है जिसे कॉल किया जाता है.
आपको कुछ ऐसे नतीजे दिखेंगे:
{
"candidates": [
{
"content": {
"parts": [
{
"text": "* **Credibility:** The audience must trust that you are an expert on the subject matter and that you have their best interests at heart.\n* **Clearness:** Your message must be easy to understand and follow. Avoid using jargon or technical terms that your audience may not be familiar with.\n* **Concreteness:** Use specific examples and data to support your arguments. Avoid making vague or general claims.\n* **Emotional appeal:** In addition to appealing to the audience's logical side, you should also try to connect with them on an emotional level. Use storytelling, humor, and personal anecdotes to make your points more memorable and engaging.\n* **Strong closing:** End your presentation with a strong call to action. Tell the audience what you want them to do and why it is important for them to do it."
}
],
"role": "model"
},
"finishReason": "STOP",
"index": 0,
"safetyRatings": [...]
}
],
"promptFeedback": {
"safetyRatings": [...]
}
}
पढ़ने में आसानी हो, इसके लिए यहां टर्मिनल आउटपुट को नियमित तौर पर फ़ॉर्मैट किया गया है:
- भरोसेमंद होना: ऑडियंस को यह भरोसा होना चाहिए कि आप विषय के विशेषज्ञ हैं और आपने उनकी पसंद को ध्यान में रखकर ही कॉन्टेंट बनाया है.
- साफ़ तौर पर: आपका मैसेज समझने और उसका पालन करने में आसान होना चाहिए. ऐसी मुश्किल शब्दावली या तकनीकी शब्दों का इस्तेमाल न करें जिनके बारे में आपकी ऑडियंस को जानकारी न हो.
- ठोस जानकारी: अपने तर्कों के पक्ष में, खास उदाहरण और डेटा का इस्तेमाल करें. अस्पष्ट या सामान्य दावे करने से बचें.
- भावनाओं से जुड़ाव: ऑडियंस के तार्किक पक्ष को ध्यान में रखने के साथ-साथ, आपको उनसे भावनात्मक तौर पर भी जुड़ने की कोशिश करनी चाहिए. अपनी बातों को ज़्यादा यादगार और दिलचस्प बनाने के लिए, कहानी कहने के तरीके, हास्य, और निजी अनुभवों का इस्तेमाल करें.
- बेहतर क्लोज़िंग: अपने प्रज़ेंटेशन के आखिर में, कॉल-टू-ऐक्शन का इस्तेमाल करें. दर्शकों को बताएं कि आपको उनसे क्या काम करवाना है और उन्हें यह काम क्यों करना चाहिए.
generationConfig और safetySettings जैसी अन्य सेटिंग के बारे में ज़्यादा जानने के लिए, प्रॉम्प्ट और सुरक्षा से जुड़ी गाइड देखें.
4. Apps Script से Gemini API को कॉल करना
- script.new पर जाएं. इससे आपके लिए
code.gsApps Script फ़ाइल अपने-आप बन जाएगी. - अपने कर्सर को
code.gsफ़ाइल पर घुमाएं. इसके बाद,
> नाम बदलें पर क्लिक करें. - फ़ाइल का नाम बदलकर
utils.gsकर दो. - फ़ाइल में से
myFunctionफ़ंक्शन हटा दें, ताकि फ़ाइल खाली हो जाए.
प्रोजेक्ट में एपीआई पासकोड जोड़ना
- नेविगेशन मेन्यू में, प्रोजेक्ट सेटिंग को चुनें.
- स्क्रिप्ट प्रॉपर्टी में जाकर, स्क्रिप्ट प्रॉपर्टी जोड़ें पर क्लिक करें.
- प्रॉपर्टी में जाकर,
GOOGLE_API_KEYडालें. - वैल्यू में जाकर, Google AI Studio से मिला एपीआई पासकोड डालें.

- स्क्रिप्ट प्रॉपर्टी सेव करें पर क्लिक करें.
- एडिटर पर वापस जाएं.
Gemini API का कोड जोड़ना
utils.gs फ़ाइल में, यह तरीका अपनाएं:
एपीआई पासकोड और एंडपॉइंट सेट अप करें:
const properties = PropertiesService.getScriptProperties().getProperties();
const geminiApiKey = properties['GOOGLE_API_KEY'];
const geminiEndpoint = `https://generativelanguage.googleapis.com/v1beta/models/gemini-1.0-pro-latest:generateContent?key=${geminiApiKey}`;
- नीचे दिया गया फ़ंक्शन जोड़ें. यह फ़ंक्शन, किसी खास प्रॉम्प्ट के साथ Gemini API को कॉल करता है:
function callGemini(prompt, temperature=0) {
const payload = {
"contents": [
{
"parts": [
{
"text": prompt
},
]
}
],
"generationConfig": {
"temperature": temperature,
},
};
const options = {
'method' : 'post',
'contentType': 'application/json',
'payload': JSON.stringify(payload)
};
const response = UrlFetchApp.fetch(geminiEndpoint, options);
const data = JSON.parse(response);
const content = data["candidates"][0]["content"]["parts"][0]["text"];
return content;
}
- प्रॉम्प्ट सेट करने वाला यह फ़ंक्शन जोड़ें:
function testGemini() {
const prompt = "The best thing since sliced bread is";
const output = callGemini(prompt);
console.log(prompt, output);
}
इसे आज़माएं
सेव करें पर क्लिक करें.- फ़ंक्शन की ड्रॉपडाउन सूची में
testGeminiचुनें और
पर क्लिक करें. - ज़रूरी अनुमतियां स्वीकार करें. आपका कोड चलना चाहिए. साथ ही, आपको एक्ज़ीक्यूशन लॉग में नतीजों के साथ कुछ कंसोल आउटपुट दिखना चाहिए.

इससे काम हो गया!
5. इमेज के साथ Gemini API को कॉल करना
Gemini फ़ैमिली के मॉडल की सबसे बेहतरीन सुविधाओं में से एक है, मल्टी-मॉडल इनपुट की सुविधा. इसका मतलब है कि सिर्फ़ टेक्स्ट ही नहीं, बल्कि अन्य फ़ॉर्मैट में भी इनपुट दिया जा सकता है! इस सेक्शन में, आपको एक ऐसा फ़ंक्शन जोड़ना होगा जो Gemini API को इमेज के साथ कॉल करता हो.
- मौजूदा
const geminiEndpointडिक्लेरेशन के बाद,utils.gsफ़ाइल में सबसे ऊपर यह लाइन जोड़ें:
const geminiProVisionEndpoint = `https://generativelanguage.googleapis.com/v1beta/models/gemini-1.0-pro-vision-latest:generateContent?key=${geminiApiKey}`;
Gemini Vision का कोड जोड़ना
- इस नए एंडपॉइंट को कॉल करने के लिए,
utils.gsफ़ाइल में एक फ़ंक्शन जोड़ें:
function callGeminiProVision(prompt, image, temperature=0) {
const imageData = Utilities.base64Encode(image.getAs('image/png').getBytes());
const payload = {
"contents": [
{
"parts": [
{
"text": prompt
},
{
"inlineData": {
"mimeType": "image/png",
"data": imageData
}
}
]
}
],
"generationConfig": {
"temperature": temperature,
},
};
const options = {
'method' : 'post',
'contentType': 'application/json',
'payload': JSON.stringify(payload)
};
const response = UrlFetchApp.fetch(geminiProVisionEndpoint, options);
const data = JSON.parse(response);
const content = data["candidates"][0]["content"]["parts"][0]["text"];
return content;
}
- यह टेस्ट फ़ंक्शन जोड़ें:
function testGeminiVision() {
const prompt = "Provide a fun fact about this object.";
const image = UrlFetchApp.fetch('https://storage.googleapis.com/generativeai-downloads/images/instrument.jpg').getBlob();
const output = callGeminiProVision(prompt, image);
console.log(prompt, output);
}
यह फ़ंक्शन, इंटरनेट से टेस्ट इमेज लोड करता है और उसे आपके तय किए गए फ़ंक्शन को पास करता है. बाद में, इसे स्प्रेडशीट से चार्ट का इस्तेमाल करने के लिए वायर किया जाता है. इसलिए, यह सिर्फ़ एक टेस्ट है.
इसे आज़माएं
testGeminiVisionफ़ंक्शन को सेव करें और चलाएं. इसके बाद, आउटपुट की जांच करें.

6. टूल की मदद से Gemini API को कॉल करना
टेक्स्ट और इमेज के अलावा, अपने प्रॉम्प्ट में टूल का ऐक्सेस भी दिया जा सकता है.
टूल को मैनेज करने वाला कोड जोड़ना
utils.gsफ़ाइल में एक ऐसा फ़ंक्शन जोड़ें जो टूल स्पेसिफ़िकेशन को स्वीकार करता हो:
function callGeminiWithTools(prompt, tools, temperature=0) {
const payload = {
"contents": [
{
"parts": [
{
"text": prompt
},
]
}
],
"tools" : tools,
"generationConfig": {
"temperature": temperature,
},
};
const options = {
'method' : 'post',
'contentType': 'application/json',
'payload': JSON.stringify(payload)
};
const response = UrlFetchApp.fetch(geminiEndpoint, options);
const data = JSON.parse(response);
const content = data["candidates"][0]["content"]["parts"][0]["functionCall"];
return content;
}
इस स्कीमा और उपलब्ध फ़ील्ड के बारे में ज़्यादा जानने के लिए, FunctionDeclaration एपीआई के बारे में जानकारी देखें.
इसे आज़माएं
- ऐसा टूल तय करें जिसका इस्तेमाल करके मॉडल, मौजूदा तारीख और समय का पता लगा सके:
function testGeminiTools() {
const prompt = "Tell me how many days there are left in this month.";
const tools = {
"function_declarations": [
{
"name": "datetime",
"description": "Returns the current date and time as a formatted string.",
"parameters": {
"type": "string"
}
}
]
};
const output = callGeminiWithTools(prompt, tools);
console.log(prompt, output);
}
यहां FunctionDeclaration स्कीमा का इस्तेमाल किया गया है. आपने तारीख और समय के फ़ंक्शन को कॉल नहीं किया है. आपको सिर्फ़ यह सूचना मिलती है कि मॉडल ने फ़ंक्शन कॉल का अनुरोध किया है. फ़ंक्शन कॉल को बाद के चरण में हैंडल किया जाता है.
- आउटपुट देखने के लिए,
testGeminiToolsफ़ंक्शन को सेव करें और चलाएं.

7. Google Workspace के साथ डेमो इंटिग्रेशन के बारे में खास जानकारी
अब आपको पता चल गया है कि फ़ंक्शन कॉलिंग कैसे काम करती है. इसलिए, Gemini मॉडल की क्षमताओं को अन्य सेवाओं के लिए आसानी से बढ़ाया जा सकता है. अगले कुछ सेक्शन में, Google Workspace के प्रॉडक्ट के साथ इंटिग्रेशन बनाए जाते हैं. जैसे, Google Drive, Google Slides, और Google Sheets. यहां एक आसान डायग्राम दिया गया है:

जब कोई उपयोगकर्ता क्वेरी करता है, तब Gemini API की फ़ंक्शन कॉलिंग सुविधा का इस्तेमाल करके यह तय किया जाता है कि कौनसे टूल का इस्तेमाल करना है. आपको तीन ऐसे टूल बनाने हैं जो ये काम कर सकें:
- मीटिंग सेट अप करें. डायग्राम में मौजूद
setupMeeting()फ़ंक्शन, Google Drive में मौजूद किसी ब्लॉग की खास जानकारी पाने के लिए Gemini 1.0 Pro API को चालू करता है. साथ ही, यह खास जानकारी को Google Calendar में बनाई गई नई मीटिंग में जोड़ता है. - चार्ट में मौजूद अहम जानकारी के आधार पर ईमेल का ड्राफ़्ट तैयार करना. डायग्राम में मौजूद
draftEmail()फ़ंक्शन, Google Sheets में मौजूद किसी चार्ट का विश्लेषण करने के लिए Gemini 1.0 Pro Vision को चालू करता है. इसके बाद, यह विश्लेषण के आधार पर Gmail में एक ईमेल लिखता है. - स्केलेटन डेक बनाना. डायग्राम में मौजूद
createDeck()फ़ंक्शन, Google Slides में डेक के लिए बुलेट पॉइंट जनरेट करने के लिए Gemini 1.0 Pro को चालू करता है.
हर टूल के लिए, आपको ये तीन काम करने होंगे:
- यह तय करता है कि Gemini API के फ़ंक्शन कॉल करने के जवाब में,
if...elseब्लॉक में उस टूल को चालू करने के लिए कहा गया है या नहीं. - टूल की सुविधा लागू करने के लिए, असल फ़ंक्शन जोड़ें.
- Gemini API के साथ टूल का एलान करें, ताकि Gemini मॉडल को टूल के बारे में पता चल सके और वह फ़ंक्शन कॉल करने का सही जवाब दे सके.
8. Apps Script की मदद से मीटिंग सेट अप करना
सबसे पहले, Google Calendar में मीटिंग को सेट अप करने की प्रोसेस को अपने-आप होने वाली प्रोसेस के तौर पर सेट किया जाता है. इसके बाद, मीटिंग के बारे में जानकारी जोड़ी जाती है. यह जानकारी, Google Drive में मौजूद किसी फ़ाइल की खास जानकारी होती है.
ऐसा करने के लिए, इन चरणों का अनुसरण करें:
- इस टेक्स्ट फ़ाइल को डाउनलोड करें. यह Gemini 1.5 Pro के लॉन्च से जुड़े ब्लॉग की टेक्स्ट कॉपी है.
- फ़ाइल को Google Drive के रूट फ़ोल्डर में अपलोड करें.
- एडिटर में,
main.gsफ़ाइल बनाएं. इसके बाद, यह कोड जोड़ें:
function main() {
const userQuery = "Set up a meeting at 10AM tomorrow with Helen to discuss the news in the Gemini-blog.txt file.";
var tool_use = callGeminiWithTools(userQuery, WORKSPACE_TOOLS);
Logger.log(tool_use);
if(tool_use['name'] == "setupMeeting") {
setupMeeting(tool_use['args']['time'], tool_use['args']['recipient'], tool_use['args']['filename']);
Logger.log("Your meeting has been set up.");
}
else
Logger.log("no proper tool found");
}
यहाँ, Gemini API की फ़ंक्शन कॉलिंग की सुविधा का इस्तेमाल किया जाता है. इसके बाद, आपको टूल फ़ंक्शन तय करना होगा.
- एडिटर में बाईं ओर, सेवाएं के बगल में मौजूद, + सेवा जोड़ें > Google Calendar API > जोड़ें पर क्लिक करें. इससे Google Calendar की ऐडवांस सेवा चालू हो जाती है. बाद में, आपको कुछ ऐडवांस एपीआई इस्तेमाल करने के लिए, इस सेवा का इस्तेमाल करना होगा.

utils.gsफ़ाइल में, यह कोड जोड़ें:
function attachFileToMeeting(event, file, fileName) {
// Get the iCal ID for the event.
const iCalEventId = event.getId();
// Log the ID and title for debugging.
console.log(`iCal event ID: ${iCalEventId}`);
console.log(`event Title: ${event.getTitle()}`);
// Set up the options for listing the event with the advanced Google Calendar service.
const options = {
iCalUID: iCalEventId,
};
// Use the primary calendar as the calendar ID to list events.
const calendarId = 'primary';
// Use the advanced Google Calendar service to list the event.
const calEvents = Calendar.Events.list(calendarId, options);
// Get the Calendar ID used by the advanced Google Calendar service.
const eventId = calEvents.items[0].id;
// Get the file URL for the attachment.
const fileUrl = file.getUrl();
// Set up the patch options to add the file.
var patch = {
attachments: [{
'fileUrl': fileUrl,
'title': fileName
}]
};
// Patch the event to add the file as an attachment.
Calendar.Events.patch(patch, 'primary', eventId, {"supportsAttachments": true});
}
function setupMeeting(time, recipient, filename) {
const files = DriveApp.getFilesByName(filename);
const file = files.next();
const blogContent = file.getAs("text/*").getDataAsString();
var geminiOutput = callGemini("Give me a really short title of this blog and a summary with less than three sentences. Please return the result as a JSON with two fields: title and summary. \n" + blogContent);
// The Gemini model likes to enclose the JSON with ```json and ```
geminiOutput = JSON.parse(geminiOutput.replace(/```(?:json|)/g, ""));
const title = geminiOutput['title'];
const fileSummary = geminiOutput['summary'];
const event = CalendarApp.getDefaultCalendar().createEventFromDescription(`meet ${recipient} at ${time} to discuss "${title}"`);
event.setDescription(fileSummary);
attachFileToMeeting(event, file, filename);
}
यह कोड ये काम करता है:
setupMeeting()फ़ंक्शन, आपके Google Drive में मौजूद सभी फ़ाइलों को स्कैन करता है औरGemini-blog.txtफ़ाइल ढूंढता है. यह फ़ाइल का नाम, तीसरे चरण में Gemini API के फ़ंक्शन कॉलिंग की सुविधा से अपने-आप मिलता है.setupMeeting()फ़ंक्शन, Gemini API को कॉल करके फ़ाइल के कॉन्टेंट का सारांश बनाता है. साथ ही, CalendarApp के साथ मीटिंग सेट अप करता है. इसके लिए, फ़्री-फ़ॉर्म में ब्यौरा देता है और मीटिंग में सारांश जोड़ता है.setupMeeting()फ़ंक्शन,attachFileToMeeting()फ़ंक्शन को कॉल करता है, ताकि Google Calendar की ऐडवांस सेवा का इस्तेमाल करके, ब्लॉग फ़ाइल को मीटिंग में अटैच किया जा सके.
utils.gsफ़ाइल में सबसे ऊपर, यह कोड जोड़ें:
const WORKSPACE_TOOLS = {
"function_declarations": [
{
"name": "setupMeeting",
"description": "Sets up a meeting in Google Calendar.",
"parameters": {
"type": "object",
"properties": {
"time": {
"type": "string",
"description": "The time of the meeting."
},
"recipient": {
"type": "string",
"description": "The name of the recipient."
},
"filename": {
"type": "string",
"description": "The name of the file."
},
},
"required": [
"time",
"recipient",
"filename"
]
}
},
// You add tools here.
]
};
- एडिटर में,
main.gsफ़ाइल पर वापस जाएं और
पर क्लिक करें. - अगर Google Workspace आपसे स्क्रिप्ट चलाने की अनुमति मांगता है, तो ठीक है पर क्लिक करें.
कुछ ही सेकंड में, एक्ज़ीक्यूशन लॉग में एक मैसेज दिखता है. इससे आपको पता चलता है कि आपकी मीटिंग सेट अप हो गई है.
- Google Calendar में, खास जानकारी और अटैचमेंट वाली मीटिंग ढूंढें.

9. Apps Script की मदद से ईमेल ड्राफ़्ट करना
इसके बाद, Gmail में ईमेल ड्राफ़्ट करने की प्रोसेस को अपने-आप होने वाली प्रोसेस के तौर पर सेट अप करें. यहां एक उदाहरण दिया गया है: मान लें कि आपको Google Sheets में डेटा का विश्लेषण करना है. सभी नंबरों को सही जगह पर रखकर चार्ट बनाया जाता है. आपको चार्ट के आधार पर ईमेल का ड्राफ़्ट बनाने के लिए, Gemini Pro Vision API का इस्तेमाल करना है.
ऐसा करने के लिए, इन चरणों का अनुसरण करें:
- इस शीट को खोलें और फ़ाइल -> कॉपी बनाएं पर क्लिक करें.
- दस्तावेज़ की कॉपी बनाएं डायलॉग बॉक्स में मौजूद नाम टेक्स्ट बॉक्स में, डिफ़ॉल्ट नाम
Copy of CollegeExpensesकोCollegeExpensesसे बदलें. main.gsफ़ाइल में, उपयोगकर्ता की पिछली क्वेरी को नई क्वेरी से बदलें. इसके बाद,if...elseस्टेटमेंट में यह कोड जोड़ें:
function main() {
// const userQuery = "Set up a meeting at 5PM with Helen to discuss the news in the Gemini-1.5-blog.txt file.";
const userQuery = "Draft an email for Mary with insights from the chart in the CollegeExpenses sheet.";
if(...) {...}
// Add this code
else if(tool_use['name'] == "draftEmail") {
draftEmail(tool_use['args']['sheet_name'], tool_use['args']['recipient']);
Logger.log("Check your Gmail to review the draft");
}
else {...}
}
utils.gsफ़ाइल में, यह कोड जोड़ें:
function draftEmail(sheet_name, recipient) {
const prompt = `Compose the email body for ${recipient} with your insights for this chart. Use information in this chart only and do not do historical comparisons. Be concise.`;
var files = DriveApp.getFilesByName(sheet_name);
var sheet = SpreadsheetApp.openById(files.next().getId()).getSheetByName("Sheet1");
var expenseChart = sheet.getCharts()[0];
var chartFile = DriveApp.createFile(expenseChart.getBlob().setName("ExpenseChart.png"));
var emailBody = callGeminiProVision(prompt, expenseChart);
GmailApp.createDraft(recipient+"@demo-email-provider.com", "College expenses", emailBody, {
attachments: [chartFile.getAs(MimeType.PNG)],
name: 'myname'
});
}
यह फ़ंक्शन, शीट से कॉलेज के खर्च का चार्ट वापस लाता है और ईमेल ड्राफ़्ट करने के लिए, इसे Gemini Pro Vision को भेजता है. Gemini Pro Vision, चार्ट से जानकारी निकालता है और आपकी ओर से ईमेल का मसौदा तैयार करता है.
utils.gsफ़ाइल में,You add tools hereकमेंट के बादWORKSPACE_TOOLSऑब्जेक्ट में यह कोड जोड़ें:
WORKSPACE_TOOLS = {
"function_declarations": [
// You add tools here.
{
"name": "draftEmail",
"description": "Write an email by analyzing data or charts in a Google Sheets file.",
"parameters": {
"type": "object",
"properties": {
"sheet_name": {
"type": "string",
"description": "The name of the sheet to analyze."
},
"recipient": {
"type": "string",
"description": "The name of the recipient."
},
},
"required": [
"sheet_name",
"recipient"
]
}
},
]
};
- एडिटर में, वापस
main.gsफ़ाइल पर जाएं. इसके बाद,
पर क्लिक करें. - दस से बीस सेकंड के बाद, Gmail खोलें. आपको इस तरह का ईमेल ड्राफ़्ट दिखेगा:
ईमेल भेजने से पहले, ड्राफ़्ट में बदलाव किया जा सकता है. इस ईमेल को Gemini Pro Vision ने लिखा है. इसके लिए, आपने उसे एक छोटा प्रॉम्प्ट और चार्ट दिया था.
10. Apps Script की मदद से स्केलेटन डेक बनाना
इसके बाद, Apps Script की मदद से Google Slides में एक स्केलेटन डेक अपने-आप जनरेट होने की सुविधा सेट अप करें.
ऐसा करने के लिए, इन चरणों का अनुसरण करें:
main.gsफ़ाइल में, उपयोगकर्ता की पिछली क्वेरी को नई क्वेरी से बदलें. साथ ही,main.gsस्टेटमेंट में यह कोड जोड़ें:if...else
function main() {
// const userQuery = "Draft an email for Mary with insights from the chart in the CollegeExpenses sheet.";
const userQuery = "Help me put together a deck about water conservation.";
if(...) {...}
// Add this code
else if(tool_use['name'] == 'createDeck') {
deckURL = createDeck(tool_use['args']['topic']);
Logger.log("Deck URL: " + deckURL);
}
else {...}
}
utils.gsफ़ाइल में, यह कोड जोड़ें:
function createDeck(topic) {
const prompt = `I'm preparing a ${NUM_SLIDES}-slide deck to discuss ${topic}. Please help me brainstorm and generate main bullet points for each slide. Keep the title of each slide short. Please produce the result as a valid JSON so that I can pass it to other APIs.`;
var geminiOutput = callGemini(prompt, 0.4);
// The Gemini model likes to enclose the JSON with ```json and ```
geminiOutput = geminiOutput.replace(/```(?:json|)/g, "");
const bulletPoints = JSON.parse(geminiOutput);
// Create a Google Slides presentation.
const presentation = SlidesApp.create("My New Presentation");
// Set up the opening slide.
var slide = presentation.getSlides()[0];
var shapes = slide.getShapes();
shapes[0].getText().setText(topic);
var body;
for (var i = 0; i < NUM_SLIDES; i++) {
slide = presentation.appendSlide(SlidesApp.PredefinedLayout.TITLE_AND_BODY);
shapes = slide.getShapes();
// Set title.
shapes[0].getText().setText(bulletPoints['slides'][i]['title']);
// Set body.
body = "";
for (var j = 0; j < bulletPoints['slides'][i]['bullets'].length; j++) {
body += '* ' + bulletPoints['slides'][i]['bullets'][j] + '\n';
}
shapes[1].getText().setText(body);
}
return presentation.getUrl();
}
यह फ़ंक्शन, किसी विषय पर नए आइडिया पाने के लिए Gemini API को कॉल करता है. साथ ही, बुलेट पॉइंट को इस फ़ॉर्मैट में दिखाता है
का इस्तेमाल करके, JSON फ़ाइल बनाएं. इसके बाद, Apps Script का इस्तेमाल करके, डेक में डेटा भरें.
utils.gsफ़ाइल में,You add tools hereकमेंट के बादWORKSPACE_TOOLSऑब्जेक्ट में यह कोड जोड़ें:
WORKSPACE_TOOLS = {
"function_declarations": [
// You add tools here.
{
"name": "createDeck",
"description": "Build a simple presentation deck with Google Slides and return the URL.",
"parameters": {
"type": "object",
"properties": {
"topic": {
"type": "string",
"description": "The topic that the presentation is about."
},
},
"required": [
"topic"
]
}
},
]
};
utils.gsफ़ाइल में सबसे ऊपर, यह कॉन्स्टेंट तय करें:
const NUM_SLIDES = 3;
यह उन स्लाइड की संख्या है जिन्हें Gemini मॉडल, शुरुआती स्लाइड के अलावा बनाता है.
- एडिटर में, वापस
main.gsफ़ाइल पर जाएं. इसके बाद,
पर क्लिक करें. कुछ ही सेकंड में, आपको एक्ज़ीक्यूशन लॉग में प्रेज़ेंटेशन का यूआरएल दिखेगा. - यूआरएल खोलने के लिए, अपने ब्राउज़र का इस्तेमाल करें. आपको बुलेट पॉइंट से भरा हुआ एक स्केलेटन डेक दिखेगा.

11. एक्सप्लोर करने के लिए आइडिया
इन तीन इंटिग्रेशन के अलावा, यहां दिए गए आइडिया आज़माए जा सकते हैं:
- Google Chat पर चैटबॉट बनाना. लार्ज लैंग्वेज मॉडल (एलएलएम) का सबसे ज़्यादा इस्तेमाल, चैटबॉट बनाने के लिए किया जाता है. Gemini API की मदद से, Google Chat के लिए चैटबॉट बनाना आसान है. ज़्यादा जानकारी के लिए, Google Chat API और कोडलैब Gemini की मदद से Google Chat के लिए ऐप्लिकेशन बनाना देखें.
- Google Drive या Keep में मौजूद अपने डेटा के साथ, जवाब जनरेट करने की बेहतर सुविधा (आरएजी) का इस्तेमाल करें. इस कोडलैब में, खास जानकारी जनरेट करने के लिए सिर्फ़ एक टेक्स्ट फ़ाइल का इस्तेमाल किया जाता है. हालांकि, Gemini API, वेक्टर डेटाबेस, और ऑर्केस्ट्रेशन टूल (जैसे, LangChain) का इस्तेमाल करके, अपने निजी Google Drive और Keep जैसे नोट, PDF, और इमेज से कॉन्टेंट का इस्तेमाल किया जा सकता है. इससे RAG किया जा सकता है और मॉडल के जवाब को अपने डेटा के हिसाब से बनाया जा सकता है.
- Gemini API की, एक से ज़्यादा बार फ़ंक्शन कॉल करने की सुविधा का इस्तेमाल करें. Gemini API में फ़ंक्शन कॉलिंग की सुविधा, एक बार में सिर्फ़ एक फ़ंक्शन कॉल करने तक सीमित नहीं है. ज़्यादा मुश्किल कामों के लिए, एक से ज़्यादा बार फ़ंक्शन कॉल करने की सुविधा का इस्तेमाल किया जा सकता है.
- Google Workspace से आगे बढ़ें. अब आपको Gemini API को Google Workspace के साथ इंटिग्रेट करने का तरीका पता चल गया है. इसलिए, अब Google Workspace के अलावा, दुनिया के अन्य एपीआई का भी फ़ायदा लिया जा सकता है.
12. बधाई हो
आपने Gemini API की मल्टी-मॉडल क्षमताओं और फ़ंक्शन कॉलिंग के बारे में जाना. आपने इनका इस्तेमाल, Apps Script की मदद से Google Workspace के कुछ टास्क को ऑटोमेट करने के लिए किया था!