Skip to content

Commit e1c5f04

Browse files
committed
Add break tools
1 parent 176f554 commit e1c5f04

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

Diff for: pkg/engine/control.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package engine
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
7+
"github.com/gptscript-ai/gptscript/pkg/types"
8+
)
9+
10+
func (e *Engine) runBreak(tool types.Tool, input string) (cmdOut *Return, cmdErr error) {
11+
info, err := json.Marshal(tool)
12+
if err != nil {
13+
return nil, err
14+
}
15+
var dict map[string]interface{}
16+
json.Unmarshal(info, &dict)
17+
dict["input"] = input
18+
info, err = json.Marshal(dict)
19+
return nil, fmt.Errorf("TOOL_BREAK: %s", info)
20+
}

Diff for: pkg/engine/engine.go

+2
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ func (e *Engine) Start(ctx Context, input string) (ret *Return, _ error) {
252252
return e.runOpenAPI(tool, input)
253253
} else if tool.IsEcho() {
254254
return e.runEcho(tool)
255+
} else if tool.IsBreak() {
256+
return e.runBreak(tool, input)
255257
}
256258
s, err := e.runCommand(ctx, tool, input, ctx.ToolCategory)
257259
if err != nil {

Diff for: pkg/types/tool.go

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const (
1919
DaemonPrefix = "#!sys.daemon"
2020
OpenAPIPrefix = "#!sys.openapi"
2121
EchoPrefix = "#!sys.echo"
22+
BreakPrefix = "#!sys.break"
2223
CommandPrefix = "#!"
2324
)
2425

@@ -664,6 +665,10 @@ func (t Tool) IsEcho() bool {
664665
return strings.HasPrefix(t.Instructions, EchoPrefix)
665666
}
666667

668+
func (t Tool) IsBreak() bool {
669+
return strings.HasPrefix(t.Instructions, BreakPrefix)
670+
}
671+
667672
func (t Tool) IsHTTP() bool {
668673
return strings.HasPrefix(t.Instructions, "#!http://") ||
669674
strings.HasPrefix(t.Instructions, "#!https://")

0 commit comments

Comments
 (0)