Skip to content

Commit f131a2a

Browse files
committed
chore: move cache options to GlobalOptions
Signed-off-by: Donnie Adams <[email protected]>
1 parent 14735f9 commit f131a2a

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ The GPTScript instance allows the caller to run gptscript files, tools, and othe
2424

2525
When creating a `GTPScript` instance, you can pass the following global options. These options are also available as run `Options`. Anything specified as a run option will take precedence over the global option.
2626

27+
- `DisableCache`: Enable or disable caching. Default (false).
28+
- `CacheDir`: The directory to use for caching. Default (""), which uses the default cache directory.
2729
- `APIKey`: Specify an OpenAI API key for authenticating requests
2830
- `BaseURL`: A base URL for an OpenAI compatible API (the default is `https://api.openai.com/v1`)
2931
- `DefaultModel`: The default model to use for chat completion requests
@@ -36,7 +38,6 @@ These are optional options that can be passed to the various `exec` functions.
3638
None of the options is required, and the defaults will reduce the number of calls made to the Model API.
3739
As noted above, the Global Options are also available to specify here. These options would take precedence.
3840

39-
- `disableCache`: Enable or disable caching. Default (false).
4041
- `subTool`: Use tool of this name, not the first tool
4142
- `input`: Input arguments for the tool run
4243
- `workspace`: Directory to use for the workspace, if specified it will not be deleted on exit

gptscript_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func TestListModelsWithDefaultProvider(t *testing.T) {
133133
func TestAbortRun(t *testing.T) {
134134
tool := ToolDef{Instructions: "What is the capital of the united states?"}
135135

136-
run, err := g.Evaluate(context.Background(), Options{DisableCache: true, IncludeEvents: true}, tool)
136+
run, err := g.Evaluate(context.Background(), Options{GlobalOptions: GlobalOptions{DisableCache: true}, IncludeEvents: true}, tool)
137137
if err != nil {
138138
t.Errorf("Error executing tool: %v", err)
139139
}
@@ -234,7 +234,7 @@ the response should be in JSON and match the format:
234234
`,
235235
}
236236

237-
run, err := g.Evaluate(context.Background(), Options{DisableCache: true}, tool)
237+
run, err := g.Evaluate(context.Background(), Options{GlobalOptions: GlobalOptions{DisableCache: true}}, tool)
238238
if err != nil {
239239
t.Errorf("Error executing tool: %v", err)
240240
}
@@ -414,7 +414,7 @@ func TestRestartFailedRun(t *testing.T) {
414414
Instructions: instructions,
415415
},
416416
}
417-
run, err := g.Evaluate(context.Background(), Options{DisableCache: true, GlobalOptions: GlobalOptions{Env: []string{"EXIT_CODE=1"}}}, tools...)
417+
run, err := g.Evaluate(context.Background(), Options{GlobalOptions: GlobalOptions{DisableCache: true, Env: []string{"EXIT_CODE=1"}}}, tools...)
418418
if err != nil {
419419
t.Fatalf("Error executing tool: %v", err)
420420
}
@@ -448,7 +448,7 @@ func TestCredentialOverride(t *testing.T) {
448448
}
449449

450450
run, err := g.Run(context.Background(), filepath.Join(wd, "test", gptscriptFile), Options{
451-
DisableCache: true,
451+
GlobalOptions: GlobalOptions{DisableCache: true},
452452
CredentialOverrides: []string{
453453
"test.ts.credential_override:TEST_CRED=foo",
454454
},
@@ -733,7 +733,7 @@ func TestToolChat(t *testing.T) {
733733
Tools: []string{"sys.chat.finish"},
734734
}
735735

736-
run, err := g.Evaluate(context.Background(), Options{DisableCache: true}, tool)
736+
run, err := g.Evaluate(context.Background(), Options{GlobalOptions: GlobalOptions{DisableCache: true}}, tool)
737737
if err != nil {
738738
t.Fatalf("Error executing tool: %v", err)
739739
}
@@ -828,7 +828,7 @@ func TestToolWithGlobalTools(t *testing.T) {
828828

829829
var eventContent string
830830

831-
run, err := g.Run(context.Background(), wd+"/test/global-tools.gpt", Options{DisableCache: true, IncludeEvents: true})
831+
run, err := g.Run(context.Background(), wd+"/test/global-tools.gpt", Options{GlobalOptions: GlobalOptions{DisableCache: true}, IncludeEvents: true})
832832
if err != nil {
833833
t.Fatalf("Error executing tool: %v", err)
834834
}

opts.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ type GlobalOptions struct {
77
OpenAIBaseURL string `json:"BaseURL"`
88
DefaultModel string `json:"DefaultModel"`
99
DefaultModelProvider string `json:"DefaultModelProvider"`
10+
DisableCache bool `json:"DisableCache"`
11+
CacheDir string `json:"CacheDir"`
1012
Env []string `json:"env"`
1113
}
1214

@@ -31,6 +33,8 @@ func (g GlobalOptions) toEnv() []string {
3133
func completeGlobalOptions(opts ...GlobalOptions) GlobalOptions {
3234
var result GlobalOptions
3335
for _, opt := range opts {
36+
result.DisableCache = firstSet(opt.DisableCache, result.DisableCache)
37+
result.CacheDir = firstSet(opt.CacheDir, result.CacheDir)
3438
result.OpenAIAPIKey = firstSet(opt.OpenAIAPIKey, result.OpenAIAPIKey)
3539
result.OpenAIBaseURL = firstSet(opt.OpenAIBaseURL, result.OpenAIBaseURL)
3640
result.DefaultModel = firstSet(opt.DefaultModel, result.DefaultModel)
@@ -57,8 +61,6 @@ type Options struct {
5761

5862
Confirm bool `json:"confirm"`
5963
Input string `json:"input"`
60-
DisableCache bool `json:"disableCache"`
61-
CacheDir string `json:"cacheDir"`
6264
SubTool string `json:"subTool"`
6365
Workspace string `json:"workspace"`
6466
ChatState string `json:"chatState"`

0 commit comments

Comments
 (0)