Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update utils.gs #122

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions examples/Apps_script_and_Workspace_codelab/utils.gs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function attachFileToMeeting(event, file, fileName) {
// 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';
Expand All @@ -247,7 +247,7 @@ function attachFileToMeeting(event, file, fileName) {
'fileUrl': fileUrl,
'title': fileName
}]
}
};

// Patch the event to add the file as an attachment.
Calendar.Events.patch(patch, 'primary', eventId, {"supportsAttachments": true});
Expand All @@ -256,30 +256,30 @@ function attachFileToMeeting(event, file, fileName) {
function setupMeeting(time, recipient, filename) {
const files = DriveApp.getFilesByName(filename);
const file = files.next();
const blogContent = file.getAs("text/*").getDataAsString()
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 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)
attachFileToMeeting(event, file, filename);
}

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.`;
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)
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'
Expand Down
Loading