Skip to content

Commit f27e193

Browse files
authored
docs: various improvements and standardizing terms (#689)
Signed-off-by: Grant Linville <[email protected]>
1 parent 3a9cfa3 commit f27e193

11 files changed

+200
-132
lines changed

docs/docs/02-examples/02-api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@ For a more advanced DigitalOcean chatbot, see our [DigitalOcean Agent](https://g
105105

106106
To read more about OpenAPI tools in GPTScript, see the [OpenAPI Tools](../03-tools/03-openapi.md) article.
107107

108-
To read more about credential storage in GPTScript, see the [Credentials](../02-credentials.md) article.
108+
To read more about credential storage in GPTScript, see the [Credentials](../06-credentials.md) article.

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

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# 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.
2+
3+
In GPTScript, tools are used to extend the capabilities of a script.
4+
The idea behind them is that AI performs better when it has very specific instructions for a given task.
5+
Tools are a way to break up the problem into smaller and more focused pieces where each tool is responsible for a specific task.
6+
A typical pattern is to have a main script that imports a set of tools it can use to accomplish its goal.
37

48
GPTScripts can utilize tools in one of three ways:
59
1. Built-in system tools
610
2. In-script tools
711
3. External tools
812

913
### System Tools
14+
1015
All GPTScripts have access to system tools, like `sys.read` and `sys.write`, that can be used without any additional configuration.
1116

1217
```yaml
@@ -16,11 +21,14 @@ Read all of the files in my current directory, do not recurse over any subdirect
1621
```
1722

1823
System tools are a set of core tools that come packaged with GPTScript by default.
24+
To see a list of the system tools, run `gptscript --list-tools`.
1925

2026
### In-Script Tools
21-
Things get more interesting when you start to use custom tools.
2227

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.
28+
Things get more interesting when you start to write your own tools.
29+
30+
The most basic example of this is an in-script tool that is defined in the same file as the main script.
31+
This is useful for breaking up a large script into smaller, more manageable pieces.
2432

2533
```yaml
2634
tools: random-number
@@ -35,7 +43,9 @@ Select a number at random between 1 and 100 and return only the number.
3543
```
3644

3745
### External Tools
38-
You can refer to GPTScript tool files that are served on the web or stored locally. This is useful for sharing tools across multiple scripts or for using tools that are not part of the core GPTScript distribution.
46+
47+
You can refer to GPTScript tool files that are served on the web or stored locally.
48+
This is useful for sharing tools across multiple scripts or for using tools that are not part of the core GPTScript distribution.
3949

4050
```yaml
4151
tools: https://get.gptscript.ai/echo.gpt
@@ -51,9 +61,11 @@ tools: echo.gpt
5161
Echo the phrase "Hello, World!".
5262
```
5363

54-
You can also refer to OpenAPI definition files as though they were GPTScript tool files. GPTScript will treat each operation in the file as a separate tool. For more details, see [OpenAPI Tools](03-openapi.md).
64+
You can also refer to OpenAPI definition files as though they were GPTScript tool files.
65+
GPTScript will treat each operation in the file as a separate tool. For more details, see [OpenAPI Tools](03-openapi.md).
5566

5667
### Packaged Tools on GitHub
68+
5769
GPTScript tools can be packaged and shared on GitHub, and referred to by their GitHub URL. For example:
5870

5971
```yaml
@@ -64,5 +76,9 @@ Generate an image of a city skyline at night and write the resulting image to a
6476
Take this image and write a description of it in the style of pirate.
6577
```
6678

79+
:::important
80+
The GitHub URL must not be prefixed with `http://` or `https://`.
81+
:::
82+
6783
When this script is run, GPTScript will locally clone the referenced GitHub repos and run the tools referenced inside them.
6884
For more info on how this works, see [Authoring Tools](02-authoring.md).

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

+19-8
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
You can author your own tools for your use or to share with others.
44
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.
5+
This file is a GPTScript that defines the tool's name, description, and what it should do.
66

77
## Quickstart
88

9-
This is a guide for writing portable tools for GPTScript. The supported languages currently are Python, Node.js, and Go. This guide uses Python, but you can see documentation for the other language below.
9+
This is a guide for writing portable tools for GPTScript. The supported languages currently are Python, Node.js, and Go.
10+
This guide uses Python, but you can see documentation for the other languages below.
1011

1112
### 1. Write the code
1213

@@ -65,17 +66,24 @@ gptscript github.com/<user>/<repo name> '{"url": "https://github.com"}'
6566

6667
## Sharing Tools
6768

68-
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 ensuring 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:
69+
GPTScript is designed to easily export and import tools.
70+
Doing this is currently based entirely around the use of GitHub repositories.
71+
You can export a tool by creating a GitHub repository and ensuring you have the `tool.gpt` file in the root of the repository.
72+
You can then import the tool into a GPTScript by specifying the URL of the repository in the `tools` section of the script.
73+
For example, we can leverage the `image-generation` tool by adding the following line to a GPTScript:
6974

7075
```yaml
7176
tools: github.com/gptscript-ai/dalle-image-generation
7277

7378
Generate an image of a city skyline at night.
7479
```
7580

76-
### Supported Languages
81+
## Supported Languages
7782

78-
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:
83+
GPTScript can execute any binary that you ask it to.
84+
However, it can also manage the installation of a language runtime and dependencies for you.
85+
Currently, this is only supported for a few languages.
86+
Here are the supported languages and examples of tools written in those languages:
7987

8088
| Language | Example |
8189
|-----------|----------------------------------------------------------------------------------------------------------------|
@@ -84,10 +92,13 @@ GPTScript can execute any binary that you ask it to. However, it can also manage
8492
| `Golang` | [Search](https://github.com/gptscript-ai/search) - Use various providers to search the internet |
8593

8694

87-
### Automatic Documentation
95+
## Automatic Documentation
8896

89-
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.
97+
Each GPTScript tool is self-documented using the `tool.gpt` file.
98+
You can automatically generate documentation for your tools by visiting `https://tools.gptscript.ai/<github repo url>`.
99+
This documentation site allows others to easily search and explore the tools that have been created.
90100

91-
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.
101+
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.
102+
These examples will be automatically included in the documentation.
92103

93104
For more information and to explore existing tools, visit [tools.gptscript.ai](https://tools.gptscript.ai).

docs/docs/03-tools/03-openapi.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Will be resolved as `https://api.example.com/v1`.
4242
## Authentication
4343

4444
:::warning
45-
All authentication options will be completely ignored if the server uses HTTP and not HTTPS.
45+
All authentication options will be completely ignored if the server uses HTTP and not HTTPS, unless the request is for `localhost` or 127.0.0.1.
4646
This is to protect users from accidentally sending credentials in plain text.
4747
HTTP is only OK, if it's on localhost/127.0.0.1.
4848
:::

docs/docs/03-tools/04-credential-tools.md

+39-16
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Here is a simple example of a credential provider tool that uses the builtin `sy
1313

1414
```yaml
1515
# my-credential-tool.gpt
16-
name: my-credential-tool
16+
Name: my-credential-tool
1717

1818
#!/usr/bin/env bash
1919

@@ -27,25 +27,31 @@ echo "{\"env\":{\"MY_ENV_VAR\":\"$credential\"}}"
2727
Continuing with the above example, this is how you can use it in a script:
2828

2929
```yaml
30-
credentials: my-credential-tool.gpt
30+
Credentials: my-credential-tool.gpt as myCred
3131

3232
#!/usr/bin/env bash
3333

3434
echo "The value of MY_ENV_VAR is $MY_ENV_VAR"
3535
```
3636

37+
:::note
38+
GPTScript accepts `Cred:`, `Creds:`, `Credential:`, and `Credentials:` as valid directives.
39+
:::
40+
3741
When you run the script, GPTScript will call the credential provider tool first, set the environment variables from its
3842
output, and then run the script body. The credential provider tool is called by GPTScript itself. GPTScript does not ask the
3943
LLM about it or even tell the LLM about the tool.
4044

4145
If GPTScript has called the credential provider tool in the same context (more on that later), then it will use the stored
4246
credential instead of fetching it again.
4347

48+
To delete the credential that just got stored, run `gptscript credential delete myCred`.
49+
4450
You can also specify multiple credential tools for the same script, but they must be on separate lines:
4551

4652
```yaml
47-
credentials: credential-tool-1.gpt
48-
credentials: credential-tool-2.gpt
53+
Credentials: credential-tool-1.gpt
54+
Credentials: credential-tool-2.gpt
4955

5056
(tool stuff here)
5157
```
@@ -56,7 +62,7 @@ GPTScript also provides a generic credential tool (`github.com/gptscript-ai/cred
5662
where you only need to set one environment variable. Here is an example of how to use it:
5763

5864
```yaml
59-
credentials: github.com/gptscript-ai/credential as myCredentialName with MY_ENV_VAR as env and "this message will be displayed to the user" as message and key as field
65+
Credentials: github.com/gptscript-ai/credential as myCredentialName with MY_ENV_VAR as env and "this message will be displayed to the user" as message and key as field
6066

6167
(tool stuff here)
6268
```
@@ -66,24 +72,24 @@ the environment variable `MY_ENV_VAR` and stored in a credential called `myCrede
6672

6773
See [the repo](https://github.com/gptscript-ai/credential) for more information.
6874

69-
## Credential Tool Arguments
75+
## Credential Tool Parameters
7076

71-
A credential tool may define arguments. Here is an example:
77+
A credential tool may define parameters. Here is an example:
7278

7379
```yaml
74-
name: my-credential-tool
75-
args: env: the environment variable to set
76-
args: val: the value to set it to
80+
Name: my-credential-tool
81+
Parameter: env: the environment variable to set
82+
Parameter: val: the value to set it to
7783

7884
#!/usr/bin/env bash
7985

8086
echo "{\"env\":{\"$ENV\":\"$VAL\"}}"
8187
```
8288

83-
When you reference this credential tool in another file, you can use syntax like this to set both arguments:
89+
When you reference this credential tool in another file, you can use syntax like this to set both parameters:
8490

8591
```yaml
86-
credential: my-credential-tool.gpt with MY_ENV_VAR as env and "my value" as val
92+
Credential: my-credential-tool.gpt with MY_ENV_VAR as env and "my value" as val
8793

8894
(tool stuff here)
8995
```
@@ -92,7 +98,7 @@ In this example, the tool's output would be `{"env":{"MY_ENV_VAR":"my value"}}`
9298

9399
## Storing Credentials
94100

95-
By default, credentials are automatically stored in the credential store. Read the [main credentials page](../02-credentials.md)
101+
By default, credentials are automatically stored in the credential store. Read the [main credentials page](../06-credentials.md)
96102
for more information about the credential store.
97103

98104
:::note
@@ -105,7 +111,7 @@ will not be stored in the credentials store.
105111
When you reference a credential tool in your script, you can give it an alias using the `as` keyword like this:
106112

107113
```yaml
108-
credentials: my-credential-tool.gpt as myAlias
114+
Credentials: my-credential-tool.gpt as myAlias
109115

110116
(tool stuff here)
111117
```
@@ -121,8 +127,7 @@ A credential context is basically a namespace for credentials. If you have multi
121127
you can switch between them by defining them in different credential contexts. The default context is called `default`,
122128
and this is used if none is specified.
123129

124-
You can set the credential context to use with the `--credential-context` flag when running GPTScript. For
125-
example:
130+
You can set the credential context to use with the `--credential-context` flag when running GPTScript. For example:
126131

127132
```bash
128133
gptscript --credential-context my-azure-workspace my-azure-script.gpt
@@ -181,3 +186,21 @@ In this example, `toolA` provides the variables `ENV_VAR_1` and `ENV_VAR_2`,
181186
This will read the values of `ENV_VAR_1` through `ENV_VAR_4` from the current environment and set them for the credential.
182187
This is a direct mapping of environment variable names. **This is not recommended when overriding credentials for
183188
multiple tools that use the same environment variable names.**
189+
190+
## Credential Refresh (Advanced)
191+
192+
Some use cases (such as OAuth) may involve the need to refresh expired credentials.
193+
To support this, your credential tool can return other fields besides `env` in its JSON output.
194+
This is the full list of supported fields in the credential tool output:
195+
196+
- `env` (type: object) - The environment variables to set.
197+
- `expiresAt` (type: string, timestamp in RFC3339 format) - The time when the credential expires.
198+
- `refreshToken` (type: string) - The refresh token to use to refresh the credential.
199+
200+
When GPTScript tries to use a credential that has a defined `expiresAt` time, it will check if the credential has expired.
201+
If the credential has expired, it will run the credential tool again, and the current value of the credential will be
202+
set to the environment variable `GPTSCRIPT_EXISTING_CREDENTIAL` as a JSON string. This way, the credential tool can check for
203+
that environment variable, and if it is set, get the refresh token from the existing credential and use it to refresh and return a new credential,
204+
typically without user interaction.
205+
206+
For an example of a tool that uses the refresh feature, see the [Gateway OAuth2 tool](https://github.com/gptscript-ai/gateway-oauth2).

0 commit comments

Comments
 (0)