サービス
サービスを探す
プロ人材を探す
仕事を探す
ブログを探す

const MODEL = 'ここに使うモデルの名前';
const ENDPOINT = 'ここにAPIのURL';
function classify() {
const key = PropertiesService.getScriptProperties().getProperty('OPENAI_API_KEY');
const sheet = SpreadsheetApp.getActive().getSheetByName('問い合わせ');
const last = sheet.getLastRow();
if (last < 2) return;
const rows = sheet.getRange(2, 1, last - 1, 2).getValues();
rows.forEach((r, i) => {
if (!r[0] || r[1]) return; // 空欄と、分類済みは飛ばす
const res = UrlFetchApp.fetch(ENDPOINT, {
method: 'post',
contentType: 'application/json',
headers: { Authorization: 'Bearer ' + key },
payload: JSON.stringify({
model: MODEL,
messages: [
{ role: 'system', content: '次の問い合わせを「質問」「要望」「クレーム」「その他」のどれか1語だけで答えてください。' },
{ role: 'user', content: String(r[0]) }
]
})
});
const label = JSON.parse(res.getContentText()).choices[0].message.content.trim();
sheet.getRange(i + 2, 2).setValue(label);
});
}