diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index f4227ea0..0da12ebf 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -97,18 +97,6 @@ func (r *Runner) Close() { r.ports.CloseDaemons() } -type ErrContinuation struct { - State *State -} - -func (e *ErrContinuation) Prompt() string { - return *e.State.Continuation.Result -} - -func (e *ErrContinuation) Error() string { - return fmt.Sprintf("chat continuation required: %s", e.Prompt()) -} - type ChatResponse struct { Done bool `json:"done"` Content string `json:"content"` @@ -188,25 +176,11 @@ func (r *Runner) Chat(ctx context.Context, prevState ChatState, prg types.Progra } func (r *Runner) Run(ctx context.Context, prg types.Program, env []string, input string) (output string, err error) { - monitor, err := r.factory.Start(ctx, &prg, env, input) - if err != nil { - return "", err - } - defer func() { - monitor.Stop(output, err) - }() - - callCtx := engine.NewContext(ctx, &prg) - state, err := r.call(callCtx, monitor, env, input) + resp, err := r.Chat(ctx, nil, prg, env, input) if err != nil { return "", err } - if state.Continuation != nil { - return "", &ErrContinuation{ - State: state, - } - } - return *state.Result, nil + return resp.Content, nil } type Event struct { diff --git a/pkg/tests/runner_test.go b/pkg/tests/runner_test.go index 666eca03..6f94d43c 100644 --- a/pkg/tests/runner_test.go +++ b/pkg/tests/runner_test.go @@ -6,7 +6,6 @@ import ( "os" "testing" - "github.com/gptscript-ai/gptscript/pkg/runner" "github.com/gptscript-ai/gptscript/pkg/tests/tester" "github.com/gptscript-ai/gptscript/pkg/types" "github.com/hexops/autogold/v2" @@ -516,10 +515,11 @@ func TestChat(t *testing.T) { }`).Equal(t, toJSONString(t, resp)) } -func TestChatRunError(t *testing.T) { +func TestChatRunNoError(t *testing.T) { r := tester.NewRunner(t) - _, err := r.Run("", "") - autogold.Expect(`"{\n \"continuation\": {\n \"state\": {\n \"completion\": {\n \"Model\": \"gpt-4-turbo-preview\",\n \"InternalSystemPrompt\": false,\n \"Tools\": null,\n \"Messages\": [\n {\n \"role\": \"system\",\n \"content\": [\n {\n \"text\": \"This is a chatbot\"\n }\n ]\n },\n {\n \"role\": \"assistant\",\n \"content\": [\n {\n \"text\": \"TEST RESULT CALL: 1\"\n }\n ]\n }\n ],\n \"MaxTokens\": 0,\n \"Temperature\": null,\n \"JSONResponse\": false,\n \"Grammar\": \"\",\n \"Cache\": null\n }\n },\n \"result\": \"TEST RESULT CALL: 1\"\n },\n \"continuationToolID\": \"testdata/TestChatRunError/test.gpt:1\"\n}"`).Equal(t, toJSONString(t, toJSONString(t, err.(*runner.ErrContinuation).State))) + s, err := r.Run("", "") + require.NoError(t, err) + autogold.Expect("TEST RESULT CALL: 1").Equal(t, s) } func TestExportContext(t *testing.T) { diff --git a/pkg/tests/testdata/TestChatRunError/call1.golden b/pkg/tests/testdata/TestChatRunNoError/call1.golden similarity index 100% rename from pkg/tests/testdata/TestChatRunError/call1.golden rename to pkg/tests/testdata/TestChatRunNoError/call1.golden diff --git a/pkg/tests/testdata/TestChatRunError/test.gpt b/pkg/tests/testdata/TestChatRunNoError/test.gpt similarity index 100% rename from pkg/tests/testdata/TestChatRunError/test.gpt rename to pkg/tests/testdata/TestChatRunNoError/test.gpt