A new era
Good morning! I recognize two kinds of developers: those who are curious about new tools, and those who harbor negatively connoted thoughts, withdrawing from AI topics to retreat back into their mental comfort zone, in order to feel safe1.
Yes, I am on the new tools team. After I had clarified all my questions and dispelled my doubts, I needed access to the best model available. ChatGPT Pro actually costs $20 per person/month2.
Then I discovered a better option and used the OpenAI API, the platform for developers. The pricing is more flexible; we get enterprise-grade security features, are on the cutting edge, and can use the latest and greatest preview models before they are made publicly available to the masses.
(Without a valid use case, a tool is just a toy.)
ChatGPT is text-in, text-out. If we put garbage in, we will get garbage out; it depends on our prompt design. The quality of an answer can be refined by creating so-called GPTs, those are virtual assistants provided with initial instructions3, a bit like role-playing.
For example, I created two assistants: a lawyer for general contracts and a principal software engineer. The lawyer helped me find certain strategies in the field of contracts and solve questions that arose between different parties. The principal software engineer assists me with finding solutions for programming topics and quickly learning new subjects.
Assistants have two useful features: Code Interpreter and Retrieval. When the Code Interpreter is enabled, our assistant can perform precise calculations for us, e.g., cost calculations. The Retrieval feature allows us to feed our assistant with context in the form of documentation4. Please note that we get the best solutions from our assistants by refining the outcomes in a dialogue.
Yesterday, for example, I freed up 20% of my iCloud space by compressing all .pdf files. I try to avoid paper, scan most of my personal documents, and store them in my iCloud. Often these documents are disproportionately large, and I use online services to reduce their size—a time-consuming manual workflow.
GPT helped me to create a shell script that finds all .pdf files in a folder structure, compresses them, displays the sizes and the compression ratios, and finally removes the originals. The solution is primarily based on Ghostscript. For your convenience, I want to show you the script for compressing .pdf files5 below.
I must admit that I am more than impressed by this awesome new technology—no doubt, it ushers in a new era.
(Disclaimer: My Copywriter assistant corrected this post6.)
#!/bin/bash
# Define the function to compress pdf and calculate the ratio
compress_pdf() {
# Define the function to calculate the ratio inside
compression_ratio() {
original_size=$1
compressed_size=$2
ratio=$(echo "scale=2; $compressed_size / $original_size * 100" | bc)
echo "$ratio"
}
original_file="$1"
compressed_file="${original_file%.pdf}-compressed.pdf"
# Perform the compression with Ghostscript
if gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$compressed_file" "$original_file";
then
original_size=$(stat -f%z "$original_file")
compressed_size=$(stat -f%z "$compressed_file")
ratio=$(compression_ratio "$original_size" "$compressed_size")
# Output: original and compressed sizes and the compression ratio
echo "File: $original_file, Original Size: $original_size bytes, Compressed Size: $compressed_size bytes, Compression Ratio: $ratio%"
# Remove the original file
rm "$original_file"
else
echo "Error: Ghostscript failed to compress $original_file" >&2
fi
}
# Make sure the script can be sourced to define the function in subshells
if [[ -z "$_PDF_COMPRESSOR_RUNNING" ]]; then
find . -iname '*.pdf' ! -iname '*-compressed.pdf' -exec bash -c '_PDF_COMPRESSOR_RUNNING=1 source "${0}" && compress_pdf "$@"' "${0}" {} \;
fi
-
Of course, there are always some in between who observe and have their thoughts. It’s a little bit like the Mandelbrot set: some are inside, some are outside—and we do not know much about those on the boundary. ↵
-
In a professional setting, ChatGPT Enterprise is a must due to security concerns. ↵
-
Assistant instructions are also referred to as system prompts, a prompt that is executed before our user prompt. ↵
-
A GPT can read various file formats, such as PDFs, Word documents, and Excel sheets. ↵
-
Use at your own risk. Ghostscript must be installed manually, for example, by running
brew install ghostscript
on macOS. ↵ -
I used my assistant, Copywriter, with the following prompt to correct this post: “Please proofread this document and check for spelling and grammar: <original-post>.” The original post can be viewed by clicking “Edit on GitHub” below. ↵