Skip to content
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
30 changes: 2 additions & 28 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/tests/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down