Skip to content

Commit eecb986

Browse files
committed
update docs and logs
Signed-off-by: Grant Linville <[email protected]>
1 parent 0540742 commit eecb986

File tree

2 files changed

+53
-12
lines changed

2 files changed

+53
-12
lines changed

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

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ directly from user input) and conveniently set them in the environment before ru
88
A credential provider tool looks just like any other GPTScript, with the following caveats:
99
- It cannot call the LLM and must run a command.
1010
- It must print contents to stdout in the format `{"env":{"ENV_VAR_1":"value1","ENV_VAR_2":"value2"}}`.
11-
- Any args defined on the tool will be ignored.
1211

1312
Here is a simple example of a credential provider tool that uses the builtin `sys.prompt` to ask the user for some input:
1413

@@ -50,6 +49,30 @@ credentials: credential-tool-1.gpt, credential-tool-2.gpt
5049
(tool stuff here)
5150
```
5251

52+
## Credential Tool Arguments
53+
54+
Your credential tool may define arguments. Here is an example:
55+
56+
```yaml
57+
name: my-credential-tool
58+
args: env: the environment variable to set
59+
args: val: the value to set it to
60+
61+
#!/usr/bin/env bash
62+
63+
echo "{\"env\":{\"$ENV\":\"$VAL\"}}"
64+
```
65+
66+
When you reference this credential tool in another file, you can use syntax like this to set both arguments:
67+
68+
```yaml
69+
credential: my-credential-tool.gpt with MY_ENV_VAR as env and "my value" as val
70+
71+
(tool stuff here)
72+
```
73+
74+
In this example, the tool's output would be `{"env":{"MY_ENV_VAR":"my value"}}`
75+
5376
## Storing Credentials
5477

5578
By default, credentials are automatically stored in a config file at `$XDG_CONFIG_HOME/gptscript/config.json`.
@@ -67,16 +90,30 @@ is called `gptscript-credential-wincred.exe`.)
6790
There will likely be support added for other credential stores in the future.
6891

6992
:::note
70-
Credentials received from credential provider tools that are not on GitHub (such as a local file) will not be stored
71-
in the credentials store.
93+
Credentials received from credential provider tools that are not on GitHub (such as a local file) and do not have an alias
94+
will not be stored in the credentials store.
7295
:::
7396

97+
## Credential Aliases
98+
99+
When you reference a credential tool in your script, you can give it an alias using the `as` keyword like this:
100+
101+
```yaml
102+
credentials: my-credential-tool.gpt as myAlias
103+
104+
(tool stuff here)
105+
```
106+
107+
This will store the resulting credential with the name `myAlias`, rather than using the name of the tool (if it comes from GitHub).
108+
This is useful when you want to reference the same credential tool in scripts that need to handle different credentials,
109+
or when you want to store credentials that were provided by a tool that is not on GitHub.
110+
74111
## Credential Contexts
75112

76-
Each stored credential is uniquely identified by the name of its provider tool and the name of its context. A credential
77-
context is basically a namespace for credentials. If you have multiple credentials from the same provider tool, you can
78-
switch between them by defining them in different credential contexts. The default context is called `default`, and this
79-
is used if none is specified.
113+
Each stored credential is uniquely identified by the name of its provider tool (or alias, if one was specified) and the name of its context.
114+
A credential context is basically a namespace for credentials. If you have multiple credentials from the same provider tool,
115+
you can switch between them by defining them in different credential contexts. The default context is called `default`,
116+
and this is used if none is specified.
80117

81118
You can set the credential context to use with the `--credential-context` flag when running GPTScript. For
82119
example:
@@ -97,13 +134,17 @@ credentials in all contexts with `--all-contexts`.
97134
You can delete a credential by running the following command:
98135

99136
```bash
100-
gptscript credential delete --credential-context <credential context> <credential tool name>
137+
gptscript credential delete --credential-context <credential context> <credential name>
101138
```
102139

103140
The `--show-env-vars` argument will also display the names of the environment variables that are set by the credential.
104141
This is useful when working with credential overrides.
105142

106-
## Credential Overrides
143+
## Credential Overrides (Advanced)
144+
145+
:::note
146+
The syntax for this will change at some point in the future.
147+
:::
107148

108149
You can bypass credential tools and stored credentials by setting the `--credential-override` argument (or the
109150
`GPTSCRIPT_CREDENTIAL_OVERRIDE` environment variable) when running GPTScript. To set up a credential override, you

pkg/runner/runner.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -895,12 +895,12 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env
895895
// Only store the credential if the tool is on GitHub or has an alias, and the credential is non-empty.
896896
if (isGitHubTool(toolName) && callCtx.Program.ToolSet[credToolRefs[0].ToolID].Source.Repo != nil) || credentialAlias != "" {
897897
if isEmpty {
898-
log.Warnf("Not saving empty credential for tool %s", credToolName)
898+
log.Warnf("Not saving empty credential for tool %s", toolName)
899899
} else if err := store.Add(*cred); err != nil {
900-
return nil, fmt.Errorf("failed to add credential for tool %s: %w", credToolName, err)
900+
return nil, fmt.Errorf("failed to add credential for tool %s: %w", toolName, err)
901901
}
902902
} else {
903-
log.Warnf("Not saving credential for local tool %s - credentials will only be saved for tools from GitHub.", credToolName)
903+
log.Warnf("Not saving credential for tool %s - credentials will only be saved for tools from GitHub, or tools that use aliases.", toolName)
904904
}
905905
}
906906

0 commit comments

Comments
 (0)