Skip to content

Commit 5b5ffda

Browse files
committed
docs: overhaul documentation
Signed-off-by: tylerslaton <[email protected]>
1 parent 78273e0 commit 5b5ffda

18 files changed

+380
-706
lines changed

README.md

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -240,31 +240,19 @@ Tool instructions go here.
240240

241241
Tool parameters are key-value pairs defined at the beginning of a tool block, before any instructional text. They are specified in the format `key: value`. The parser recognizes the following keys (case-insensitive and spaces are ignored):
242242

243-
`Name`: The name of the tool.
244243

245-
`Model Name`: The OpenAI model to use, by default it uses "gpt-4-turbo-preview"
244+
| Key | Description |
245+
|------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
246+
| `Name` | The name of the tool. |
247+
| `Model Name` | The OpenAI model to use, by default it uses "gpt-4-turbo-preview" |
248+
| `Description` | The description of the tool. It is important that this properly describes the tool's purpose as the description is used by the LLM. |
249+
| `Internal Prompt`| Setting this to `false` will disable the built-in system prompt for this tool. |
250+
| `Tools` | A comma-separated list of tools that are available to be called by this tool. |
251+
| `Args` | Arguments for the tool. Each argument is defined in the format `arg-name: description`. |
252+
| `Max Tokens` | Set to a number if you wish to limit the maximum number of tokens that can be generated by the LLM. |
253+
| `JSON Response` | Setting to `true` will cause the LLM to respond in a JSON format. If you set true you must also include instructions in the tool. |
254+
| `Temperature` | A floating-point number representing the temperature parameter. By default, the temperature is 0. Set to a higher number for more creativity. |
246255

247-
`Description`: The description of the tool. It is important that the properly describes the tool's purpose as the
248-
description is used by the LLM to determine if the tool is to be invoked.
249-
250-
`Internal Prompt`: Setting this to `false` will disable the built in system prompt for this tool. GPTScript includes a
251-
default system prompt to instruct the AI to behave more like a script engine and not a "helpful assistant."
252-
253-
`Tools`: A comma-separated list of tools that are available to be called by this tool. A tool can only call the tools
254-
that are defined here. A tool name can reference a name in the current file, or a file relative to the current directory
255-
of the tool file, a http(s) URL, or a file in GitHub using github.com/username/repo/file.gpt format. When referencing
256-
a file or URL the tool loaded is the first tool in the file. To reference a specific tool in a file or URL use the
257-
syntax `tool-name from file-or-url`.
258-
259-
`Args`: Arguments for the tool. Each argument is defined in the format `arg-name: description`. All arguments are essentially
260-
strings. No other type really exists as all input and output to tools is text based.
261-
262-
`Max Tokens`: Set to a number if you wish to limit the maximum number of tokens that can be generated by the LLM.
263-
264-
`JSON Response`: Setting to `true` will cause the LLM to respond in a JSON format. If you set true you must also include instructions in the tool
265-
to inform the LLM to respond in some JSON structure.
266-
267-
`Temperature`: A floating-point number representing the temperature parameter. By default the temperature is 0. Set to a higher number to make the LLM more creative.
268256

269257
#### Tool Body
270258

File renamed without changes.

