-
-
Save tronghieu60s/591650f690dc5dd1bd941cd510d40b4a to your computer and use it in GitHub Desktop.
Hàm để dùng Gemini trong Google Sheets. Xem cách sử dụng: https://www.tiktok.com/@juno_okyo/video/7378880956209401094?_r=1&_t=8n5NIEqPjqE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Author: JUNO_OKYO - J2TEAM (EDITED Gemini By Trong Hieu) | |
const API_KEY = "EDIT_ME"; // CHÚ Ý: sửa key của bạn trước khi sử dụng!!! | |
const URL = | |
"https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent"; | |
function askGPT(prompt) { | |
const payload = { | |
contents: [ | |
{ | |
parts: [ | |
{ | |
text: prompt, | |
}, | |
], | |
}, | |
], | |
}; | |
const options = { | |
method: "post", | |
contentType: "application/json", | |
payload: JSON.stringify(payload), | |
}; | |
try { | |
const response = UrlFetchApp.fetch(`${URL}?key=${API_KEY}`, options); | |
const json = JSON.parse(response.getContentText()); | |
return json.candidates[0].content.parts[0].text; | |
} catch (e) { | |
return `Error: ${e.message}`; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment