Skip to content

Commit 43a8d48

Browse files
authored
Merge pull request #6 from AIObjectives/tidy-up-example
Update googlesheet-with-config.mjs
2 parents 24ee557 + 293ecbd commit 43a8d48

File tree

1 file changed

+21
-32
lines changed

1 file changed

+21
-32
lines changed

examples/googlesheet-with-config.mjs

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,38 @@ import { parse } from "csv-parse/sync";
44

55
/*
66
* Report generation options:
7-
* reportTitle (string): The title of this report.
8-
* reportQuestion (string): The overall topic of this report's content
9-
* googleSheetUrl (string): full URL for a Google Sheets spreadsheet. The data
7+
* title (string): The title of this report.
8+
* question (string): The overall topic of this report's content
9+
* googleSheet:
10+
* - url (string): full URL for a Google Sheets spreadsheet. The data
1011
* to analyze must be in the first tab of this sheet.
11-
* pieChartColumns (string|null): a list of column names in the spreadsheet to
12+
* - pieChartColumns (string|null): a list of column names in the spreadsheet to
1213
* treat as quantitative data, displayed as pie charts at the beginning of
1314
* the report. Values must match the spreadsheet column names exactly.
14-
* whitelistCSV (string|null): the name of a CSV in the current directory listing
15-
* email addresses to include responses from, if desired.
15+
* - filterEmails (array of strings|null): list of email addresses to whitelist
16+
* (we'll loading these from a CSV in this example)
1617
*
1718
* Note: in any single column, all cells must have the same data type (string or
1819
* number format) for the Google Sheets API to fetch them as displayed.
1920
*
2021
* Run this script with `node googlesheet-with-config.mjs`.
2122
*/
23+
2224
const CONFIG = {
23-
reportTitle: "Talk to the City [synethic survey]",
24-
reportQuestion: "What are your impressions of Talk to the City?",
25-
googleSheetUrl: "https://docs.google.com/spreadsheets/d/1pQjnqA4Ul07JCRDr0UMuOP26z3QD0RfigTa6zuOUBmw/edit#gid=0",
26-
pieChartColumns: [
27-
"Would you use the tool described in the article? (1 = Very unlikely to use; 5 = Very likely to use)",
28-
"How helpful would you expect this tool to be for your work? (1 = Not helpful; 5 = Very helpful)"
29-
],
30-
whitelistCSV: "example-email-whitelist.csv"
25+
apiKey: process.env.OPENAI_API_KEY,
26+
title: "Talk to the City [synthetic survey]",
27+
question: "What are your impressions of Talk to the City?",
28+
googleSheet: {
29+
url: "https://docs.google.com/spreadsheets/d/1pQjnqA4Ul07JCRDr0UMuOP26z3QD0RfigTa6zuOUBmw/edit#gid=0",
30+
pieChartColumns: [
31+
"Would you use the tool described in the article? (1 = Very unlikely to use; 5 = Very likely to use)",
32+
"How helpful would you expect this tool to be for your work? (1 = Not helpful; 5 = Very helpful)"
33+
],
34+
filterEmails: getWhiteListFromCSV("example-email-whitelist.csv"),
35+
}
3136
}
3237

33-
34-
function unpackCSV(filename) {
38+
function getWhiteListFromCSV(filename) {
3539
const content = fs.readFileSync(filename);
3640
let records = parse(content, {
3741
columns: false,
@@ -43,27 +47,12 @@ function unpackCSV(filename) {
4347
}
4448

4549
async function main() {
46-
let whitelist = null;
47-
if (CONFIG.whitelistCSV) {
48-
whitelist = unpackCSV(CONFIG.whitelistCSV);
49-
console.log('Including only responses from emails in ' + CONFIG.whitelistCSV);
50-
}
51-
5250
const res = await fetch("http://localhost:8080/generate", {
5351
method: "POST",
5452
headers: {
5553
"Content-Type": "application/json",
5654
},
57-
body: JSON.stringify({
58-
apiKey: process.env.OPENAI_API_KEY,
59-
googleSheet: {
60-
url: CONFIG.googleSheetUrl,
61-
pieChartColumns: CONFIG.pieChartColumns,
62-
filterEmails: CONFIG.emailwhitelist
63-
},
64-
title: CONFIG.reportTitle,
65-
question: CONFIG.reportQuestion
66-
}),
55+
body: JSON.stringify(CONFIG),
6756
});
6857
const resData = await res.json();
6958
console.log("The report will be generated at: ", resData.url);

0 commit comments

Comments
 (0)