« 東京商工会議所の「東商版 すぐできる! 株価試算」サービス | トップページ | マイクロソフトのイメージクリエイターというAI »

2024/11/11

Copilotでもやってみた

ChatGPTに聞きながら、仕組みを作ってみたのときは、ChatGPTを使った。その後、Geminiでもやってみようとやってみた。そして今度は、Copilotではどうかと思いまして。

Copilotに同じ質問をした

公平にCopilotにChatGPTに入力したのと同じ質問、プロンプトを入力してみた。

20241025-185228

全く同じものをコピペした。

当然だが、またまた回答が違う

またまた回答が違った。当たり前だけど。
Copilotでは、先にcode.gsが出てきたよ。

function doGet() {
return HtmlService.createHtmlOutputFromFile('index');
}

function sendEmails(subject, body, label) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sending');
var data = sheet.getDataRange().getValues();
var headers = data[0];

for (var i = 1; i < data.length; i++) {
var row = data[i];
var email = row[headers.indexOf('メールアドレス')];
var customSubject = replaceVariables(subject, row, headers);
var customBody = replaceVariables(body, row, headers);

MailApp.sendEmail(email, customSubject, customBody);

// Add label
GmailApp.getMessagesForThreads(GmailApp.search('subject:' + customSubject))
.forEach(function(thread) {
thread.getMessages().forEach(function(message) {
message.addLabel(GmailApp.createLabel(label));
});
});
}
}

function replaceVariables(text, row, headers) {
var replacements = {
'$氏名': row[headers.indexOf('氏名')],
'$役職': row[headers.indexOf('役職')],
'$会社名': row[headers.indexOf('会社名')],
'$部署': row[headers.indexOf('部署')],
'$コメント': row[headers.indexOf('コメント')]
};

for (var key in replacements) {
text = text.replace(new RegExp(key, 'g'), replacements[key]);
}

return text;
}

index.htmlはこちら。

<!DOCTYPE html>
<html>
<head>
<base target="_top">
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
textarea {
width: 100%;
height: 150px;
}
input[type=text] {
width: 100%;
margin-bottom: 10px;
}
input[type=button] {
margin-top: 10px;
}
</style>
</head>
<body>
<h1>メール送信システム</h1>
<form id="emailForm">
<label for="subject">メールタイトル</label><br>
<input type="text" id="subject" name="subject"><br>
<label for="body">メール本文</label><br>
<textarea id="body" name="body"></textarea><br>
<label for="label">ラベル</label><br>
<input type="text" id="label" name="label"><br>
<input type="button" value="送信" onclick="confirmSend()">
<input type="button" value="キャンセル" onclick="confirmCancel()">
</form>

<script>
function confirmSend() {
var subject = document.getElementById('subject').value;
var body = document.getElementById('body').value;

if (!subject) {
alert('メールタイトルを入力してください');
return;
}

if (!body) {
alert('本文を入力してください');
return;
}

if (confirm('本当に送信しますか')) {
google.script.run.sendEmails(
subject,
body,
document.getElementById('label').value
);
alert('メールを送信しました');
}
}

function confirmCancel() {
if (confirm('本当に終了しますか')) {
google.script.host.close();
}
}
</script>
</body>
</html>

プログラムをチェックしてみる

code.gsをチェックしたところ、バグはなさそう。加えて、GeminiでもChatGPTでも問題になっていたラベルも行けそうなコードになっている。実際には、メールの件名を引っかけてラベルを付けるというプログラムになっているので、件名が全く同じものがあると、きっとラベルが無駄に付いてしまうなと思う。

コードとしては、Copilotが一番良いように思う。

 

« 東京商工会議所の「東商版 すぐできる! 株価試算」サービス | トップページ | マイクロソフトのイメージクリエイターというAI »

パソコン・インターネット」カテゴリの記事

AI利用」カテゴリの記事

コメント

コメントを書く

コメントは記事投稿者が公開するまで表示されません。

(ウェブ上には掲載しません)

« 東京商工会議所の「東商版 すぐできる! 株価試算」サービス | トップページ | マイクロソフトのイメージクリエイターというAI »

カテゴリー

最近のトラックバック