🙃
ChatGPT API の使い方(Google Apps Script)
ChatGPT APIをGoogle Apps Script(Javascript)で動かしてみた
const SECRET_KEY = "sk-xxxxxxxxxx"; // OpenAIからとってきてね
function Gpt35turbo(role,prompt) {
const url = "https://api.openai.com/v1/chat/completions";
const payload = {
model: 'gpt-3.5-turbo',
"messages": [
{"role": "system", "content": role},
{"role": "user", "content": prompt}
],
};
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].message.content
}
ChatGPTに対して役割を強めに強制できるのでCoTが捗りますね。
関連記事
Discussion