Skip to content

Commit 7c0542b

Browse files
committed
feat: refactor docs and add content around tools and authoring
Signed-off-by: tylerslaton <[email protected]>
1 parent dd0c7e9 commit 7c0542b

File tree

13 files changed

+276
-138
lines changed

13 files changed

+276
-138
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ ci: build
3838
./bin/gptscript ./scripts/ci.gpt
3939

4040
serve-docs:
41-
(cd docs && npm start)
41+
(cd docs && npm i && npm start)

docs/docs/01-overview.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: Overview
3+
slug: /
4+
---
5+
6+
GPTScript is a new scripting language to automate your interaction with a Large Language Model (LLM), namely OpenAI. The ultimate goal is to create a fully natural language based programming experience. The syntax of GPTScript is largely natural language, making it very easy to learn and use. Natural language prompts can be mixed with traditional scripts such as bash and python or even external HTTP service calls. With GPTScript you can do just about anything like [plan a vacation](https://github.com/gptscript-ai/gptscript/blob/main/examples/travel-agent.gpt), [edit a file](https://github.com/gptscript-ai/gptscript/blob/main/examples/add-go-mod-dep.gpt), [run some SQL](https://github.com/gptscript-ai/gptscript/blob/main/examples/sqlite-download.gpt), or [build a mongodb/flask app](https://github.com/gptscript-ai/gptscript/blob/main/examples/hacker-news-headlines.gpt).
7+
8+
```yaml
9+
# example.gpt
10+
11+
Tools: sys.download, sys.exec, sys.remove
12+
13+
Download https://www.sqlitetutorial.net/wp-content/uploads/2018/03/chinook.zip to a
14+
random file. Then expand the archive to a temporary location as there is a sqlite
15+
database in it.
16+
17+
First inspect the schema of the database to understand the table structure.
18+
19+
Form and run a SQL query to find the artist with the most number of albums and output
20+
the result of that.
21+
22+
When done remove the database file and the downloaded content.
23+
```
24+
```
25+
$ gptscript ./example.gpt
26+
27+
OUTPUT:
28+
29+
The artist with the most number of albums in the database is Iron Maiden, with a total
30+
of 21 albums.
31+
```
32+
33+
For more examples check out the [examples](https://github.com/gptscript-ai/gptscript/blob/main/examples) directory.
34+
35+
## Community
36+
37+
Join us on Discord: [![Discord](https://img.shields.io/discord/1204558420984864829?label=Discord)](https://discord.gg/9sSf4UyAMC)

docs/docs/02-getting-started.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Getting Started
2+
3+
### 1. Install the latest release
4+
5+
#### Homebrew (macOS and Linux)
6+
7+
```shell
8+
brew install gptscript-ai/tap/gptscript
9+
```
10+
11+
#### Install Script (macOS and Linux):
12+
13+
```shell
14+
curl https://get.gptscript.ai/install.sh | sh
15+
```
16+
17+
#### WinGet (Windows)
18+
19+
```shell
20+
winget install gptscript-ai.gptscript
21+
```
22+
23+
#### Manually
24+
25+
Download and install the archive for your platform and architecture from the [releases page](https://github.com/gptscript-ai/gptscript/releases).
26+
27+
### 2. Get an API key from [OpenAI](https://platform.openai.com/api-keys).
28+
29+
```shell
30+
export OPENAI_API_KEY="your-api-key"
31+
```
32+
33+
### 3. Run Hello World
34+
35+
```shell
36+
gptscript https://get.gptscript.ai/echo.gpt --input 'Hello, World!'
37+
38+
OUTPUT:
39+
40+
Hello, World!
41+
```
42+
The model used by default is `gpt-4-turbo-preview` and you must have access to that model in your OpenAI account.
43+
44+
### 4. Extra Credit: Examples and Run Debugging UI
45+
46+
Clone examples and run debugging UI
47+
```shell
48+
git clone https://github.com/gptscript-ai/gptscript
49+
cd gptscript/examples
50+
51+
# Run the debugging UI
52+
gptscript --server
53+
```
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Overview
2+
3+
In GPTScript, tools are used to extend the capabilities of a script. The idea behind them is that AI performs better when it has very specific instructions for a given task. Tools are a way to break-up the problem into smaller and more focused pieces where each tool is responsible for a specific task. A typical flow like this is to have a main script that imports a set of tools it can use to accomplish its goal.
4+
5+
## Using Tools
6+
7+
GPTScripts can utilize tools in one of three ways:
8+
1. Built-in system tools
9+
2. In-script tools
10+
3. External tools
11+
12+
### System Tools
13+
All GPTScripts have access to system tools, like `sys.read` and `sys.write`, that can be used without any additional configuration.
14+
15+
```yaml
16+
tools: sys.read, sys.write
17+
18+
Read all of the files in my current directory, do no recurse over any subdirectories, and give me a description of this directory's contents.s
19+
```
20+
21+
System tools are a set of core tools that come packaged with GPTScript by default.
22+
23+
### In-Script Tools
24+
Things get more interesting when you start to use custom tools.
25+
26+
The most basic example of this is an in-script tool that is defined in the same file as the main script. This is useful for breaking up a large script into smaller, more manageable pieces.
27+
28+
```yaml
29+
tools: random-number
30+
31+
Select a number at random and, based on the results, write a poem about it.
32+
33+
---
34+
name: random-number
35+
description: Generate a random number between 1 and 100.
36+
37+
Select a number at random between 1 and 100 and return only the number.
38+
```
39+
40+
### External Tools
41+
42+
This is where the real power of GPTScript starts to become evident. For this example lets use the external [image-generation](https://github.com/gptscript-ai/image-generation) and [search](https://github.com/gptscript-ai/search) tools to generate an image and then search the web for similar images.
43+
44+
```yaml
45+
tools: ./image-generation, ./search, sys.read
46+
47+
Generate an image of a city skyline at night and write the resulting image to a file called city_skyline.png.
48+
49+
Take this image and search the web for similar images. Write links for the top 5 results to a file called similar_images.txt.
50+
```
51+
52+
External tools are tools that are defined by a `tool.gpt` file in their root directory. They can be imported into a GPTScript by specifying the path to the tool's root directory.
53+
54+
## Authoring External Tools
55+
You can author your own tools for your own use or to share with others. The process for authoring a tool is as simple as creating a `tool.gpt` file in the root directory of your tool This file is itself a GPTScript that defines the tool's name, description, and what it should do.
56+
57+
Here's an example of the `tool.gpt` file for the `image-generation` tool:
58+
59+
```yaml
60+
description: I am a tool that can generate images based on arguments that are sent to me. I return a list of URLs to the generated images.
61+
args: prompt: (required) The text prompt based on which the GPT model will generate a response
62+
args: model: (optional) The model to use for image generation. Defaults to "dall-e-3".
63+
args: size: (optional) The size of the image to generate, format WxH (e.g. 1024x1024). Defaults to 1024x1024.
64+
args: quality: (optional) The quality of the generated image. Allowed values are "standard" or "hd". Default is "standard".
65+
args: number: (optional) The number of images to generate. Defaults to 1.
66+
67+
#!/usr/bin/env python3 ./cli.py --prompt="${prompt}" --model="${model}" --size="${size}" --quality="${quality}" --number="${number}"
68+
```
69+
70+
At the bottom you'll notice a shebang line that specifies the command to run when the tool is invoked. This is the exact command that will be executed when the tool is used in a GPTScript. Doing this with tools allows for a high degree of reliability that the tool would not otherwise have.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Binary Tools
2+
GPTScript can call binaries and scripts located on your system or externally. This is done by defining a `tool.gpt` file in the same directory that the binary or script is located. In that `tool.gpt` file, you call it directly using the `#!` directive.
3+
4+
For example:
5+
6+
```yaml
7+
description: This is a tool that calls a binary.
8+
args: arg1: The first argument.
9+
10+
#!/usr/bin/env ./path/to/binary
11+
```
12+
13+
## Shell
14+
You can call shell scripts directly using the `#!` directive. For example:
15+
16+
```yaml
17+
description: This is a tool that calls a shell script.
18+
args: arg1: The first argument.
19+
20+
#!/usr/bin/env sh
21+
echo "Hello, world!"
22+
./path/to/script.sh
23+
```
24+
25+
## Python
26+
You can also call Python scripts directly the same way. For example:
27+
28+
```yaml
29+
description: This is a tool that calls a Python script.
30+
args: arg1: The first argument.
31+
32+
#!/usr/bin/env python3 ./path/to/script.py
33+
```
34+
35+
If you need to bootstrap a Python environment, you can use a virtual environment. For example:
36+
37+
```yaml
38+
description: This is a tool that calls a Python script in a virtual environment.
39+
args: arg1: The first argument.
40+
41+
#!/usr/bin/env sh
42+
python3 -m venv .venv
43+
pip3 install -r requirements.txt
44+
python3 ./path/to/script.py
45+
```
46+
47+
## Node
48+
49+
You can also call Node.js scripts directly the same way. For example:
50+
51+
```yaml
52+
description: This is a tool that calls a Node.js script.
53+
args: arg1: The first argument.
54+
55+
#!/usr/bin/env node ./path/to/script.js
56+
```
57+
58+
If you need to bootstrap a Node.js environment, you can use call npm in the `tool.gpt` file. For example:
59+
60+
```yaml
61+
description: This is a tool that calls a Node.js script with a package manager.
62+
args: arg1: The first argument.
63+
64+
#!/usr/bin/env sh
65+
npm install
66+
node ./path/to/script.js
67+
```
68+
69+
## Golang
70+
71+
You can also call Golang binaries directly the same way. For example:
72+
73+
```yaml
74+
description: This is a tool that calls a Golang binary.
75+
args: arg1: The first argument.
76+
77+
#!/usr/bin/env ./path/to/binary
78+
```
79+
80+
If you need to bootstrap a Golang binary, you can the go CLI to build it before running it. For example:
81+
82+
```yaml
83+
description: This is a tool that calls a Golang binary.
84+
args: arg1: The first argument.
85+
86+
#!/usr/bin/env sh
87+
go build -o ./path/to/binary
88+
./path/to/binary
89+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "Authoring",
3+
"position": 1
4+
}
File renamed without changes.
File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "Offerings",
3+
"position": 2
4+
}

docs/docs/tools/_category_.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
{
22
"label": "Tools",
3-
"position": 2,
4-
"link": {
5-
"type": "generated-index",
6-
"description": "Explore the various tools on offer for gptscripts"
7-
}
3+
"position": 2
84
}

0 commit comments

Comments
 (0)