Skip to content

Commit

Permalink
Add break tools
Browse files Browse the repository at this point in the history
  • Loading branch information
bindung committed Jun 7, 2024
1 parent 176f554 commit e1c5f04
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/engine/control.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package engine

import (
"encoding/json"
"fmt"

"github.com/gptscript-ai/gptscript/pkg/types"
)

func (e *Engine) runBreak(tool types.Tool, input string) (cmdOut *Return, cmdErr error) {
info, err := json.Marshal(tool)
if err != nil {
return nil, err
}
var dict map[string]interface{}
json.Unmarshal(info, &dict)
dict["input"] = input
info, err = json.Marshal(dict)
return nil, fmt.Errorf("TOOL_BREAK: %s", info)
}
2 changes: 2 additions & 0 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ func (e *Engine) Start(ctx Context, input string) (ret *Return, _ error) {
return e.runOpenAPI(tool, input)
} else if tool.IsEcho() {
return e.runEcho(tool)
} else if tool.IsBreak() {
return e.runBreak(tool, input)
}
s, err := e.runCommand(ctx, tool, input, ctx.ToolCategory)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/types/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
DaemonPrefix = "#!sys.daemon"
OpenAPIPrefix = "#!sys.openapi"
EchoPrefix = "#!sys.echo"
BreakPrefix = "#!sys.break"
CommandPrefix = "#!"
)

Expand Down Expand Up @@ -664,6 +665,10 @@ func (t Tool) IsEcho() bool {
return strings.HasPrefix(t.Instructions, EchoPrefix)
}

func (t Tool) IsBreak() bool {
return strings.HasPrefix(t.Instructions, BreakPrefix)
}

func (t Tool) IsHTTP() bool {
return strings.HasPrefix(t.Instructions, "#!http://") ||
strings.HasPrefix(t.Instructions, "#!https://")
Expand Down

0 comments on commit e1c5f04

Please sign in to comment.