「Google/スプレットシート/ChatGPT」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→参考) |
|||
| 行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> | ||
==モデルについて== | ==モデルについて== | ||
2023/1時点の最新 | 2023/1時点の最新 | ||
2023年1月30日 (月) 10:15時点における版
サンプルコード
/**
* 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();
}
モデルについて
2023/1時点の最新
2022年11月に公開された"text-davinci-003"
参考
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/
モデル一覧 https://learn.microsoft.com/ja-jp/azure/cognitive-services/openai/concepts/models
