Skip to content

Commit 655b4ee

Browse files
authored
Merge pull request #53 from thedadams/metadata-to-tool
feat: add metadata and type fields to tools
2 parents 22c1258 + 401b947 commit 655b4ee

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

gptscript_test.go

+57
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,42 @@ func TestParseSimpleFile(t *testing.T) {
404404
}
405405
}
406406

407+
func TestParseFileWithMetadata(t *testing.T) {
408+
wd, err := os.Getwd()
409+
if err != nil {
410+
t.Fatalf("Error getting working directory: %v", err)
411+
}
412+
413+
tools, err := g.Parse(context.Background(), wd+"/test/parse-with-metadata.gpt")
414+
if err != nil {
415+
t.Errorf("Error parsing file: %v", err)
416+
}
417+
418+
if len(tools) != 2 {
419+
t.Fatalf("Unexpected number of tools: %d", len(tools))
420+
}
421+
422+
if tools[0].ToolNode == nil {
423+
t.Fatalf("No tool node found")
424+
}
425+
426+
if !strings.Contains(tools[0].ToolNode.Tool.Instructions, "requests.get(") {
427+
t.Errorf("Unexpected instructions: %s", tools[0].ToolNode.Tool.Instructions)
428+
}
429+
430+
if tools[0].ToolNode.Tool.MetaData["requirements.txt"] != "requests" {
431+
t.Errorf("Unexpected metadata: %s", tools[0].ToolNode.Tool.MetaData["requirements.txt"])
432+
}
433+
434+
if tools[1].TextNode == nil {
435+
t.Fatalf("No text node found")
436+
}
437+
438+
if tools[1].TextNode.Fmt != "metadata:foo:requirements.txt" {
439+
t.Errorf("Unexpected text: %s", tools[1].TextNode.Fmt)
440+
}
441+
}
442+
407443
func TestParseTool(t *testing.T) {
408444
tools, err := g.ParseTool(context.Background(), "echo hello")
409445
if err != nil {
@@ -1069,3 +1105,24 @@ func TestGetEnv(t *testing.T) {
10691105
})
10701106
}
10711107
}
1108+
1109+
func TestRunPythonWithMetadata(t *testing.T) {
1110+
wd, err := os.Getwd()
1111+
if err != nil {
1112+
t.Fatalf("Error getting working directory: %v", err)
1113+
}
1114+
1115+
run, err := g.Run(context.Background(), wd+"/test/parse-with-metadata.gpt", Options{IncludeEvents: true})
1116+
if err != nil {
1117+
t.Fatalf("Error executing file: %v", err)
1118+
}
1119+
1120+
out, err := run.Text()
1121+
if err != nil {
1122+
t.Fatalf("Error reading output: %v", err)
1123+
}
1124+
1125+
if out != "200" {
1126+
t.Errorf("Unexpected output: %s", out)
1127+
}
1128+
}

test/parse-with-metadata.gpt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Name: foo
2+
3+
#!/usr/bin/env python3
4+
import requests
5+
6+
7+
resp = requests.get("https://google.com")
8+
print(resp.status_code, end="")
9+
10+
---
11+
!metadata:foo:requirements.txt
12+
requests

tool.go

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type ToolDef struct {
2929
Agents []string `json:"agents,omitempty"`
3030
Credentials []string `json:"credentials,omitempty"`
3131
Instructions string `json:"instructions,omitempty"`
32+
Type string `json:"type,omitempty"`
3233
}
3334

3435
func ObjectSchema(kv ...string) *openapi3.Schema {
@@ -86,6 +87,7 @@ type Tool struct {
8687
ID string `json:"id,omitempty"`
8788
Arguments *openapi3.Schema `json:"arguments,omitempty"`
8889
ToolMapping map[string][]ToolReference `json:"toolMapping,omitempty"`
90+
MetaData map[string]string `json:"metadata,omitempty"`
8991
LocalTools map[string]string `json:"localTools,omitempty"`
9092
Source ToolSource `json:"source,omitempty"`
9193
WorkingDir string `json:"workingDir,omitempty"`

0 commit comments

Comments
 (0)