Skip to content

Instantly share code, notes, and snippets.

@tronghieu60s
Forked from J2TEAM/gpt-for-google-sheet.js
Last active June 17, 2024 07:41
Show Gist options
  • Save tronghieu60s/591650f690dc5dd1bd941cd510d40b4a to your computer and use it in GitHub Desktop.
Save tronghieu60s/591650f690dc5dd1bd941cd510d40b4a to your computer and use it in GitHub Desktop.

Revisions

  1. tronghieu60s revised this gist Jun 11, 2024. 2 changed files with 32 additions and 30 deletions.
    32 changes: 32 additions & 0 deletions gemini-for-google-sheet.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    // 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}`;
    }
    }
    30 changes: 0 additions & 30 deletions gpt-for-google-sheet.js
    Original file line number Diff line number Diff line change
    @@ -1,30 +0,0 @@
    // 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}`;
    }
    }
  2. @J2TEAM J2TEAM revised this gist Jun 10, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gpt-for-google-sheet.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    // Author: JUNO_OKYO - J2TEAM
    const API_KEY = 'EDIT_ME';
    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) {
  3. @J2TEAM J2TEAM created this gist Jun 10, 2024.
    30 changes: 30 additions & 0 deletions gpt-for-google-sheet.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    // 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}`;
    }
    }