ChatGPTではなく、Geminiでもやってみた
ChatGPTに聞きながら、仕組みを作ってみたのときは、ChatGPTを使ったわけだけど、GASを使うんだから、Geminiでもやってみようと思い立った。
Geminiに同じ質問をした
GeminiにChatGPTに入力したのと同じ質問、プロンプトを入力してみた。
全く同じものをコピペした。
当然だが、回答が違う
回答は違ったものが出てきた。当然かな。index.htmlとcode.gsを下に示す。
まずは、index.html。
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<title>メール送信アプリ</title>
<style>
/* CSSスタイルは必要に応じて調整してください */
/* 例: */
body {
font-family: sans-serif;
margin: 20px;
}
</style>
<script>
function sendEmail() {
// メールタイトル、本文、ラベルを取得
const title = document.getElementById('title').value;
const body = document.getElementById('body').value;
const label = document.getElementById('label').value;// 入力チェック
if (!title) {
alert('メールタイトルを入力してください');
return;
}
if (!body) {
alert('本文を入力してください');
return;
}// 確認ダイアログ
if (confirm('本当に送信しますか?')) {
google.script.run
.sendEmail(title, body, label)
.then(() => {
alert('送信完了');
})
.catch(error => {
alert('エラーが発生しました: ' + error);
});
}
}function cancel() {
if (confirm('本当に終了しますか?')) {
google.script.run.withSuccessHandler(google.script.host.close).doGet();
}
}
</script>
</head>
<body>
<input type="text" id="title" placeholder="メールタイトル">
<textarea id="body" placeholder="メール本文"></textarea>
<input type="text" id="label" placeholder="ラベル">
<button onclick="sendEmail()">送信</button>
<button onclick="cancel()">キャンセル</button>
</body>
</html>
続いて、code.gs。
function doGet() {
return HtmlService.createHtmlOutputFromFile('index');
}function sendEmail(title, body, label) {
// Googleスプレッドシートからデータを取得
const sheet = SpreadsheetApp.getActiveSheet();
const data = sheet.getDataRange().getValues();// 各行に対してメール送信
data.forEach(row => {
const to = row[0]; // メールアドレス
const variables = {
'氏名': row[1],
'役職': row[2],
// ... 他の変数も同様に追加
};// メール本文をテンプレート化
let template = body;
Object.keys(variables).forEach(key => {
template = template.replace(new RegExp(`\\$${key}`, 'g'), variables[key]);
});// メール送信
GmailApp.sendEmail(to, title, template, {
label: label
});
});
}
違いをチェックしてみる
まず、すぐに気づくのが、codeの方、「他の変数も同様に追加しろ」とコメントがあり、途中で止めている(笑)。それから、index.htmlについては、titleタグがある。確か、ChatGPTにはタイトルはなかった。一方、CSSは結構適当(笑)。
細かなところだと、sendEmailのメソッドの引数の書き方が違う。ラベルのところの書き方が違うのだが、この書き方でラベルが付くのか。と思ったら付かないじゃん!テストしてみたら、全然付かない(笑)。
今度は、Copilotでもやってみようかな。
« ラクロスボックス日本代表 | トップページ | 東京商工会議所の「東商版 すぐできる! 株価試算」サービス »
「AI利用」カテゴリの記事
- マイクロソフトのイメージクリエイターというAI(2024.11.14)
- ChatGPT:canvas(2024.12.21)
- Copilotでもやってみた(2024.11.11)
- ChatGPTではなく、Geminiでもやってみた(2024.11.06)
- メールを配信するプログラム(2024.10.31)
コメント