Skip to content

Commit b1db1e2

Browse files
committed
feat: refactor docs and add content around tools and authoring
- chore: add note about adding local model support - docs: add image-generator cookbook - docs: add gen-docs.gpt and a make target for it Signed-off-by: tylerslaton <[email protected]>
1 parent d2054f3 commit b1db1e2

17 files changed

+416
-154
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,8 @@ validate: tidy lint
3939
ci: build
4040
./bin/gptscript ./scripts/ci.gpt
4141

42+
gen-docs: build
43+
./bin/gptscript ./scripts/gen-docs.gpt
44+
4245
serve-docs:
43-
(cd docs && npm start)
46+
(cd docs && npm i && npm start)

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
## Overview
44

5-
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.
5+
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 natural language programming experience. The syntax of GPTScript is largely natural language, making it very easy to learn and use.
66
Natural language prompts can be mixed with traditional scripts such as bash and python or even external HTTP service
7-
calls. With GPTScript you can do just about anything like [plan a vacation](./examples/travel-agent.gpt),
7+
calls. With GPTScript you can do just about anything, like [plan a vacation](./examples/travel-agent.gpt),
88
[edit a file](./examples/add-go-mod-dep.gpt), [run some SQL](./examples/sqlite-download.gpt), or [build a mongodb/flask app](./examples/hacker-news-headlines.gpt).
99

10+
| :memo: | We are currently exploring options for interacting with local models using GPTScript. |
11+
|-|:-|
12+
1013
```yaml
1114
# example.gpt
1215

@@ -59,10 +62,18 @@ Download and install the archive for your platform and architecture from the [re
5962

6063
### 2. Get an API key from [OpenAI](https://platform.openai.com/api-keys).
6164

65+
#### macOS and Linux
66+
6267
```shell
6368
export OPENAI_API_KEY="your-api-key"
6469
```
6570

71+
#### Windows
72+
73+
```powershell
74+
$env:OPENAI = 'your-api-key'
75+
```
76+
6677
### 3. Run Hello World
6778

6879
```shell
@@ -175,7 +186,7 @@ Description: Tool description
175186
# This tool can invoke tool1 or tool2 if needed
176187
Tools: tool1, tool2
177188
Args: arg1: The description of arg1
178-
189+
179190
Tool instructions go here.
180191
```
181192
#### Tool Parameters
@@ -228,7 +239,7 @@ description: A tool that echos the input
228239
args: input: The input
229240

230241
#!/bin/bash
231-
242+
232243
echo "${input}"
233244
```
234245

