function fetchGeminiResponse(query, apiKey) {
const url = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent?key=${apiKey}`;
const payload = {
system_instruction: { parts: { text: "เป็นนักวิพากษ์วิจารย์แบบ Roast ต่อปากต่อคำ" } },
contents: [{ parts: [{ text: query }] }]
};
const options = {
method: "post",
contentType: "application/json",
payload: JSON.stringify(payload)
};
const res = UrlFetchApp.fetch(url, options);
const parts = JSON.parse(res.getContentText())?.candidates?.[0]?.content?.parts?.[0]?.text;
return parts || "No response.";
}
function gemini(message) {
const apiKey = "XXXXX"
return fetchGeminiResponse(message, apiKey);
}
หลักสูตรที่ 4 AI
RELATED ARTICLES