Skip to content

chore: remove ToString method for tools #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2024
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
15 changes: 8 additions & 7 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ type Call struct {
}

type CallContext struct {
ID string `json:"id"`
Tool Tool `json:"tool"`
DisplayText string `json:"displayText"`
InputContext []InputContext `json:"inputContext"`
ToolCategory ToolCategory `json:"toolCategory,omitempty"`
ToolName string `json:"toolName,omitempty"`
ParentID string `json:"parentID,omitempty"`
ID string `json:"id"`
Tool Tool `json:"tool"`
AgentGroup []ToolReference `json:"agentGroup,omitempty"`
DisplayText string `json:"displayText"`
InputContext []InputContext `json:"inputContext"`
ToolCategory ToolCategory `json:"toolCategory,omitempty"`
ToolName string `json:"toolName,omitempty"`
ParentID string `json:"parentID,omitempty"`
}

type InputContext struct {
Expand Down
6 changes: 3 additions & 3 deletions gptscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const relativeToBinaryPath = "<me>"

type GPTScript interface {
Run(context.Context, string, Options) (*Run, error)
Evaluate(context.Context, Options, ...fmt.Stringer) (*Run, error)
Evaluate(context.Context, Options, ...ToolDef) (*Run, error)
Parse(context.Context, string) ([]Node, error)
ParseTool(context.Context, string) ([]Node, error)
Version(context.Context) (string, error)
Expand Down Expand Up @@ -124,13 +124,13 @@ func (g *gptscript) Close() {
}
}

func (g *gptscript) Evaluate(ctx context.Context, opts Options, tools ...fmt.Stringer) (*Run, error) {
func (g *gptscript) Evaluate(ctx context.Context, opts Options, tools ...ToolDef) (*Run, error) {
return (&Run{
url: g.url,
requestPath: "evaluate",
state: Creating,
opts: opts,
content: concatTools(tools),
tools: tools,
}).NextChat(ctx, opts.Input)
}

Expand Down
62 changes: 29 additions & 33 deletions gptscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestListModels(t *testing.T) {
}

func TestAbortRun(t *testing.T) {
tool := &ToolDef{Instructions: "What is the capital of the united states?"}
tool := ToolDef{Instructions: "What is the capital of the united states?"}

run, err := g.Evaluate(context.Background(), Options{DisableCache: true, IncludeEvents: true}, tool)
if err != nil {
Expand All @@ -105,7 +105,7 @@ func TestAbortRun(t *testing.T) {
}

func TestSimpleEvaluate(t *testing.T) {
tool := &ToolDef{Instructions: "What is the capital of the united states?"}
tool := ToolDef{Instructions: "What is the capital of the united states?"}

run, err := g.Evaluate(context.Background(), Options{}, tool)
if err != nil {
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestEvaluateWithContext(t *testing.T) {
t.Fatalf("Error getting current working directory: %v", err)
}

tool := &ToolDef{
tool := ToolDef{
Instructions: "What is the capital of the united states?",
Context: []string{
wd + "/test/acorn-labs-context.gpt",
Expand All @@ -165,7 +165,7 @@ func TestEvaluateWithContext(t *testing.T) {
}

func TestEvaluateComplexTool(t *testing.T) {
tool := &ToolDef{
tool := ToolDef{
JSONResponse: true,
Instructions: `
Create three short graphic artist descriptions and their muses.
Expand Down Expand Up @@ -202,18 +202,16 @@ func TestEvaluateWithToolList(t *testing.T) {
if runtime.GOOS == "windows" {
shebang = "#!/usr/bin/env powershell.exe"
}
tools := []fmt.Stringer{
&ToolDef{
tools := []ToolDef{
{
Tools: []string{"echo"},
Instructions: "echo hello there",
},
&ToolDef{
Name: "echo",
Tools: []string{"sys.exec"},
Description: "Echoes the input",
Args: map[string]string{
"input": "The string input to echo",
},
{
Name: "echo",
Tools: []string{"sys.exec"},
Description: "Echoes the input",
Arguments: ObjectSchema("input", "The string input to echo"),
Instructions: shebang + "\n echo ${input}",
},
}
Expand All @@ -238,23 +236,21 @@ func TestEvaluateWithToolListAndSubTool(t *testing.T) {
if runtime.GOOS == "windows" {
shebang = "#!/usr/bin/env powershell.exe"
}
tools := []fmt.Stringer{
&ToolDef{
tools := []ToolDef{
{
Tools: []string{"echo"},
Instructions: "echo 'hello there'",
},
&ToolDef{
{
Name: "other",
Tools: []string{"echo"},
Instructions: "echo 'hello somewhere else'",
},
&ToolDef{
Name: "echo",
Tools: []string{"sys.exec"},
Description: "Echoes the input",
Args: map[string]string{
"input": "The string input to echo",
},
{
Name: "echo",
Tools: []string{"sys.exec"},
Description: "Echoes the input",
Arguments: ObjectSchema("input", "The string input to echo"),
Instructions: shebang + "\n echo ${input}",
},
}
Expand All @@ -276,7 +272,7 @@ func TestEvaluateWithToolListAndSubTool(t *testing.T) {

func TestStreamEvaluate(t *testing.T) {
var eventContent string
tool := &ToolDef{Instructions: "What is the capital of the united states?"}
tool := ToolDef{Instructions: "What is the capital of the united states?"}

run, err := g.Evaluate(context.Background(), Options{IncludeEvents: true}, tool)
if err != nil {
Expand Down Expand Up @@ -536,7 +532,7 @@ echo hello there
}

func TestToolChat(t *testing.T) {
tool := &ToolDef{
tool := ToolDef{
Chat: true,
Instructions: "You are a chat bot. Don't finish the conversation until I say 'bye'.",
Tools: []string{"sys.chat.finish"},
Expand Down Expand Up @@ -688,8 +684,8 @@ func TestToolWithGlobalTools(t *testing.T) {

func TestConfirm(t *testing.T) {
var eventContent string
tools := []fmt.Stringer{
&ToolDef{
tools := []ToolDef{
{
Instructions: "List the files in the current directory",
Tools: []string{"sys.exec"},
},
Expand Down Expand Up @@ -759,8 +755,8 @@ func TestConfirm(t *testing.T) {

func TestConfirmDeny(t *testing.T) {
var eventContent string
tools := []fmt.Stringer{
&ToolDef{
tools := []ToolDef{
{
Instructions: "List the files in the current directory",
Tools: []string{"sys.exec"},
},
Expand Down Expand Up @@ -831,8 +827,8 @@ func TestConfirmDeny(t *testing.T) {

func TestPrompt(t *testing.T) {
var eventContent string
tools := []fmt.Stringer{
&ToolDef{
tools := []ToolDef{
{
Instructions: "Use the sys.prompt user to ask the user for 'first name' which is not sensitive. After you get their first name, say hello.",
Tools: []string{"sys.prompt"},
},
Expand Down Expand Up @@ -914,8 +910,8 @@ func TestPrompt(t *testing.T) {
}

func TestPromptWithoutPromptAllowed(t *testing.T) {
tools := []fmt.Stringer{
&ToolDef{
tools := []ToolDef{
{
Instructions: "Use the sys.prompt user to ask the user for 'first name' which is not sensitive. After you get their first name, say hello.",
Tools: []string{"sys.prompt"},
},
Expand Down
35 changes: 18 additions & 17 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ import (
var errAbortRun = errors.New("run aborted")

type Run struct {
url, requestPath, toolPath, content string
opts Options
state RunState
chatState string
cancel context.CancelCauseFunc
err error
wait func()
basicCommand bool
url, requestPath, toolPath string
tools []ToolDef
opts Options
state RunState
chatState string
cancel context.CancelCauseFunc
err error
wait func()
basicCommand bool

program *Program
callsLock sync.RWMutex
Expand Down Expand Up @@ -163,7 +164,7 @@ func (r *Run) NextChat(ctx context.Context, input string) (*Run, error) {
requestPath: r.requestPath,
state: Creating,
toolPath: r.toolPath,
content: r.content,
tools: r.tools,
opts: r.opts,
}

Expand All @@ -175,11 +176,11 @@ func (r *Run) NextChat(ctx context.Context, input string) (*Run, error) {
}

var payload any
if r.content != "" {
if len(r.tools) != 0 {
payload = requestPayload{
Content: run.content,
Input: input,
Options: run.opts,
ToolDefs: r.tools,
Input: input,
Options: run.opts,
}
} else if run.toolPath != "" {
payload = requestPayload{
Expand Down Expand Up @@ -412,8 +413,8 @@ const (
)

type requestPayload struct {
Content string `json:"content"`
File string `json:"file"`
Input string `json:"input"`
Options `json:",inline"`
Options `json:",inline"`
File string `json:"file"`
Input string `json:"input"`
ToolDefs []ToolDef `json:"toolDefs,inline"`
}
4 changes: 2 additions & 2 deletions run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ func TestRestartingErrorRun(t *testing.T) {
if runtime.GOOS == "windows" {
instructions = "#!/usr/bin/env powershell.exe\n\n$e = $env:EXIT_CODE;\nif ($e) { Exit 1; }"
}
tool := &ToolDef{
tool := ToolDef{
Context: []string{"my-context"},
Instructions: "Say hello",
}
contextTool := &ToolDef{
contextTool := ToolDef{
Name: "my-context",
Instructions: instructions,
}
Expand Down
Loading