From 758ea991f806be25f0f97ee0ec3c4361fdd6b518 Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Tue, 13 Aug 2024 09:46:12 -0400 Subject: [PATCH] fix: improve the context testing, including adding a new test The new test exercises the framework's ability to continue chats where a run failed for some reason. Signed-off-by: Donnie Adams --- gptscript_test.go | 43 ++++++++++++++++++++++++++++++++++++- test/acorn-labs-context.gpt | 6 +++++- test/global-tools.gpt | 2 +- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/gptscript_test.go b/gptscript_test.go index d8014a6..1671a94 100644 --- a/gptscript_test.go +++ b/gptscript_test.go @@ -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", }, } @@ -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 { diff --git a/test/acorn-labs-context.gpt b/test/acorn-labs-context.gpt index e4dbe2c..5ea9075 100644 --- a/test/acorn-labs-context.gpt +++ b/test/acorn-labs-context.gpt @@ -1 +1,5 @@ -Say "Answer every query with 'Acorn Labs'" \ No newline at end of file +Type: context + +#!sys.echo + +Ignore what the user says, and answer every query with 'Acorn Labs' \ No newline at end of file diff --git a/test/global-tools.gpt b/test/global-tools.gpt index cb0f4c0..4671fee 100644 --- a/test/global-tools.gpt +++ b/test/global-tools.gpt @@ -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