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
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
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.