Skip to content

Commit 4a254d9

Browse files
committed
fix: put metadata filed on tool def
This change allows for the following flow: parse tool with metadata from file -> run tool defs from this parse. Signed-off-by: Donnie Adams <[email protected]>
1 parent 655b4ee commit 4a254d9

File tree

2 files changed

+50
-24
lines changed

2 files changed

+50
-24
lines changed

gptscript_test.go

+28-2
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,8 @@ func TestFileChat(t *testing.T) {
667667
}
668668
inputs := []string{
669669
"List the 3 largest of the Great Lakes by volume.",
670-
"What is the volume of the second one in cubic miles?",
671-
"What is the total area of the third one in square miles?",
670+
"What is the volume of the second in the list in cubic miles?",
671+
"What is the total area of the third in the list in square miles?",
672672
}
673673

674674
expectedOutputs := []string{
@@ -1126,3 +1126,29 @@ func TestRunPythonWithMetadata(t *testing.T) {
11261126
t.Errorf("Unexpected output: %s", out)
11271127
}
11281128
}
1129+
1130+
func TestParseThenEvaluateWithMetadata(t *testing.T) {
1131+
wd, err := os.Getwd()
1132+
if err != nil {
1133+
t.Fatalf("Error getting working directory: %v", err)
1134+
}
1135+
1136+
tools, err := g.Parse(context.Background(), wd+"/test/parse-with-metadata.gpt")
1137+
if err != nil {
1138+
t.Fatalf("Error parsing file: %v", err)
1139+
}
1140+
1141+
run, err := g.Evaluate(context.Background(), Options{}, tools[0].ToolNode.Tool.ToolDef)
1142+
if err != nil {
1143+
t.Fatalf("Error executing file: %v", err)
1144+
}
1145+
1146+
out, err := run.Text()
1147+
if err != nil {
1148+
t.Fatalf("Error reading output: %v", err)
1149+
}
1150+
1151+
if out != "200" {
1152+
t.Errorf("Unexpected output: %s", out)
1153+
}
1154+
}

tool.go

+22-22
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,28 @@ import (
99

1010
// ToolDef struct represents a tool with various configurations.
1111
type ToolDef struct {
12-
Name string `json:"name,omitempty"`
13-
Description string `json:"description,omitempty"`
14-
MaxTokens int `json:"maxTokens,omitempty"`
15-
ModelName string `json:"modelName,omitempty"`
16-
ModelProvider bool `json:"modelProvider,omitempty"`
17-
JSONResponse bool `json:"jsonResponse,omitempty"`
18-
Chat bool `json:"chat,omitempty"`
19-
Temperature *float32 `json:"temperature,omitempty"`
20-
Cache *bool `json:"cache,omitempty"`
21-
InternalPrompt *bool `json:"internalPrompt"`
22-
Arguments *openapi3.Schema `json:"arguments,omitempty"`
23-
Tools []string `json:"tools,omitempty"`
24-
GlobalTools []string `json:"globalTools,omitempty"`
25-
GlobalModelName string `json:"globalModelName,omitempty"`
26-
Context []string `json:"context,omitempty"`
27-
ExportContext []string `json:"exportContext,omitempty"`
28-
Export []string `json:"export,omitempty"`
29-
Agents []string `json:"agents,omitempty"`
30-
Credentials []string `json:"credentials,omitempty"`
31-
Instructions string `json:"instructions,omitempty"`
32-
Type string `json:"type,omitempty"`
12+
Name string `json:"name,omitempty"`
13+
Description string `json:"description,omitempty"`
14+
MaxTokens int `json:"maxTokens,omitempty"`
15+
ModelName string `json:"modelName,omitempty"`
16+
ModelProvider bool `json:"modelProvider,omitempty"`
17+
JSONResponse bool `json:"jsonResponse,omitempty"`
18+
Chat bool `json:"chat,omitempty"`
19+
Temperature *float32 `json:"temperature,omitempty"`
20+
Cache *bool `json:"cache,omitempty"`
21+
InternalPrompt *bool `json:"internalPrompt"`
22+
Arguments *openapi3.Schema `json:"arguments,omitempty"`
23+
Tools []string `json:"tools,omitempty"`
24+
GlobalTools []string `json:"globalTools,omitempty"`
25+
GlobalModelName string `json:"globalModelName,omitempty"`
26+
Context []string `json:"context,omitempty"`
27+
ExportContext []string `json:"exportContext,omitempty"`
28+
Export []string `json:"export,omitempty"`
29+
Agents []string `json:"agents,omitempty"`
30+
Credentials []string `json:"credentials,omitempty"`
31+
Instructions string `json:"instructions,omitempty"`
32+
Type string `json:"type,omitempty"`
33+
MetaData map[string]string `json:"metadata,omitempty"`
3334
}
3435

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

0 commit comments

Comments
 (0)