-
-
Save J2TEAM/91bc15ab65941d8db9cfb30de2b849a3 to your computer and use it in GitHub Desktop.
Hàm để dùng ChatGPT 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 | |
const API_KEY = 'EDIT_ME'; // CHÚ Ý: sửa key của bạn trước khi sử dụng!!! | |
const URL = 'https://api.openai.com/v1/chat/completions'; | |
function askGPT(prompt) { | |
const payload = { | |
model: "gpt-4o", | |
messages: [ | |
{ role: "system", content: "You are a helpful assistant. Your name is J2TEAM GPT." }, | |
{ role: "user", content: prompt } | |
] | |
}; | |
const options = { | |
method: 'post', | |
contentType: 'application/json', | |
headers: { | |
Authorization: `Bearer ${API_KEY}` | |
}, | |
payload: JSON.stringify(payload) | |
}; | |
try { | |
const response = UrlFetchApp.fetch(URL, options); | |
const json = JSON.parse(response.getContentText()); | |
return json.choices[0].message.content.trim(); | |
} catch (e) { | |
return `Error: ${e.message}`; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment