「Google/スプレットシート/ChatGPT」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→サンプルコード) |
|||
| (同じ利用者による、間の13版が非表示) | |||
| 行1: | 行1: | ||
| + | ==サンプルコード== | ||
| + | <pre> | ||
| + | /** | ||
| + | * GPT-3 and Google Sheets | ||
| + | * | ||
| + | * @param {string} prompt Prompt. | ||
| + | * @param {number} temperature (Optional) Temperature. | ||
| + | * @param {string} model (Optional) GPT-3 Model. | ||
| + | * @return Response returned by GPT-3. | ||
| + | * @customfunction | ||
| + | */ | ||
| + | const SECRET_KEY = "ここにAPIkeyをペースト"; | ||
| + | //const MAX_TOKENS = 10; | ||
| + | const MODEL_NAME = "text-davinci-003"; | ||
| + | const MODEL_TEMP = 0.3; | ||
| + | |||
| + | function GPT(prompt,max_tokens=30) { | ||
| + | const url = "https://api.openai.com/v1/completions"; | ||
| + | const payload = { | ||
| + | model: MODEL_NAME, | ||
| + | prompt: prompt, | ||
| + | temperature: MODEL_TEMP, | ||
| + | max_tokens: max_tokens | ||
| + | }; | ||
| + | const options = { | ||
| + | contentType: "application/json", | ||
| + | headers: { Authorization: "Bearer " + SECRET_KEY }, | ||
| + | payload: JSON.stringify(payload), | ||
| + | }; | ||
| + | const res = JSON.parse(UrlFetchApp.fetch(url, options).getContentText()); | ||
| + | return res.choices[0].text.trim(); | ||
| + | } | ||
| + | </pre> | ||
| + | 上のスクリプトを、拡張機能のAppsScriptへ、貼り付ける。 | ||
| + | |||
| + | 以下をセルに貼り付ける | ||
| + | =IF(ISBLANK(A1),"",GPT("10代が書きそうな日記を書いて",1000)) | ||
| + | |||
| + | ==モデルについて== | ||
| + | 2023/1時点の最新 | ||
| + | 2022年11月に公開された"text-davinci-003" | ||
| + | |||
| + | ===GPT-3のモデル一覧=== | ||
| + | <pre> | ||
| + | Ada | ||
| + | Text-Ada-001 | ||
| + | Babbage | ||
| + | Text-Babbage-001 | ||
| + | Curie | ||
| + | Text-curie-001 | ||
| + | Davinci* | ||
| + | Text-davinci-001 | ||
| + | Text-davinci-002 | ||
| + | Text-davinci-003 | ||
| + | Text-davinci-fine-tune-002* | ||
| + | </pre> | ||
| + | モデル一覧 https://learn.microsoft.com/ja-jp/azure/cognitive-services/openai/concepts/models | ||
| + | |||
==参考== | ==参考== | ||
https://liquidjumper.com/google-sheets/googlespreadsheet_connect_to_gpt_3 | https://liquidjumper.com/google-sheets/googlespreadsheet_connect_to_gpt_3 | ||
| − | https://auto-worker.com/blog/?p=7007 | + | https://bamka.info/googlespreadsheet-chatgpt-kansu/ |
| + | |||
| + | ChatGPTのAPIはない https://auto-worker.com/blog/?p=7007 | ||
| + | |||
| + | 各種パラメータについて https://data-analytics.fun/2021/12/01/gpt-3-api/ | ||
2023年2月2日 (木) 23:09時点における最新版
サンプルコード
/**
* GPT-3 and Google Sheets
*
* @param {string} prompt Prompt.
* @param {number} temperature (Optional) Temperature.
* @param {string} model (Optional) GPT-3 Model.
* @return Response returned by GPT-3.
* @customfunction
*/
const SECRET_KEY = "ここにAPIkeyをペースト";
//const MAX_TOKENS = 10;
const MODEL_NAME = "text-davinci-003";
const MODEL_TEMP = 0.3;
function GPT(prompt,max_tokens=30) {
const url = "https://api.openai.com/v1/completions";
const payload = {
model: MODEL_NAME,
prompt: prompt,
temperature: MODEL_TEMP,
max_tokens: max_tokens
};
const options = {
contentType: "application/json",
headers: { Authorization: "Bearer " + SECRET_KEY },
payload: JSON.stringify(payload),
};
const res = JSON.parse(UrlFetchApp.fetch(url, options).getContentText());
return res.choices[0].text.trim();
}
上のスクリプトを、拡張機能のAppsScriptへ、貼り付ける。
以下をセルに貼り付ける
=IF(ISBLANK(A1),"",GPT("10代が書きそうな日記を書いて",1000))
モデルについて
2023/1時点の最新
2022年11月に公開された"text-davinci-003"
GPT-3のモデル一覧
Ada Text-Ada-001 Babbage Text-Babbage-001 Curie Text-curie-001 Davinci* Text-davinci-001 Text-davinci-002 Text-davinci-003 Text-davinci-fine-tune-002*
モデル一覧 https://learn.microsoft.com/ja-jp/azure/cognitive-services/openai/concepts/models
参考
https://liquidjumper.com/google-sheets/googlespreadsheet_connect_to_gpt_3
https://bamka.info/googlespreadsheet-chatgpt-kansu/
ChatGPTのAPIはない https://auto-worker.com/blog/?p=7007
各種パラメータについて https://data-analytics.fun/2021/12/01/gpt-3-api/
