MCPcopy Create free account
hub / github.com/analyticswithadam/App_Script / formatReport

Function formatReport

EndtoEndAutomatedDecks.js:116–165  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

114}
115
116function formatReport() {
117 auth();
118 var input = pullVariables()
119 var ss = SpreadsheetApp.getActiveSpreadsheet();
120 var aggSheet = ss.getSheetByName('Category');
121 var aggSheet2 = ss.getSheetByName('Vendor');
122 var reportSheet = ss.getSheetByName('Output') || ss.insertSheet('Output');
123 reportSheet.clear();
124
125 var aggData = aggSheet.getDataRange().getValues(); // Pivot Data
126 var aggData2 = aggSheet2.getDataRange().getValues(); // Pivot Data
127
128 cache = CacheService.getUserCache();
129 token = cache.get("token");
130 if (token == "") return "ERROR";
131 Logger.log(`Token = ${token}`);
132 url = `https://us-central1-aiplatform.googleapis.com/v1/projects/${project}/locations/us-central1/publishers/google/models/gemini-1.5-pro:generateContent`
133 data = {
134 contents: {
135 role: "USER",
136 parts: { "text": `${input.var7}` + ' Only reffer to the data provided do not make anything up. This is the Aggregated data:'+ aggData2 + '---- This is the Full Data:' + aggData}
137 },
138 generation_config: {
139 temperature: 0.3,
140 topP: 1,
141 maxOutputTokens: 1000
142 }
143 }
144 const options = {
145 method: "post",
146 contentType: 'application/json',
147 headers: {
148 Authorization: `Bearer ${token}`,
149 },
150 payload: JSON.stringify(data)
151 };
152
153 const response = UrlFetchApp.fetch(url, options);
154 if (response.getResponseCode() == 200) {
155 json = JSON.parse(response.getContentText());
156 answer = json.candidates[0].content.parts[0].text;
157 Logger.log(answer);
158 var commentary = reportSheet.getRange("J3");
159 commentary.setValue(answer);
160 commentary.setWrap(true);
161 }
162 else{
163 Logger.log("ERROR");
164 }
165}
166
167function onOpen() {
168 var ui = SpreadsheetApp.getUi();

Callers 1

generateReportFunction · 0.70

Calls 2

authFunction · 0.70
pullVariablesFunction · 0.70

Tested by

no test coverage detected