Skip to content

Instantly share code, notes, and snippets.

@browny
Created June 22, 2024 05:59
Show Gist options
  • Save browny/5b06727894a52f1ccf48d6aef445936f to your computer and use it in GitHub Desktop.
Save browny/5b06727894a52f1ccf48d6aef445936f to your computer and use it in GitHub Desktop.
apps script gemini
function execute(prompt) {
console.log(`prompt: ${prompt}`);
const data = {
"contents": [{
"parts": [{
"text": prompt
}]
}],
"generationConfig": {
"temperature": 2.0,
"topK": 1,
"topP": 1,
"maxOutputTokens": 2048,
"stopSequences": []
},
"safetySettings": [
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_NONE"
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "BLOCK_NONE"
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_NONE"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_NONE"
}
]
};
const options = {
'method': 'post',
'contentType': 'application/json',
'payload': JSON.stringify(data) // Convert the JavaScript object to a JSON string.
};
const apiKey = PropertiesService.getScriptProperties().getProperty('api_key');
let response = UrlFetchApp.fetch('https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent?key=' + apiKey, options);
const payload = JSON.parse(response.getContentText());
const text = payload.candidates[0].content.parts[0].text;
return text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment