-
Notifications
You must be signed in to change notification settings - Fork 1
/
stochastic-parrot-in-the-sheets.gs
43 lines (35 loc) · 1.16 KB
/
stochastic-parrot-in-the-sheets.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPITS - Stochastic Parrot In The Sheets
// Isaac Wyatt
// https://github.com/iwyatt/spits
function spits(apiKey, prompt) {
const url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=" + apiKey;
var payload = {
safetySettings: [
{category: "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_ONLY_HIGH"},
{category: "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_ONLY_HIGH"},
{category: "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_ONLY_HIGH"}
],
contents: [{
parts: [{
text: prompt
}]
}]
};
const options = {
"method" : "post",
"payload" : JSON.stringify(payload),
"headers": {
"Content-Type": "application/json"
}
};
console.log(payload);
const response = UrlFetchApp.fetch(url, options);
console.log(response);
const content = JSON.parse(response.getContentText());
console.log(content);
if (content.candidates.finishReason === 'SAFETY')
{return "[Prompt Response Blocked]"}
const firstCandidate = content.candidates[0];
const generatedText = firstCandidate.content.parts[0].text;
return generatedText;
}