-
-
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 | |
| const API_KEY = 'EDIT_ME'; | |
| 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