From d2e9015e07a85b26b9be4b4922442420ab15f842 Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Tue, 3 Sep 2024 09:28:57 -0400 Subject: [PATCH 1/2] chore: move cache dir option to GlobalOptions Signed-off-by: Donnie Adams --- README.md | 1 + gptscript_test.go | 2 +- opts.go | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 04fc514..725e81c 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ The GPTScript instance allows the caller to run gptscript files, tools, and othe 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. +- `CacheDir`: The directory to use for caching. Default (""), which uses the default cache directory. - `APIKey`: Specify an OpenAI API key for authenticating requests - `BaseURL`: A base URL for an OpenAI compatible API (the default is `https://api.openai.com/v1`) - `DefaultModel`: The default model to use for chat completion requests diff --git a/gptscript_test.go b/gptscript_test.go index 325cb86..3797707 100644 --- a/gptscript_test.go +++ b/gptscript_test.go @@ -414,7 +414,7 @@ func TestRestartFailedRun(t *testing.T) { Instructions: instructions, }, } - run, err := g.Evaluate(context.Background(), Options{DisableCache: true, GlobalOptions: GlobalOptions{Env: []string{"EXIT_CODE=1"}}}, tools...) + run, err := g.Evaluate(context.Background(), Options{GlobalOptions: GlobalOptions{Env: []string{"EXIT_CODE=1"}}, DisableCache: true}, tools...) if err != nil { t.Fatalf("Error executing tool: %v", err) } diff --git a/opts.go b/opts.go index bf91422..191a8d0 100644 --- a/opts.go +++ b/opts.go @@ -7,6 +7,7 @@ type GlobalOptions struct { OpenAIBaseURL string `json:"BaseURL"` DefaultModel string `json:"DefaultModel"` DefaultModelProvider string `json:"DefaultModelProvider"` + CacheDir string `json:"CacheDir"` Env []string `json:"env"` } @@ -31,6 +32,7 @@ func (g GlobalOptions) toEnv() []string { func completeGlobalOptions(opts ...GlobalOptions) GlobalOptions { var result GlobalOptions for _, opt := range opts { + result.CacheDir = firstSet(opt.CacheDir, result.CacheDir) result.OpenAIAPIKey = firstSet(opt.OpenAIAPIKey, result.OpenAIAPIKey) result.OpenAIBaseURL = firstSet(opt.OpenAIBaseURL, result.OpenAIBaseURL) result.DefaultModel = firstSet(opt.DefaultModel, result.DefaultModel) @@ -55,10 +57,9 @@ func firstSet[T comparable](in ...T) T { type Options struct { GlobalOptions `json:",inline"` + DisableCache bool `json:"disableCache"` Confirm bool `json:"confirm"` Input string `json:"input"` - DisableCache bool `json:"disableCache"` - CacheDir string `json:"cacheDir"` SubTool string `json:"subTool"` Workspace string `json:"workspace"` ChatState string `json:"chatState"` From aa14fb67ac83b4f87466517a75110a5db552f7cb Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Tue, 3 Sep 2024 09:34:01 -0400 Subject: [PATCH 2/2] fix: address a flake in the chat tests Signed-off-by: Donnie Adams --- gptscript_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gptscript_test.go b/gptscript_test.go index 3797707..e705c98 100644 --- a/gptscript_test.go +++ b/gptscript_test.go @@ -785,8 +785,8 @@ func TestFileChat(t *testing.T) { } inputs := []string{ "List the 3 largest of the Great Lakes by volume.", - "For the second one in the list: what is the volume cubic miles?", - "For the third one in the list: what is the total area in square miles?", + "What is the second one in the list?", + "What is the third?", } expectedOutputs := []string{