Charlie Harrington
@whatrocks
Is there a Google sheets formula for calling Gemini? The same way there is for Google translate?
3 replies
2 recasts
35 reactions
Govind
@themogul
Did this thru App Scripts. (1) Grab an API Key from Gemini (2) Extensions > App Scripts (3) Drop this script: function callGemini(prompt) { var apiKey = "YOUR_GEMINI_API_KEY"; // Replace with your actual API key var url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateText?key=" + apiKey; var payload = { "contents": [{ "parts": [{ "text": prompt }] }] }; var options = { "method": "post", "contentType": "application/json", "payload": JSON.stringify(payload) }; var response = UrlFetchApp.fetch(url, options); var json = JSON.parse(response.getContentText()); if (json && json.candidates && json.candidates.length > 0) { return json.candidates[0].content.parts[0].text; } else { return "Error: No response from Gemini"; } } (4) Save/close (5) Use function =callGemini(“Why didn’t I ask Gemini how to do this?”) 🙂
0 reply
0 recast
0 reaction