Accessing the Google Pathways LLM from a Bash Script
Implementation
The Bash shell script that implements the PaLM shell as PaLMShell.bash
is a script of approximately 100 lines of code in length. This short length demonstrates the simplicity of the PaLM shell in comparison to the compiled high-level language examples available.
Ignoring line comments, the length of the PaLM shell script is nearly halved to 40 lines of code. Thus half the Bash script source code is comments to document and explain the PaLM shell Bash script.
Initialize
The initialize section initializes, or sets up, the Bash script (Listing 1). The header with information about the Bash script is reported, including the release, version, and copyright.
Listing 1
Initialize
01 PALM_KEY="NHGUBE-PBATENGF-BA-XABJVAT-EBG13-PBQVAT" 02 03 # 04 # 05 # 06 echo "PaLM Shell v1.1 (c) 2023 William F. Gilreath" 07 echo "All Rights Reserved. License is GPLv3 " 08 echo 09 10 # 11 # check if PALM_KEY empty, report error need key, exit 12 if [ -z $PALM_KEY ] 13 then 14 echo "Must have PaLM key to use PaLM API!" 15 exit 1 16 fi 17 18 date_time=$(date | date | tr ' ' '-' | tr ':' '-') 19 log_file="PaLM-$date_time.log" 20 21 echo 22 echo "Logging this session to: 'PaLM-$date_time.log'" 23 echo
The script then checks that the variable PALM_KEY
, which is the RESTful API key provided by Google to access the Pathways LLM, exists and is set. If not, the script exits, as it cannot access the RESTful API.
Then the date and time are used to create the transcript or log filename used by the script; the filename generated is then reported to the user.
Main Body Infinite Loop
The main body of the bash script for the PaLM shell is an infinite loop (Listing 2). The infinite loop is the software classic REPL. A while
loop continues the process of evaluating prompts (see the "Prompt Engineering" box for more on prompts). The command-line prompt is printed, and then the user prompt line read.
Listing 2
Main Body
01 while : 02 do 03 echo -n "PaLM>" 04 read prompt_line 05 06 #'bye' is bye/exit/quit PaLM Shell 07 if [ "$prompt_line" == "bye" ]; then 08 break 09 fi 10 11 echo "Prompt: '$prompt_line'" | tee -a $log_file 12 13 echo | tee -a $log_file #PaLM-$date_time.log 14 15 curl \ 16 -s \ 17 -H 'Content-Type: application/json' \ 18 -d '{ "prompt": { "text": '"\"$prompt_line\""' }}' \ 19 "https://generativelanguage.googleapis.com/v1beta2/models/text-bison-001: 20 generateText?key=$PALM_KEY" | jq '.candidates | .[].output' | sed 's/\\n/\n/g' 21 | tee -a $log_file #PaLM-$date_time.log 22 23 echo | tee -a $log_file ##PaLM-$date_time.log 24 25 done
Prompt Engineering
With the rise of large language models, it has become clear that the quality of the AI response often depends on the quality of the question. The concept of creating the right prompt to get the answer you want from an LLM is known as prompt engineering [4].
A better prompt will result in a better answer, thus the prompt provided by the user truly matters. There is much material about prompt engineering, and I recommend some study of the topic, especially if you want to master the subtleties of working with an LLM.
An early example of bad prompt engineering was when King Croesus of Lydia asked the Oracle of Delphi whether he should go to war against Persia [5]. The oracle responded that if Croesus attacked Persia he would "destroy a great empire."
Croesus then went to war with the Persians and lost. A great empire did fall, but it was Croesus's own empire. Croesus demonstrated an early example of flawed prompt engineering: A better prompt would have forced the oracle to be more specific.
If the input is only the command bye
, the while
loop is broken to continue the rest of the script. Otherwise the input is a prompt, in which case that prompt is reported and then sent to the Pathways LLM via a RESTful HTTP call. The response is received and then printed to the user. All the output to the user is also recorded as a transcript to the log file.
« Previous 1 2 3 4 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.
-
CachyOS Adds Support for System76's COSMIC Desktop
The August 2024 release of CachyOS includes support for the COSMIC desktop as well as some important bits for video.
-
Linux Foundation Adopts OMI to Foster Ethical LLMs
The Open Model Initiative hopes to create community LLMs that rival proprietary models but avoid restrictive licensing that limits usage.
-
Ubuntu 24.10 to Include the Latest Linux Kernel
Ubuntu users have grown accustomed to their favorite distribution shipping with a kernel that's not quite as up-to-date as other distros but that changes with 24.10.
-
Plasma Desktop 6.1.4 Release Includes Improvements and Bug Fixes
The latest release from the KDE team improves the KWin window and composite managers and plenty of fixes.
-
Manjaro Team Tests Immutable Version of its Arch-Based Distribution
If you're a fan of immutable operating systems, you'll be thrilled to know that the Manjaro team is working on an immutable spin that is now available for testing.