Skip to content

chore: move cache options to GlobalOptions #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions gptscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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{
Expand Down
5 changes: 3 additions & 2 deletions opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand All @@ -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)
Expand All @@ -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"`
Expand Down