docs/docs/03-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.
4+
The process for authoring a tool is as simple as creating a `tool.gpt` file in the root directory of your project.
5+
This file is itself a GPTScript that defines the tool's name, description, and what it should do.
6+
7+
For example, you can create a tool to read the contents of a webpage and return it to the user. The `tool.gpt` file for this tool might look like this:
8+
9+
```yaml
10+
Description: Read and summarize the content of a webpage.
11+
Tools: sys.html2text
12+
Args: url: The URL of the webpage.
13+
14+
Read the the contents of the webpage at ${url} and summarize it.
15+
```
16+
17+
You can also utilize traditional code-based tools. For example, here's an example of the `tool.gpt` file for the `image-generation` tool which wraps a python CLI:
18+
19+
```yaml
20+
Description: Generates images based on the specified parameters and returns a list of URLs to the generated images.
21+
Args: prompt: (required) The text prompt based on which the GPT model will generate a response
22+
Args: size: (optional) The size of the image to generate, format WxH (e.g. 1024x1024). Defaults to 1024x1024.
23+
Args: quality: (optional) The quality of the generated image. Allowed values are "standard" or "hd". Default is "standard".
24+
Args: number: (optional) The number of images to generate. Defaults to 1.
25+
26+
#!/usr/bin/env python3 ${GPTSCRIPT_TOOL_DIR}/cli.py --prompt="${prompt}" --size="${size}" --quality="${quality}" --number="${number}"
27+
```
28+
29+
At the bottom you'll notice a shebang (`#!/usr/bin/env ...`) 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.
30+
If there is no shebang line, then it will be treated as natural language for the LLM to process.
31+
32+
:::tip
33+
Every arg becomes an environment variable when the tool is invoked. So instead of accepting args using flags like `--size="${size}", your program can just read the `size` environment variable.
34+
:::
35+
36+
## Quickstart
37+
38+
This is a guide for writing portable tools for GPTScript. The supported languages currently are Python, NodeJS, and Go. This guide uses Python but you can see documentation for the other language below.
39+
40+
### 1. Write the code
41+
42+
Create a file called `tool.py` with the following contents:
43+
44+
```python
45+
import os
46+
import requests
47+
48+
print(requests.get(os.getenv("url")).text)
49+
```
50+
51+
Create a file called `requirements.txt` with the following contents:
52+
53+
```
54+
requests
55+
```
56+
57+
### 2. Create the tool
58+
59+
Create a file called `tool.gpt` with the following contents:
60+
61+
```
62+
Description: Returns the contents of a webpage.
63+
Args: url: The URL of the webpage.
64+
65+
#!/usr/bin/env python3 ${GPTSCRIPT_TOOL_DIR}/tool.py
66+
```
67+
68+
The `GPTSCRIPT_TOOL_DIR` environment variable is automatically populated by GPTScript so that the tool
69+
will be able to find the `tool.py` file no matter what the user's current working directory is.
70+
71+
If you make the tool available in a public GitHub repo, then you will be able to refer to it by
72+
the URL, i.e. `github.com/<user>/<repo name>`. GPTScript will automatically set up a Python virtual
73+
environment, install the required packages, and execute the tool.
74+
75+
### 3. Use the tool
76+
77+
Here is an example of how you can use the tool once it is on GitHub:
78+
79+
```
80+
Tools: github.com/<user>/<repo name>
81+
82+
Get the contents of https://github.com
83+
```
84+
85+
## Sharing Tools
86+
87+
GPTScript is designed to easily export and import tools. Doing this is currently based entirely around the use of GitHub repositories. You can export a tool by creating a GitHub repository and ensureing you have the `tool.gpt` file in the root of the repository. You can then import the tool into a GPTScript by specifying the URL of the repository in the `tools` section of the script. For example, we can leverage the `image-generation` tool by adding the following line to a GPTScript:
88+
89+
```yaml
90+
tools: github.com/gptscript-ai/image-generation
91+
92+
Generate an image of a city skyline at night.
93+
```
94+
95+
### Supported Languages
96+
97+
GPTScript can execute any binary that you ask it to. However, it can also manage the installation of a language runtime and dependencies for you. Currently this is only supported for a few languages. Here are the supported languages and examples of tools written in those languages:
98+
99+
| Language | Example |
100+
|----------|---------|
101+
| `Python` | [Image Generation](https://github.com/gptscript-ai/image-generation) - Generate images based on a prompt |
102+
| `Node.js` | [Vision](https://github.com/gptscript-ai/vision) - Analyze and interpret images |
103+
| `Golang` | [Search](https://github.com/gptscript-ai/search) - Use various providers to search the internet |
104+
105+
106+
## Automatic Documentation
107+
108+
Each GPTScript tool is self-documented using the `tool.gpt` file. You can automatically generate documentation for your tools by visiting `tools.gptscript.ai/<github repo url>`. This documentation site allows others to easily search and explore the tools that have been created.
109+
110+
You can add more information about how to use your tool by adding an `examples` directory to your repository and adding a collection of `.gpt` files that demonstrate how to use your tool. These examples will be automatically included in the documentation.
111+
112+
For more information and to explore existing tools, visit [tools.gptscript.ai](https://tools.gptscript.ai).

docs/docs/04-use-cases.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Use Cases
2+
3+
## Retrieval
4+
5+
Retrieval-Augmented Generation (RAG) leverages a knowledge base outside of the training data before consulting the LLM to generate a response.
6+
The following GPTScript implements RAG:
7+
8+
```yaml
9+
name: rag
10+
description: implements retrieval-augmented generation
11+
args: prompt: a string
12+
tools: query
13+
14+
First query the ${prompt} in the knowledge base, then construsts an answer to ${prompt} based on the result of the query.
15+
16+
---
17+
18+
name: query
19+
description: queries the prompt in the knowledge base
20+
args: prompt: a string
21+
22+
... (implementation of knowledge base query follows) ...
23+
```
24+
25+
The idea behind RAG is simple. Its core logic can be implemented in one GPTScript statement: `First query the ${prompt} in the knowledge base, then construsts an answer to ${prompt} based on the result of the query.` The real work of building RAG lies in the tool that queries your knowledge base.
26+
27+
You construct the appropriate query tool based on the type of knowledge base you have.
28+
29+
| Knowledge Base | Query Tool |
30+
|------|------|
31+
| A vector database storing common document types such as text, HTML, PDF, and Word | Integrate with LlamaIndex for vector database support [Link to example]|
32+
| Use the public or private internet to supply up-to-date knowledge | Implement query tools using a search engine, as shown in [`search.gpt`](https://github.com/gptscript-ai/gptscript/tree/main/examples/search.gpt)|
33+
| A structured database supporting SQL such as sqlite, MySQL, PostgreSQL, and Oracle DB | Implement query tools using database command line tools such as `sqlite` and `mysql` [Link to example]|
34+
| An ElasticSearch/OpenSearch database storing logs or other text files | Implement query tools using database command line tools [Link to example]|
35+
| Other databases such as graph or time series databases | Implement query tools using database command line tools [Link to example]|
36+
37+
## Task Automation
38+
39+
### Planning
40+
41+
Here is a GPTScript that produces a detailed travel itinerary based on inputs from a user: [`travel-agent.gpt`](https://github.com/gptscript-ai/gptscript/tree/main/examples/travel-agent.gpt)
42+
43+
### Web UI Automation
44+
45+
Here is a GPTScript that automates a web browser to browse and navigate website, extract information: [coachella-browse.gpt](https://github.com/gptscript-ai/gptscript/browser/tree/main/examples/coachella-browse.gpt)
46+
47+
For additional examples, please explore [here](https://github.com/gptscript-ai/gptscript/browser?tab=readme-ov-file#examples).
48+
49+
### API Automation
50+
51+
Here are a few GPTScripts that interact with issues on GitHub:
52+
53+
- [Create GitHub Issues](https://github.com/gptscript-ai/gptscript/create-github-issues/tree/main/examples/example.gpt)
54+
- [Modify GitHub Issues](https://github.com/gptscript-ai/gptscript/modify-github-issues/tree/main/examples/example.gpt)
55+
- [Query GitHub Issues](https://github.com/gptscript-ai/gptscript/query-github-issues/tree/main/examples/example.gpt)
56+
57+
### CLI Automation
58+
59+
Here is a GPTScript that automates Kubernetes operations by driving the `kubectl` command line. [Link to example here]
60+
61+
## Agents and Assistants
62+
63+
Agents and assistants are synonyms. They are software programs that leverage LLM to carry out tasks.
64+
65+
In GPTScript, agents and assistants are implemented using tools. Tools can use other tools. Tools can be implemented using natural language prompts or using traditional programming languages such as Python or JavaScript. You can therefore build arbitrarily complex agents and assistants in GPTScript. Here is an example of an assistant that leverages an HTTP client, MongoDB, and Python code generation to display Hacker News headlines: [`hacker-news-headlines.gpt`](https://github.com/gptscript-ai/gptscript/tree/main/examples/hacker-news-headlines.gpt)
66+
67+
## Data Analysis
68+
69+
Depending on the context window supported by the LLM, you can either send a large amount of data to the LLM to analyze in one shot or supply data in batches.
70+
71+
### Summarization
72+
73+
Here is a GPTScript that sends a large document in batches to the LLM and produces a summary of the entire document. [hamlet-summarizer](https://github.com/gptscript-ai/gptscript/tree/main/examples/hamlet-summarizer)
74+
75+
Here is a GPTScript that reads the content of a large SQL database and produces a summary of the entire database. [Link to example here]
76+
77+
### Tagging
78+
79+
Here is a GPTScript that performs sentiment analysis on the input text: [Social Media Post Sentiment Analyzer](https://github.com/gptscript-ai/gptscript/tree/main/examples/sentiments)
80+
81+
### CSV Files
82+
83+
Here is a GPTScript that reads the content of a CSV file and make query using natural language: [csv-reader.gpt](https://github.com/gptscript-ai/gptscript/csv-reader/tree/main/examples/csv-reader.gpt)
84+
85+
### Understanding Code
86+
87+
Here is a GPTScript that summarizes the code stored under the current directory: [`describe-code.gpt`](https://github.com/gptscript-ai/gptscript/tree/main/examples/describe-code.gpt)
88+
89+
## Vision, Image, and Audio
90+
91+
### Vision
92+
93+
Here is an example of a web app that leverages GPTScript to recognize ingredients in a photo and suggest a recipe based on them: [recipe-generator](https://github.com/gptscript-ai/gptscript/tree/main/examples/recipegenerator).
94+
95+
### Image Generation
96+
97+
Here is a GPTScript that takes a story prompt and generates an illustrated children's book: [story-book.gpt](https://github.com/gptscript-ai/gptscript/tree/main/examples/story-book)
98+
99+
## Memory Management
100+
101+
LLMs are stateless. That's why GPTScript by default caches LLM invocations. LLM apps need to keep memory outside of the model.
102+
103+
GPTScript provides a means to manage memory that persists across multiple LLM invocations. The relevant information can be extracted and passed into the LLM as part of the context. In addition, LLM can utilize tools to obtain additional data from the memory maintained in GPTScript.
104+
105+
[More details to follow.]
106+
107+
## Chatbots
108+
109+
GPTScript in combination with Rubra UI provide you with a turn-key implementation of chatbots. [More details to follow]

docs/docs/05-how-it-works.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# How it works
2+
3+
**_GPTScript is composed of tools._** Each tool performs a series of actions similar to a function. Tools have available
4+
to them other tools that can be invoked similar to a function call. While similar to a function, the tools are
5+
primarily implemented with a natural language prompt. **_The interaction of the tools is determined by the AI model_**,
6+
the model determines if the tool needs to be invoked and what arguments to pass. Tools are intended to be implemented
7+
with a natural language prompt but can also be implemented with a command or HTTP call.
8+
9+
## Example
10+
11+
Below are two tool definitions, separated by `---`. The first tool does not require a name or description, but
12+
every tool after name and description are required. The first tool, has the parameter `tools: bob` meaning that the tool named `bob` is available to be called if needed.
13+
14+
```yaml
15+
tools: bob
16+
17+
Ask Bob how he is doing and let me know exactly what he said.
18+
19+
---
20+
name: bob
21+
description: I'm Bob, a friendly guy.
22+
args: question: The question to ask Bob.
23+
24+
When asked how I am doing, respond with "Thanks for asking "${question}", I'm doing great fellow friendly AI tool!"
25+
```
26+
27+
Put the above content in a file named `bob.gpt` and run the following command:
28+
29+
```shell
30+
$ gptscript bob.gpt
31+
```
32+
33+
```
34+
OUTPUT:
35+
36+
Bob said, "Thanks for asking 'How are you doing?', I'm doing great fellow friendly AI tool!"
37+
```
38+
39+
Tools can be implemented by invoking a program instead of a natural language prompt. The below
40+
example is the same as the previous example but implements Bob using python.
41+
42+
```yaml
43+
Tools: bob
44+
45+
Ask Bob how he is doing and let me know exactly what he said.
46+
47+
---
48+
Name: bob
49+
Description: I'm Bob, a friendly guy.
50+
Args: question: The question to ask Bob.
51+
52+
#!python3
53+
54+
import os
55+
56+
print(f"Thanks for asking {os.environ['question']}, I'm doing great fellow friendly AI tool!")
57+
```
58+
59+
With these basic building blocks you can create complex scripts with AI interacting with AI, your local system, data,
60+
or external services.
61+

0 commit comments

Comments
 (0)