Accessing the Google Pathways LLM from a Bash Script
Smart Shell
The PaLMShell.bash script lets you connect to the Google Pathways API Large Language Model (PaLM) from the command line.
The PaLM shell is a simple Bash script that interfaces with the Google Pathways large language model (LLM) API [1] over a RESTful API. This method for accessing Google Pathways is simpler than a more complex implementation in a high-level compiled language. You only need a shell script – no other libraries, packages, or configuration files.
Large Language Models
Large language models, or LLMs [2], are currently very newly popular. An LLM is a neural network, but a neural network that has been trained on massive amounts of data, using massive amounts of computing power to create a model [3] with potentially billions of parameters.
The most well-known and popular LLM is ChatGPT or Chat Generative Pre-trained Transformer from OpenAI, which was trained using 175 billion parameters for the model. ChatGPT, which was launched in 2022, is available as a chatbot. Other LLMs include LLaMA (Large Language Model Meta AI) [6] from Meta and BLOOM (BigScience Large Open-science Open-access Multilingual Language Model) [7], which was created by over 1,000 researchers in artificial intelligence for large-scale public access.
For the shell-based LLM client described in this article, I will use the Pathways Language Model (PaLM) from Google. PaLM was introduced in April 2022 [8] and is trained on 540 billion parameters. This LLM is now part of Google Gemini, which is part of the Google AI Studio.
PaLM is a single LLM that can generalize across domains and tasks while being highly efficient. In May 2023, Google announced PaLM2, the next LLM. Google PaLM is available through Google's PaLM API, a RESTful interface to the online LLM service.
Several programming languages support access to the PaLM API, including Java, Python, Go, C#, and Swift. I downloaded the Java version of the client and libraries, and after some tinkering and effort, I got the Java code to run and work with Google PaLM. But the effort to get the Java source code to work as a client to the PaLM RESTful API was a challenge. I decided to roll my own Bash-based PaLM client that would be accessible from the command line.
Access by API Key
One thing you'll need to work with the Google PaLM RESTful API is an API key. You can request the API key online. I requested a key and it took approximately three days to receive it.
Bash Script Goals
The goals for a Bash script that functions as a PaLM shell are simple:
1. Connect to the Google PaLM RESTful API successfully via HTTP.
2. Operate simply, with only one shell command to exit the shell.
3. Automatically log and record the session as a shell transcript to file.
Several external utilities were used to construct the PaLM shell as a Bash script, including:
- cURL – connect to Google PaLM RESTful API via an HTTP URL.
- jq – JSON is used in the payload or body of the message.
- sed – classic stream editor.
- tee – logs output from the Bash script to an external file with an automatic name.
Two other utilities were date and tr, which were used to create the external file name used with the tee utility.
The PaLM shell has three phases:
1. Initialize
2. Infinite command loop, REPL (read, evaluate, print, loop) [9]
3. De-initialize
Initialization simply sets up the PaLM API key and reports the version, date, and license. The script checks that the PaLM API key is not empty and then creates the external log file name.
The main loop is an infinite loop that continues to read, echo prompts, print to the user, and tee to an external file. This process continues until the one PaLM command bye
, which causes the infinite loop to terminate.
The last phase of the Bash shell script is to finalize and de-initialize what is simply an exit message, and then clean exit from the Bash shell script to the operating system.
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
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
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.