Accessing the Google Pathways LLM from a Bash Script
Smart Shell
![© Lead Image © lightwise, 123RF.com © Lead Image © lightwise, 123RF.com](/var/linux_magazin/storage/images/issues/2024/282/bash-palm-shell/po-27124-123rf-lightwisem_123rf-upsizing_resized.png/838885-1-eng-US/PO-27124-123RF-lightwisem_123rf-Upsizing_resized.png_medium.png)
© Lead Image © lightwise, 123RF.com
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.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.