Skip to content

Instantly share code, notes, and snippets.

@sergiolopes
Last active July 1, 2023 14:36
Show Gist options
  • Save sergiolopes/faf25d8781f4340edfc65a11b37ceb60 to your computer and use it in GitHub Desktop.
Save sergiolopes/faf25d8781f4340edfc65a11b37ceb60 to your computer and use it in GitHub Desktop.
Use GPT no Google Spreadcheets com essa função App Script
const SECRET_KEY = "YOUR API KEY";
const MAX_TOKENS = 3000;
const TEMPERATURE = 0.9;
function EMAILALUNO(aluno, nota) {
const url = "https://api.openai.com/v1/chat/completions";
const payload = {
model: 'gpt-3.5-turbo',
messages: [
{ role: "system", content: "Crie um parágrafo de incentivo para um aluno que recebeu uma nota na prova. Vou passar o nome do aluno e a nota." },
{ role: "user", content: "Aluno: " + aluno + '. Nota: ' + nota },
],
temperature: TEMPERATURE,
max_tokens: MAX_TOKENS,
};
const options = {
contentType: "application/json",
headers: { Authorization: "Bearer " + SECRET_KEY },
payload: JSON.stringify(payload),
timeoutInSeconds: 60
};
const res = JSON.parse(UrlFetchApp.fetch(url, options).getContentText());
return res.choices[0].message.content.trim();
}
@bomes01
Copy link

bomes01 commented Jun 23, 2023

Sergio parabéns pelas aulas

@FrancisMV
Copy link

Muito interessante o uso do App Script com OpenAI, funcionou aqui.
Mas apenas para testar também fiz o exercício utilizando a extensão SheetGPT e ficou bom também. Usei o prompt: =GPT("Crie o texto de um e-mail para nota do semestre de Física do aluno" &A2& "que recebeu a nota:" &F2& "com assinatura do professor Galileo Galilei")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment