| 105 | |
| 106 | |
| 107 | function report(inputText) { |
| 108 | cache = CacheService.getUserCache(); |
| 109 | token = cache.get("token"); |
| 110 | if (token == "") return "ERROR"; |
| 111 | Logger.log(`Token = ${token}`); |
| 112 | url = `https://us-central1-aiplatform.googleapis.com/v1/projects/${project}/locations/us-central1/publishers/google/models/gemini-1.0-pro:generateContent` |
| 113 | prompt = "Role: You are a financial analyst and you are required to summarise the key insights of given numerical tables.Task: Step 1: List important, but no more than five, highlights from the figures provided in the given table.Step 2: Write a paragraph about the main movers of net income comparing each year from the figures provided. (For a dataset with three years of figures compare Year 1 to Year 2 and Year 2 to Year 3) Further Instructions: Please write in a professional and business-neutral tone similar to the financial times.The summary should only be based on the information presented in the table and only contain facts form that table." |
| 114 | text = prompt + inputText; |
| 115 | data = { |
| 116 | contents: { |
| 117 | role: "USER", |
| 118 | parts: { "text": text } |
| 119 | }, |
| 120 | generation_config: { |
| 121 | temperature: 0.3, |
| 122 | topP: 1, |
| 123 | maxOutputTokens: 2000 |
| 124 | } |
| 125 | } |
| 126 | const options = { |
| 127 | method: "post", |
| 128 | contentType: 'application/json', |
| 129 | headers: { |
| 130 | Authorization: `Bearer ${token}`, |
| 131 | }, |
| 132 | payload: JSON.stringify(data) |
| 133 | }; |
| 134 | |
| 135 | const response = UrlFetchApp.fetch(url, options); |
| 136 | if (response.getResponseCode() == 200) { |
| 137 | json = JSON.parse(response.getContentText()); |
| 138 | answer = json.candidates[0].content.parts[0].text; |
| 139 | return answer; |
| 140 | } |
| 141 | return "ERROR"; |
| 142 | } |
| 143 | |
| 144 | function reported(cellRange) { |
| 145 | const sheet = SpreadsheetApp.getActiveSheet(); |