Skip to content

Commit 9e7751f

Browse files
authored
Merge pull request #167 from tylerslaton/overhaul-docs
docs: overhaul documentation
2 parents 78273e0 + 0aacf45 commit 9e7751f

18 files changed

+337
-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: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
## Quickstart
8+
9+
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.
10+
11+
### 1. Write the code
12+
13+
Create a file called `tool.py` with the following contents:
14+
15+
```python
16+
import os
17+
import requests
18+
19+
print(requests.get(os.getenv("url")).text)
20+
```
21+
22+
Create a file called `requirements.txt` with the following contents:
23+
24+
```
25+
requests
26+
```
27+
28+
### 2. Create the tool
29+
30+
Create a file called `tool.gpt` with the following contents:
31+
32+
```
33+
Description: Returns the contents of a webpage.
34+
Args: url: The URL of the webpage.
35+
36+
#!/usr/bin/env python3 ${GPTSCRIPT_TOOL_DIR}/tool.py
37+
```
38+
39+
:::tip
40+
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.
41+
:::
42+
43+
The `GPTSCRIPT_TOOL_DIR` environment variable is automatically populated by GPTScript so that the tool
44+
will be able to find the `tool.py` file no matter what the user's current working directory is.
45+
46+
If you make the tool available in a public GitHub repo, then you will be able to refer to it by
47+
the URL, i.e. `github.com/<user>/<repo name>`. GPTScript will automatically set up a Python virtual
48+
environment, install the required packages, and execute the tool.
49+
50+
### 3. Use the tool
51+
52+
Here is an example of how you can use the tool once it is on GitHub:
53+
54+
```
55+
Tools: github.com/<user>/<repo name>
56+
57+
Get the contents of https://github.com
58+
```
59+
60+
## Sharing Tools
61+
62+
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:
63+
64+
```yaml
65+
tools: github.com/gptscript-ai/image-generation
66+
67+
Generate an image of a city skyline at night.
68+
```
69+
70+
### Supported Languages
71+
72+
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:
73+
74+
| Language | Example |
75+
|----------|---------|
76+
| `Python` | [Image Generation](https://github.com/gptscript-ai/image-generation) - Generate images based on a prompt |
77+
| `Node.js` | [Vision](https://github.com/gptscript-ai/vision) - Analyze and interpret images |
78+
| `Golang` | [Search](https://github.com/gptscript-ai/search) - Use various providers to search the internet |
79+
80+
81+
### Automatic Documentation
82+
83+
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.
84+
85+
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.
86+
87+
For more information and to explore existing tools, visit [tools.gptscript.ai](https://tools.gptscript.ai).

docs/docs/04-use-cases.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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/browser/tree/main/examples/coachella-browse.gpt)
46+
47+
For additional examples, please explore [here](https://github.com/gptscript-ai/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/create-github-issues/tree/main/examples/example.gpt)
54+
- [Modify GitHub Issues](https://github.com/gptscript-ai/modify-github-issues/tree/main/examples/example.gpt)
55+
- [Query GitHub Issues](https://github.com/gptscript-ai/gptscriptquery-github-issues/tree/main/examples/example.gpt)
56+
57+
## Agents and Assistants
58+
59+
Agents and assistants are synonyms. They are software programs that leverage LLM to carry out tasks.
60+
61+
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)
62+
63+
## Data Analysis
64+
65+
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.
66+
67+
### Summarization
68+
69+
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)
70+
71+
### Tagging
72+
73+
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)
74+
75+
### CSV Files
76+
77+
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/csv-reader/tree/main/examples/csv-reader.gpt)
78+
79+
### Understanding Code
80+
81+
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)
82+
83+
## Vision, Image, and Audio
84+
85+
### Vision
86+
87+
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).
88+
89+
### Image Generation
90+
91+
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)

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+

docs/docs/06-gpt-file-reference.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# GPT File Reference
2+
3+
## Extension
4+
5+
GPTScript files use the `.gpt` extension by convention.
6+
7+
## File Structure
8+
9+
A GPTScript file has one or more tools in the file. Each tool is separated by three dashes `---` alone on a line.
10+
11+
```yaml
12+
Name: tool1
13+
Description: This is tool1
14+
15+
Do sample tool stuff.
16+
17+
---
18+
Name: tool2
19+
Description: This is tool2
20+
21+
Do more sample tool stuff.
22+
```
23+
24+
## Tool Definition
25+
26+
A tool starts with a preamble that defines the tool's name, description, args, available tools and additional parameters.
27+
The preamble is followed by the tool's body, which contains the instructions for the tool. Comments in
28+
the preamble are lines starting with `#` and are ignored by the parser. Comments are not really encouraged
29+
as the text is typically more useful in the description, argument descriptions or instructions.
30+
31+
```yaml
32+
Name: tool-name
33+
# This is a comment in the preamble.
34+
Description: Tool description
35+
# This tool can invoke tool1 or tool2 if needed
36+
Tools: tool1, tool2
37+
Args: arg1: The description of arg1
38+
39+
Tool instructions go here.
40+
```
41+
42+
## Tool Parameters
43+
44+
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):
45+
46+
| Key | Description |
47+
|------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
48+
| `Name` | The name of the tool. |
49+
| `Model Name` | The OpenAI model to use, by default it uses "gpt-4-turbo-preview" |
50+
| `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. |
51+
| `Internal Prompt`| Setting this to `false` will disable the built-in system prompt for this tool. |
52+
| `Tools` | A comma-separated list of tools that are available to be called by this tool. |
53+
| `Args` | Arguments for the tool. Each argument is defined in the format `arg-name: description`. |
54+
| `Max Tokens` | Set to a number if you wish to limit the maximum number of tokens that can be generated by the LLM. |
55+
| `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. |
56+
| `Temperature` | A floating-point number representing the temperature parameter. By default, the temperature is 0. Set to a higher number for more creativity. |
57+
58+
59+
60+
## Tool Body
61+
62+
The tool body contains the instructions for the tool which can be a natural language prompt or
63+
a command to execute. Commands must start with `#!` followed by the interpreter (e.g. `#!/bin/bash`, `#!python3`)
64+
a text that will be placed in a file and passed to the interpreter. Arguments can be references in the instructions
65+
using the format `${arg1}`.
66+
67+
```yaml
68+
name: echo-ai
69+
description: A tool that echos the input
70+
args: input: The input
71+
72+
Just return only "${input}"
73+
74+
---
75+
name: echo-command
76+
description: A tool that echos the input
77+
args: input: The input
78+
79+
#!/bin/bash
80+
81+
echo "${input}"
82+
```

0 commit comments

Comments
 (0)