Skip to content

Commit 0a7d53a

Browse files
Merge pull request #291 from ibuildthecloud/main
bug: fix panic when calling nested chat tool without --force-chat
2 parents eb9e7f5 + 73f9497 commit 0a7d53a

File tree

4 files changed

+6
-32
lines changed

4 files changed

+6
-32
lines changed

pkg/runner/runner.go

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,6 @@ func (r *Runner) Close() {
9797
r.ports.CloseDaemons()
9898
}
9999

100-
type ErrContinuation struct {
101-
State *State
102-
}
103-
104-
func (e *ErrContinuation) Prompt() string {
105-
return *e.State.Continuation.Result
106-
}
107-
108-
func (e *ErrContinuation) Error() string {
109-
return fmt.Sprintf("chat continuation required: %s", e.Prompt())
110-
}
111-
112100
type ChatResponse struct {
113101
Done bool `json:"done"`
114102
Content string `json:"content"`
@@ -188,25 +176,11 @@ func (r *Runner) Chat(ctx context.Context, prevState ChatState, prg types.Progra
188176
}
189177

190178
func (r *Runner) Run(ctx context.Context, prg types.Program, env []string, input string) (output string, err error) {
191-
monitor, err := r.factory.Start(ctx, &prg, env, input)
192-
if err != nil {
193-
return "", err
194-
}
195-
defer func() {
196-
monitor.Stop(output, err)
197-
}()
198-
199-
callCtx := engine.NewContext(ctx, &prg)
200-
state, err := r.call(callCtx, monitor, env, input)
179+
resp, err := r.Chat(ctx, nil, prg, env, input)
201180
if err != nil {
202181
return "", err
203182
}
204-
if state.Continuation != nil {
205-
return "", &ErrContinuation{
206-
State: state,
207-
}
208-
}
209-
return *state.Result, nil
183+
return resp.Content, nil
210184
}
211185

212186
type Event struct {

pkg/tests/runner_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"os"
77
"testing"
88

9-
"github.com/gptscript-ai/gptscript/pkg/runner"
109
"github.com/gptscript-ai/gptscript/pkg/tests/tester"
1110
"github.com/gptscript-ai/gptscript/pkg/types"
1211
"github.com/hexops/autogold/v2"
@@ -516,10 +515,11 @@ func TestChat(t *testing.T) {
516515
}`).Equal(t, toJSONString(t, resp))
517516
}
518517

519-
func TestChatRunError(t *testing.T) {
518+
func TestChatRunNoError(t *testing.T) {
520519
r := tester.NewRunner(t)
521-
_, err := r.Run("", "")
522-
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)))
520+
s, err := r.Run("", "")
521+
require.NoError(t, err)
522+
autogold.Expect("TEST RESULT CALL: 1").Equal(t, s)
523523
}
524524

525525
func TestExportContext(t *testing.T) {

0 commit comments

Comments
 (0)