const GEMINI_API_KEY = '你的API密鑰';
function generateSimpleMessage() {
const apiUrl = 'https://generativelanguage.googleapis.com/v1/models/gemini-pro:generateMessage?key=' + GEMINI_API_KEY;
const payload = {
"prompt": {
"text": "生成一段歡迎學生學習的訊息"
}
};
const options = {
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify(payload)
};
const response = UrlFetchApp.fetch(apiUrl, options);
const data = JSON.parse(response.getContentText());
Logger.log("生成的訊息:" + data.candidates[0].content);
}
步驟:
GEMINI_API_KEY
替換為你的實際密鑰。
const GEMINI_API_KEY = '你的API密鑰';
function generateQuizQuestion() {
const apiUrl = 'https://generativelanguage.googleapis.com/v1/models/gemini-pro:generateContent?key=' + GEMINI_API_KEY;
const payload = {
"prompt": "請生成一個關於 HTML 基礎的選擇題,包括問題、選項和答案。"
};
const options = {
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify(payload)
};
const response = UrlFetchApp.fetch(apiUrl, options);
const data = JSON.parse(response.getContentText());
Logger.log("生成的範例問題:" + data.candidates[0].content);
}
步驟:
GEMINI_API_KEY
為你的密鑰。