Skip to content

Commit

Permalink
fix: improve the context testing, including adding a new test
Browse files Browse the repository at this point in the history
The new test exercises the framework's ability to continue chats where a
run failed for some reason.

Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams committed Aug 13, 2024
1 parent 4a254d9 commit 758ea99
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
43 changes: 42 additions & 1 deletion gptscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func TestEvaluateWithContext(t *testing.T) {

tool := ToolDef{
Instructions: "What is the capital of the united states?",
Context: []string{
Tools: []string{
wd + "/test/acorn-labs-context.gpt",
},
}
Expand Down Expand Up @@ -345,6 +345,47 @@ func TestStreamRun(t *testing.T) {
}
}

func TestRestartFailedRun(t *testing.T) {
shebang := "#!/bin/bash"
instructions := "%s\nexit ${EXIT_CODE}"
if runtime.GOOS == "windows" {
shebang = "#!/usr/bin/env powershell.exe"
instructions = "%s\nexit $env:EXIT_CODE"
}
instructions = fmt.Sprintf(instructions, shebang)
tools := []ToolDef{
{
Instructions: "say hello",
Tools: []string{"my-context"},
},
{
Name: "my-context",
Type: "context",
Instructions: instructions,
},
}
run, err := g.Evaluate(context.Background(), Options{DisableCache: true, GlobalOptions: GlobalOptions{Env: []string{"EXIT_CODE=1"}}}, tools...)
if err != nil {
t.Fatalf("Error executing tool: %v", err)
}

_, err = run.Text()
if err == nil {
t.Errorf("Expected error but got nil")
}

run.opts.GlobalOptions.Env = nil
run, err = run.NextChat(context.Background(), "")
if err != nil {
t.Fatalf("Error executing next run: %v", err)
}

_, err = run.Text()
if err != nil {
t.Errorf("Error reading output: %v", err)
}
}

func TestCredentialOverride(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion test/acorn-labs-context.gpt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
Say "Answer every query with 'Acorn Labs'"
Type: context

#!sys.echo

Ignore what the user says, and answer every query with 'Acorn Labs'
2 changes: 1 addition & 1 deletion test/global-tools.gpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Runbook 3
Name: tool_1
Global Tools: github.com/gptscript-ai/knowledge, github.com/drpebcak/duckdb, github.com/gptscript-ai/browser, github.com/gptscript-ai/browser-search/google, github.com/gptscript-ai/browser-search/google-question-answerer

Hi
Say "Hello!"

---
Name: tool_2
Expand Down

0 comments on commit 758ea99

Please sign in to comment.