GPTScript offers an innovative way to work with large language models (LLMs). The first public presentation took place on February 24, 2024, by Darren Shepherd on X (formerly Twitter). Already five days earlier, the initial version v0.0.1 was released on GitHub. One month later, the official announcement followed on the acorn.io website, which is how I became aware of it and chose it as my next Tech-Up topic.
Background
In his blog post, Shepherd explained that GPTScript initially started as an experiment to enable programming using natural language. The idea was to combine natural language with the functionality of traditional scripts. In doing so, the team discovered an elegant and simple model that connects AI with traditional systems, data, and code. GPTScript uses tools that can either be pure prompts or implemented with code. ChatGPT then makes it possible to link these individual tools together to efficiently handle complex tasks.
Main Features of GPTScript
One of the main features of GPTScript is definitely its user-friendliness. The syntax is mainly based on natural language, which makes it accessible to a wide range of users. In addition, GPTScript impresses with its versatility, as it can cover a variety of use cases, such as task automation, data analysis, and integration with external services. Another important feature is the seamless integration of GPTScript with traditional scripts, such as Bash or Python, as well as external HTTP services. This integration significantly expands the capabilities and application possibilities of GPTScript.
Application Possibilities
GPTScript thus offers a wide variety of application possibilities. For example, the automation of complex tasks, such as vacation planning or database management. In addition, intelligent tools can be developed that cover a variety of functions. Even demanding data analyses and their visualizations can be carried out efficiently with GPTScript, which facilitates the processing of complex data sets. Furthermore, GPTScript offers possibilities for developing applications in image, video, and audio processing, whereby powerful multimedia applications can be realized.
Practical Examples
- Chat with Local CLI:
- Enables the creation of AI integrations with CLIs or other executables on the local computer.
- Example: GitHub CLI (gh) or Kubernetes CLI (kubectl).
- Chat with an API:
- DevOps engineers often interact with cloud providers via dashboards, APIs, and CLIs. Now you can define a desired task, and ChatGPT generates and executes the necessary API calls.
- Example: With Digital Ocean’s OpenAPI specification, you can create a chatbot that can launch droplets and databases.
- Chat with Local Files:
- You can also work with local files.
- Example: Query Excel files, CSVs, and PDFs to read, transform, and then use the data.
Structure of a GPTScript
If you want to create a gptscript
, you have to create a file with the file extension .gpt
. This file can contain several tools by separating the individual areas with three hyphens (---
) on one line.
|
|
Each tool starts with a description before the actual part of the script comes with the actual content. Of course, there is also the possibility to add comments.
|
|
Parameters at a Glance
At the beginning of the script, there are different parameters that can and sometimes must be used. Particularly important are the description and the name so that ChatGPT can use the necessary tools from the context.
- Name:
- The name of the tool.
- Model Name & Global Model Name:
- The LLM model name to be used. Currently, “gpt-4” is used by default.
- Description:
- This describes the specific purpose and functionality of the tool so that the model can use the appropriate tool from the context.
- Internal Prompt:
- If set to false, the built-in system prompt for this tool is disabled.
- Tools & Global Tools:
- Defines all tools that are available.
- Credentials:
- Since it is possible to create credential tools, these can be linked separately here.
- Args:
- Arguments that the tool accepts. The format
arg-name: Description
must be used.
- Arguments that the tool accepts. The format
- Max Tokens:
- Limits the maximum number of tokens that can be generated by the LLM.
- JSON Response:
- If set to true, the LLM responds in JSON format. In this case, instructions must also be included in the tool.
- Temperature:
- A floating-point number that determines the creativity level of the model. By default, the temperature is set to 0, which produces a more deterministic and less creative response.
- Chat:
- If set to true, an interactive chat session is enabled for the tool.
- Context:
- Defines the context for the prompts. It is possible to refer to a text file, whereby different tools can share the same context.
Defining the Interpreter
The interpreter must start with #!
, for example:
#!/bin/bash
#!/python3
Tools in GPTScript
In GPTScript, tools help to extend the capabilities of a script. The idea behind this is that AI works better when it is given very specific instructions for a task. Tools make it possible to break down a problem into smaller, more focused parts, with each tool performing a specific task.
There is already a selection of GPTScript tools that you can use: GPTScript Tools.
In addition, a distinction is made between different types:
- System Tools:
- For example,
sys.read
orsys.write
(see: System Tools)
- For example,
- Custom Tools:
- If you write your own scripts and tools, you have the possibility to define several individual tools within the script.
- External Tools:
- Existing tools can be linked and used directly within the script.
Hands-On Example
In the following section, we will take a closer look at the practical application of GPTScript using a detailed example script. We will show how different tools are defined and used within the script to comprehensively demonstrate the described functions and to illustrate the diverse application possibilities of GPTScript.
Installation
First, GPTScript must be installed on the system. In our case, we will use Homebrew, a popular package management system for macOS and Linux, to simplify the installation process. This can be done by running the following command from the terminal to install GPTScript:
|
|
Creating an OpenAI API Key
To use the features of GPTScript, you need an API key from OpenAI. To do this, you need to do the following:
- Visit the OpenAI platform at OpenAI API Keys.
- Log in to an existing account or create a new one.
- Create a new API key and copy it.
After the API key has been created, it must be set as an environment variable so that GPTScript can access it. You can set the key via the terminal with the following command:
|
|
Pricing
The use of the OpenAI API is subject to charges. The exact costs depend on the amount of usage and the model chosen. OpenAI offers different pricing models that can be selected according to your needs. A detailed price list can be found on the OpenAI website at OpenAI API Pricing. It is important to be aware of the costs to avoid surprises and to plan usage accordingly.
Defining the First GPTScript File - Step 1
After installation and setting up the API key, you can create the first GPTScript file. In this example, a script called techhub-generator_01.gpt
is defined. In the following steps, I will create a new file again and again so that you can see how often you have to adjust the prompt.
The first script is used to create a suitable title and description for a Techhub blog article based on a given link. This is achieved by the following code:
|
|
By executing the script with the command:
|
|
a title and description for the specified link will be generated.
The output in the console looked like this:
|
|
The output is often quite helpful, as you can see the individual calls and what the input and output was. This will be particularly noticeable later when using multiple tools.
Step 2
After creating the first GPTScript file in the previous step, the process is continued in step 2 by adding an extended part with the tool mkdir
. This script not only creates a suitable title and description for a Techhub blog article but also generates a folder based on the slug if it does not already exist. In addition, a text file with the description is saved in this folder.
|
|
The command to execute the script is as follows:
|
|
If you are still interested in the output from the terminal, you can have a look at it in the TechHub Repo.
Thus, with this step, you get a more automated process that creates the following folder structure:
|
|
Step 3
In this step, the script is extended so that a thumbnail is also generated. This is done within the tool thumb-generator
. I used an existing tool from GptScript myself.
|
|
Again, the execution of the script.
|
|
Again, the output is located in our TechHub Repo.
Step 4
Now we come to the last step of our example script. The only thing missing is the possibility to create a Markdown file that already contains an outline with the most important topics. For this, I wrote the article-generator
.
An index.md
file should be created in the same folder where the thumbnail was generated. The title of the blog article should be added to this file. An outline for the article is created with the descriptions created. This outline can then be used as a guide when writing the article.
|
|
Now we execute the script one last time:
|
|
Especially with the length of the console output, it is also located in our Repo.
In the folder structure, you can see that an index.md
file and a thumb.png have been created. In this case, it is not just an outline, but some sentences have already been added. Here it becomes clear that the prompt would have to be much more precise in this case in order to obtain the desired result.
And this is the result of the thumb generator:
Conclusion
GPTScript actually offers a very impressive way to easily link traditional scripts with LLMs. This naturally extends the basic functionality enormously. This allows you to easily come up with a wide variety of ideas.
But of course, as with any technology, you have to deal with some challenges. What I would like to emphasize here is the writing of prompts. Anyone who has ever done prompt engineering themselves knows what a change this means. And you can already see this in such small tools that you create with GPTScript.
So far, I have not tried out all the functionalities, but there are some useful functions that you can definitely try out. These include, for example, analyzing local data.
Finally, it can be said that this offers a very simple and good way to automate different things and link them with the possibilities of LLMs. However, you have to get used to this type of development at the beginning and invest a little time to achieve the desired goals.
[!TIP]
All examples are also available in our Techhub Repository
This techup has been translated automatically by Gemini