Skip to content

Commit 4341fa1

Browse files
authored
Merge pull request #26 from thedadams/remove-to-string
chore: remove ToString method for tools
2 parents 7a845df + 41f191d commit 4341fa1

File tree

6 files changed

+94
-159
lines changed

6 files changed

+94
-159
lines changed

frame.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,14 @@ type Call struct {
8484
}
8585

8686
type CallContext struct {
87-
ID string `json:"id"`
88-
Tool Tool `json:"tool"`
89-
DisplayText string `json:"displayText"`
90-
InputContext []InputContext `json:"inputContext"`
91-
ToolCategory ToolCategory `json:"toolCategory,omitempty"`
92-
ToolName string `json:"toolName,omitempty"`
93-
ParentID string `json:"parentID,omitempty"`
87+
ID string `json:"id"`
88+
Tool Tool `json:"tool"`
89+
AgentGroup []ToolReference `json:"agentGroup,omitempty"`
90+
DisplayText string `json:"displayText"`
91+
InputContext []InputContext `json:"inputContext"`
92+
ToolCategory ToolCategory `json:"toolCategory,omitempty"`
93+
ToolName string `json:"toolName,omitempty"`
94+
ParentID string `json:"parentID,omitempty"`
9495
}
9596

9697
type InputContext struct {

gptscript.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const relativeToBinaryPath = "<me>"
2828

2929
type GPTScript interface {
3030
Run(context.Context, string, Options) (*Run, error)
31-
Evaluate(context.Context, Options, ...fmt.Stringer) (*Run, error)
31+
Evaluate(context.Context, Options, ...ToolDef) (*Run, error)
3232
Parse(context.Context, string) ([]Node, error)
3333
ParseTool(context.Context, string) ([]Node, error)
3434
Version(context.Context) (string, error)
@@ -124,13 +124,13 @@ func (g *gptscript) Close() {
124124
}
125125
}
126126

127-
func (g *gptscript) Evaluate(ctx context.Context, opts Options, tools ...fmt.Stringer) (*Run, error) {
127+
func (g *gptscript) Evaluate(ctx context.Context, opts Options, tools ...ToolDef) (*Run, error) {
128128
return (&Run{
129129
url: g.url,
130130
requestPath: "evaluate",
131131
state: Creating,
132132
opts: opts,
133-
content: concatTools(tools),
133+
tools: tools,
134134
}).NextChat(ctx, opts.Input)
135135
}
136136

gptscript_test.go

+29-33
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestListModels(t *testing.T) {
8181
}
8282

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

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

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

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

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

167167
func TestEvaluateComplexTool(t *testing.T) {
168-
tool := &ToolDef{
168+
tool := ToolDef{
169169
JSONResponse: true,
170170
Instructions: `
171171
Create three short graphic artist descriptions and their muses.
@@ -202,18 +202,16 @@ func TestEvaluateWithToolList(t *testing.T) {
202202
if runtime.GOOS == "windows" {
203203
shebang = "#!/usr/bin/env powershell.exe"
204204
}
205-
tools := []fmt.Stringer{
206-
&ToolDef{
205+
tools := []ToolDef{
206+
{
207207
Tools: []string{"echo"},
208208
Instructions: "echo hello there",
209209
},
210-
&ToolDef{
211-
Name: "echo",
212-
Tools: []string{"sys.exec"},
213-
Description: "Echoes the input",
214-
Args: map[string]string{
215-
"input": "The string input to echo",
216-
},
210+
{
211+
Name: "echo",
212+
Tools: []string{"sys.exec"},
213+
Description: "Echoes the input",
214+
Arguments: ObjectSchema("input", "The string input to echo"),
217215
Instructions: shebang + "\n echo ${input}",
218216
},
219217
}
@@ -238,23 +236,21 @@ func TestEvaluateWithToolListAndSubTool(t *testing.T) {
238236
if runtime.GOOS == "windows" {
239237
shebang = "#!/usr/bin/env powershell.exe"
240238
}
241-
tools := []fmt.Stringer{
242-
&ToolDef{
239+
tools := []ToolDef{
240+
{
243241
Tools: []string{"echo"},
244242
Instructions: "echo 'hello there'",
245243
},
246-
&ToolDef{
244+
{
247245
Name: "other",
248246
Tools: []string{"echo"},
249247
Instructions: "echo 'hello somewhere else'",
250248
},
251-
&ToolDef{
252-
Name: "echo",
253-
Tools: []string{"sys.exec"},
254-
Description: "Echoes the input",
255-
Args: map[string]string{
256-
"input": "The string input to echo",
257-
},
249+
{
250+
Name: "echo",
251+
Tools: []string{"sys.exec"},
252+
Description: "Echoes the input",
253+
Arguments: ObjectSchema("input", "The string input to echo"),
258254
Instructions: shebang + "\n echo ${input}",
259255
},
260256
}
@@ -276,7 +272,7 @@ func TestEvaluateWithToolListAndSubTool(t *testing.T) {
276272

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

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

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

689685
func TestConfirm(t *testing.T) {
690686
var eventContent string
691-
tools := []fmt.Stringer{
692-
&ToolDef{
687+
tools := []ToolDef{
688+
{
693689
Instructions: "List the files in the current directory",
694690
Tools: []string{"sys.exec"},
695691
},
@@ -759,8 +755,8 @@ func TestConfirm(t *testing.T) {
759755

760756
func TestConfirmDeny(t *testing.T) {
761757
var eventContent string
762-
tools := []fmt.Stringer{
763-
&ToolDef{
758+
tools := []ToolDef{
759+
{
764760
Instructions: "List the files in the current directory",
765761
Tools: []string{"sys.exec"},
766762
},
@@ -831,8 +827,8 @@ func TestConfirmDeny(t *testing.T) {
831827

832828
func TestPrompt(t *testing.T) {
833829
var eventContent string
834-
tools := []fmt.Stringer{
835-
&ToolDef{
830+
tools := []ToolDef{
831+
{
836832
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.",
837833
Tools: []string{"sys.prompt"},
838834
},
@@ -914,8 +910,8 @@ func TestPrompt(t *testing.T) {
914910
}
915911

916912
func TestPromptWithoutPromptAllowed(t *testing.T) {
917-
tools := []fmt.Stringer{
918-
&ToolDef{
913+
tools := []ToolDef{
914+
{
919915
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.",
920916
Tools: []string{"sys.prompt"},
921917
},

run.go

+18-17
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ import (
1818
var errAbortRun = errors.New("run aborted")
1919

2020
type Run struct {
21-
url, requestPath, toolPath, content string
22-
opts Options
23-
state RunState
24-
chatState string
25-
cancel context.CancelCauseFunc
26-
err error
27-
wait func()
28-
basicCommand bool
21+
url, requestPath, toolPath string
22+
tools []ToolDef
23+
opts Options
24+
state RunState
25+
chatState string
26+
cancel context.CancelCauseFunc
27+
err error
28+
wait func()
29+
basicCommand bool
2930

3031
program *Program
3132
callsLock sync.RWMutex
@@ -163,7 +164,7 @@ func (r *Run) NextChat(ctx context.Context, input string) (*Run, error) {
163164
requestPath: r.requestPath,
164165
state: Creating,
165166
toolPath: r.toolPath,
166-
content: r.content,
167+
tools: r.tools,
167168
opts: r.opts,
168169
}
169170

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

177178
var payload any
178-
if r.content != "" {
179+
if len(r.tools) != 0 {
179180
payload = requestPayload{
180-
Content: run.content,
181-
Input: input,
182-
Options: run.opts,
181+
ToolDefs: r.tools,
182+
Input: input,
183+
Options: run.opts,
183184
}
184185
} else if run.toolPath != "" {
185186
payload = requestPayload{
@@ -412,8 +413,8 @@ const (
412413
)
413414

414415
type requestPayload struct {
415-
Content string `json:"content"`
416-
File string `json:"file"`
417-
Input string `json:"input"`
418-
Options `json:",inline"`
416+
Options `json:",inline"`
417+
File string `json:"file"`
418+
Input string `json:"input"`
419+
ToolDefs []ToolDef `json:"toolDefs,inline"`
419420
}

run_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ func TestRestartingErrorRun(t *testing.T) {
1111
if runtime.GOOS == "windows" {
1212
instructions = "#!/usr/bin/env powershell.exe\n\n$e = $env:EXIT_CODE;\nif ($e) { Exit 1; }"
1313
}
14-
tool := &ToolDef{
14+
tool := ToolDef{
1515
Context: []string{"my-context"},
1616
Instructions: "Say hello",
1717
}
18-
contextTool := &ToolDef{
18+
contextTool := ToolDef{
1919
Name: "my-context",
2020
Instructions: instructions,
2121
}

0 commit comments

Comments
 (0)