@@ -247,7 +258,7 @@ Join us on Discord: [![Discord](https://img.shields.io/discord/12045584209848648
247258

248259
## License
249260

250-
Copyright (c) 2023 [Acorn Labs, Inc.](http://acorn.io)
261+
Copyright (c) 2024 [Acorn Labs, Inc.](http://acorn.io)
251262

252263
Licensed under the Apache License, Version 2.0 (the "License");
253264
you may not use this file except in compliance with the License.

docs/docs/01-overview.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 natural language 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+
:::note
9+
We are currently exploring options for interacting with local models using GPTScript.
10+
:::
11+
12+
```yaml
13+
# example.gpt
14+
15+
Tools: sys.download, sys.exec, sys.remove
16+
17+
Download https://www.sqlitetutorial.net/wp-content/uploads/2018/03/chinook.zip to a
18+
random file. Then expand the archive to a temporary location as there is a sqlite
19+
database in it.
20+
21+
First inspect the schema of the database to understand the table structure.
22+
23+
Form and run a SQL query to find the artist with the most number of albums and output
24+
the result of that.
25+
26+
When done remove the database file and the downloaded content.
27+
```
28+
```
29+
$ gptscript ./example.gpt
30+
31+
OUTPUT:
32+
33+
The artist with the most number of albums in the database is Iron Maiden, with a total
34+
of 21 albums.
35+
```
36+
37+
For more examples check out the [examples](https://github.com/gptscript-ai/gptscript/blob/main/examples) directory.
38+
39+
## Community
40+
41+
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: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
#### macOS and Linux
30+
31+
```shell
32+
export OPENAI_API_KEY="your-api-key"
33+
```
34+
35+
#### Windows
36+
37+
```powershell
38+
$env:OPENAI = 'your-api-key'
39+
```
40+
41+
### 3. Run Hello World
42+
43+
```shell
44+
gptscript https://get.gptscript.ai/echo.gpt --input 'Hello, World!'
45+
46+
OUTPUT:
47+
48+
Hello, World!
49+
```
50+
The model used by default is `gpt-4-turbo-preview` and you must have access to that model in your OpenAI account.
51+
52+
### 4. Extra Credit: Examples and Run Debugging UI
53+
54+
Clone examples and run debugging UI
55+
```shell
56+
git clone https://github.com/gptscript-ai/gptscript
57+
cd gptscript/examples
58+
59+
# Run the debugging UI
60+
gptscript --server
61+
```

docs/docs/100-tools/01-using.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Using Tools
2+
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.
3+
4+
GPTScripts can utilize tools in one of three ways:
5+
1. Built-in system tools
6+
2. In-script tools
7+
3. External tools
8+
9+
### System Tools
10+
All GPTScripts have access to system tools, like `sys.read` and `sys.write`, that can be used without any additional configuration.
11+
12+
```yaml
13+
tools: sys.read, sys.write
14+
15+
Read all of the files in my current directory, do not recurse over any subdirectories, and give me a description of this directory's contents.
16+
```
17+
18+
System tools are a set of core tools that come packaged with GPTScript by default.
19+
20+
### In-Script Tools
21+
Things get more interesting when you start to use custom tools.
22+
23+
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.
24+
25+
```yaml
26+
tools: random-number
27+
28+
Select a number at random and, based on the results, write a poem about it.
29+
30+
---
31+
name: random-number
32+
description: Generate a random number between 1 and 100.
33+
34+
Select a number at random between 1 and 100 and return only the number.
35+
```
36+
37+
### External Tools
38+
39+
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.
40+
41+
:::note
42+
There will be better packaging and distribution for external tools in the future. For now, this assumes you have the tools cloned locally and are pointing to their repos directly.
43+
:::
44+
45+
```yaml
46+
tools: ./image-generation/tool.gpt, ./vision/tool.gpt, sys.read
47+
48+
Generate an image of a city skyline at night and write the resulting image to a file called city_skyline.png.
49+
50+
Take this image and write a description of it in the style of pirate.
51+
```
52+
53+
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.

docs/docs/100-tools/02-authoring.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Authoring Tools
2+
3+
You can author your own tools for your 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 project. This file is itself a GPTScript that defines the tool's name, description, and what it should do.
4+
5+
Here's an example of the `tool.gpt` file for the `image-generation` tool:
6+
7+
```yaml
8+
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.
9+
args: prompt: (required) The text prompt based on which the GPT model will generate a response
10+
args: model: (optional) The model to use for image generation. Defaults to "dall-e-3".
11+
args: size: (optional) The size of the image to generate, format WxH (e.g. 1024x1024). Defaults to 1024x1024.
12+
args: quality: (optional) The quality of the generated image. Allowed values are "standard" or "hd". Default is "standard".
13+
args: number: (optional) The number of images to generate. Defaults to 1.
14+
15+
#!/usr/bin/env python3 ./cli.py --prompt="${prompt}" --model="${model}" --size="${size}" --quality="${quality}" --number="${number}"
16+
```
17+
18+
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.
19+
20+
:::tip
21+
Every arg becomes an environment variable when the tool is invoked.
22+
:::
23+
24+
## Binary Tools
25+
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.
26+
27+
For example:
28+
29+
```yaml
30+
description: This is a tool that calls a binary.
31+
args: arg1: The first argument.
32+
33+
#!/usr/bin/env ./path/to/binary --arg1="${arg1}"
34+
```
35+
36+
## Shell
37+
You can call shell scripts directly using the `#!` directive. For example:
38+
39+
```yaml
40+
description: This is a tool that calls a shell script.
41+
args: arg1: The first argument.
42+
43+
#!/usr/bin/env sh
44+
echo "Hello, world!"
45+
./path/to/script.sh --arg1="${arg1}"
46+
```
47+
48+
## Python
49+
You can call Python scripts directly, for example:
50+
51+
```yaml
52+
description: This is a tool that calls a Python script.
53+
args: arg1: The first argument.
54+
55+
#!/usr/bin/env python3 ./path/to/script.py --arg1="${arg1}"
56+
```
57+
58+
If you need to bootstrap a Python environment, you can use a virtual environment. For example:
59+
60+
```yaml
61+
description: This is a tool that calls a Python script in a virtual environment.
62+
args: arg1: The first argument.
63+
64+
#!/usr/bin/env sh
65+
python3 -m venv .venv
66+
pip3 install -r requirements.txt
67+
python3 ./path/to/script.py --arg1="${arg1}"
68+
```
69+
70+
## Node
71+
72+
You can call Node.js scripts directly, for example:
73+
74+
```yaml
75+
description: This is a tool that calls a Node.js script.
76+
args: arg1: The first argument.
77+
78+
#!/usr/bin/env node ./path/to/script.js --arg1="${arg1}"
79+
```
80+
81+
If you need to bootstrap a Node.js environment, you can use call npm in the `tool.gpt` file. For example:
82+
83+
```yaml
84+
description: This is a tool that calls a Node.js script with a package manager.
85+
args: arg1: The first argument.
86+
87+
#!/usr/bin/env sh
88+
npm install
89+
node ./path/to/script.js --arg1="${arg1}"
90+
```
91+
92+
## Golang
93+
94+
You can call Golang binaries directly, for example:
95+
96+
```yaml
97+
description: This is a tool that calls a Golang binary.
98+
args: arg1: The first argument.
99+
100+
#!/usr/bin/env ./path/to/binary --arg1="${arg1}"
101+
```
102+
103+
If you need to bootstrap a Golang binary, you can the go CLI to build it before running it. For example:
104+
105+
```yaml
106+
description: This is a tool that calls a Golang binary.
107+
args: arg1: The first argument.
108+
109+
#!/usr/bin/env sh
110+
go build -o ./path/to/binary
111+
./path/to/binary --arg1="${arg1}"
112+
```

docs/docs/tools/image-generation.md renamed to docs/docs/100-tools/03-offerings/01-image-generation.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
# Image Generation
22

3-
## Overview
4-
53
The `image-generation` tool leverages OpenAI's DALL-E model to convert textual descriptions into images. It offers a versatile approach to creating visual content, making it suitable for a wide range of applications, from content creation to design assistance.
64

75
For more information, check out the tool [here](https://github.com/gptscript-ai/image-generation)
86

7+
## Installation
8+
We are working on an process where installation of tools will be as simple as
9+
referencing the tool's link in your GPTScript. For now, you can follow the steps below to install the image-generation tool.
10+
11+
1. Clone the image-generation tool repository [from GitHub](https://github.com/gptscript-ai/image-generation).
12+
13+
```shell
14+
git clone https://github.com/gptscript-ai/image-generation
15+
```
16+
17+
2. Run `make bootstrap` to setup the python venv and install the required dependencies.
18+
19+
```shell
20+
make bootstrap
21+
```
22+
23+
3. Reference `<path-to-the-repo>/tool.gpt` in your GPTScript.
24+
925
## Usage
1026
To use the Image Generation tool, you need to make sure that the OPENAI_API_KEY environment variable is set to your OpenAI API key. You can obtain an API key from the OpenAI platform if you don't already have one.
1127

1228
With that setup, you can use it in any GPTScript like so:
1329

14-
:::tip
15-
This script assumes you have the `image-generation` tool repo cloned locally and located at `./image-generation`. The ability to import tools from remote
16-
locations is coming soon.
17-
:::
18-
1930
```
20-
tools: ./image-generation, sys.write
31+
tools: ./image-generation/tool.gpt, sys.download, sys.write
2132
2233
Generate an image of a city skyline at night with a resolution of 512x512 pixels.
2334

docs/docs/tools/system.md renamed to docs/docs/100-tools/03-offerings/02-system.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,12 @@ Writes content to a specified file.
104104

105105
- `content`: The content to be written to the file.
106106
- `filename`: The filename where the content should be written.
107+
108+
## sys.append
109+
110+
Appends the contents to a file.
111+
112+
#### Arguments
113+
114+
- `content`: The content to append.
115+
- `filename`: The name of the file to append to.

0 commit comments

Comments
 (0)