Skip to content

Commit

Permalink
Merge pull request #61 from thedadams/global-cache-options
Browse files Browse the repository at this point in the history
chore: move cache options to GlobalOptions
  • Loading branch information
thedadams authored Sep 3, 2024
2 parents 14735f9 + aa14fb6 commit c0fb2e8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
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

0 comments on commit c0fb2e8

Please sign in to comment.