Skip to content

Commit c0fb2e8

Browse files
authored
Merge pull request #61 from thedadams/global-cache-options
chore: move cache options to GlobalOptions
2 parents 14735f9 + aa14fb6 commit c0fb2e8

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ 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+
- `CacheDir`: The directory to use for caching. Default (""), which uses the default cache directory.
2728
- `APIKey`: Specify an OpenAI API key for authenticating requests
2829
- `BaseURL`: A base URL for an OpenAI compatible API (the default is `https://api.openai.com/v1`)
2930
- `DefaultModel`: The default model to use for chat completion requests

gptscript_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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{Env: []string{"EXIT_CODE=1"}}, DisableCache: true}, tools...)
418418
if err != nil {
419419
t.Fatalf("Error executing tool: %v", err)
420420
}
@@ -785,8 +785,8 @@ func TestFileChat(t *testing.T) {
785785
}
786786
inputs := []string{
787787
"List the 3 largest of the Great Lakes by volume.",
788-
"For the second one in the list: what is the volume cubic miles?",
789-
"For the third one in the list: what is the total area in square miles?",
788+
"What is the second one in the list?",
789+
"What is the third?",
790790
}
791791

792792
expectedOutputs := []string{

opts.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type GlobalOptions struct {
77
OpenAIBaseURL string `json:"BaseURL"`
88
DefaultModel string `json:"DefaultModel"`
99
DefaultModelProvider string `json:"DefaultModelProvider"`
10+
CacheDir string `json:"CacheDir"`
1011
Env []string `json:"env"`
1112
}
1213

@@ -31,6 +32,7 @@ func (g GlobalOptions) toEnv() []string {
3132
func completeGlobalOptions(opts ...GlobalOptions) GlobalOptions {
3233
var result GlobalOptions
3334
for _, opt := range opts {
35+
result.CacheDir = firstSet(opt.CacheDir, result.CacheDir)
3436
result.OpenAIAPIKey = firstSet(opt.OpenAIAPIKey, result.OpenAIAPIKey)
3537
result.OpenAIBaseURL = firstSet(opt.OpenAIBaseURL, result.OpenAIBaseURL)
3638
result.DefaultModel = firstSet(opt.DefaultModel, result.DefaultModel)
@@ -55,10 +57,9 @@ func firstSet[T comparable](in ...T) T {
5557
type Options struct {
5658
GlobalOptions `json:",inline"`
5759

60+
DisableCache bool `json:"disableCache"`
5861
Confirm bool `json:"confirm"`
5962
Input string `json:"input"`
60-
DisableCache bool `json:"disableCache"`
61-
CacheDir string `json:"cacheDir"`
6263
SubTool string `json:"subTool"`
6364
Workspace string `json:"workspace"`
6465
ChatState string `json:"chatState"`

0 commit comments

Comments
 (0)