I must admit, I have been somewhat circumspect to what impact applications like ChatGPT would have on my work and life. I am not going to deny the potential, but there are too many stories that make me wonder, such as John Johnston’s chat with Bing. Really, I have had enough trouble handing over some of my work to colleagues, I therefore cannot see my work disappearing anytime soon, even if I were to somehow hand it over to a chatbox.
However, one area that I have found it interesting to explore is the ability to learn with the support of a chatbot. This is a use that I have seen come up in my feed. For example, Ben Collins talks about using AI tools to create formulas:
The AI tools can create formulas for you too.
ChatGPT and Bard generally give correct answers for simple formulas but it’s hit-and-miss with more complex formula asks.
Again, it pays to be as specific as possible with your prompt.
Source: What AI Can Do For You As A Google Sheets User. Is The Hype Justified? by Ben Collins
While Doug Belshaw has reflected on using AI tools to improve code:
I’ll not go into too much detail, but I wanted to replicate the style of my main archives page which is generated using the Simple Yearly Archive plugin. I duplicated archive.php in my themes folder, renamed it category.php and then tinkered around with it. ChatGPT was excellent at giving me the code I needed to do the things I wanted, including for the category RSS feed.
Source: Tinkering with WordPress category archive pages by Doug Belshaw
Through my work Microsoft account, I discovered I have access to Bing’s Co-Pilot chatbot based on OpenAI’s GPT-4. I have therefore been tinkering with this a bit. In particular, I have been using this when I have a question about creating a formula or script. For example, today I asked for a PowerShell script to change the naming format of a group of files. I began by asking:
How do I use PowerShell to swap around parts of multiple file names each split with an “”? For example, the current format is 12343_FirstName_Surname.pdf but I want it to be 12343_Surname_FirstName.pdf
Bing came back with a formula that spoke about moving around the different parts split into an array and move the elements around, however it did not account for the ‘.pdf’ ending. So I asked the following:
Using PowerShell, How do I split a file name into an array using _, but exclude the ending .pdf
It then added the missing lines associated with removing the .pdf ending at the start of the process and then adding it back at the end.
See the final script below.
# Set the current directory
$directory = "xxx"
# Get all files in the directory
$files = Get-ChildItem -Path $directory
# Loop through each file
foreach ($file in $files) {
# Remove the .pdf extension from the file name
$fileNameWithoutExtension = $file.Name.Substring(0, $file.Name.Length - 4)
# Split the file name into an array using the underscore as a delimiter
$fileParts = $fileNameWithoutExtension.Split("_")
# Swap the first and last elements of the array
$fileParts[0], $fileParts[1], $fileParts[2] = $fileParts[2], $fileParts[0], $fileParts[1]
# Join the array back into a string using the underscore as a delimiter
$newFileName = $fileParts -join "_"
# Add the file extension to the new file name
$newFileName = "$newFileName.pdf"
# Rename the file with the new file name
Rename-Item -Path $file.FullName -NewName $newFileName
}
What I have found is that although I often get an answer, it is not always the final answer or correct for that matter. This was the case when after I recently exported all my links from Diigo and asked Bing for a Google Sheets formula to check which URLs sent back a 404 and which didn’t. Co-Pilot gave me back the following formula:
=IF(HTTPResponse(A1)=404,"404 Error","No Error")
I tried this in Google Sheets only to get the error:
Unknown function: ‘HTTPResponse’.
I then asked Bing, “What is the HTTPResponse function in Google Sheets?” To which Bing responded that there was no function ‘HTTPResponse’ built-in, but that I could use UrlFetchApp.fetch
in Google Apps Script to create a custom function. It then also provided links to a number of sources which I followed, finding Adham El Banhawy’s guide the most helpful. Ironically, I then got an error in trying to run the custom script, which I raised in Co-Pilot, and was given a fix.
function getStatusCode(url) {
if (url === undefined || url === null) {
return null;
}
var url_trimmed = url.trim();
// Check if script cache has a cached status code for the given url
var cache = CacheService.getScriptCache();
var result = cache.get(url_trimmed);
// If value is not in cache/or cache is expired fetch a new request to the url
if (!result) {
var options = {
'muteHttpExceptions': true,
'followRedirects': false
};
var response = UrlFetchApp.fetch(url_trimmed, options);
var responseCode = response.getResponseCode();
// Store the response code for the url in script cache for subsequent retrievals
cache.put(url_trimmed, responseCode, 21600); // cache maximum storage duration is 6 hours
result = responseCode;
}
return result;
}
In each of my experiences of CoPilot, I have had to make adjustments to the code provided. A part of this is actually learning what is happening. However, this may well be the questions that I asked:
Source: How to write better ChatGPT prompts for the best generative AI results – David Gewirtz, ZDNet, Oct 12, 2023 Commentary by Stephen Downes
- talk to it as if it were a person
- set the stage and provide context
- have the AI assume an identity or profession
- iterate with multiple attempts
- keep it on track
- specify output format
- explicit constraints on responses
Or it may well be the trial and error
. The thought that I am left with is a comment a few months back that questioned if we have to learn what prompts to use with AI tools, how intelligent are they? I With this in mind, for me I feel that AI tools are useful as an aide, but I am circumspect about using them as the answer. I guess time will tell.As always, comments and webmentions welcome.