GASからChatGPTを使ってみたのでメモ…
APIキーの取得
platform.openai.com
7 Users
294 Pockets
OpenAI API
An API for accessing new AI models developed by OpenAI
サンプルコード
function chatGpt(text) {
Logger.log(text)
var url = "https://api.openai.com/v1/chat/completions";
var apiKey = API_KEY;
var headers = {
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer ' + apiKey,
};
var postData = {
'model': 'gpt-3.5-turbo',
'messages': [{'role': 'user', 'content': text}]
};
var options = {
'method' : 'post',
'headers' : headers,
'payload' : JSON.stringify(postData),
'muteHttpExceptions':true
};
response = UrlFetchApp.fetch(url, options);
data = JSON.parse(response.getContentText('UTF-8'));
return data.choices[0].message.content
}