Skip to content

Commit

Permalink
fix: put metadata filed on tool def
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
thedadams committed Aug 8, 2024
1 parent 655b4ee commit 4a254d9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 24 deletions.
30 changes: 28 additions & 2 deletions gptscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,8 @@ func TestFileChat(t *testing.T) {
}
inputs := []string{
"List the 3 largest of the Great Lakes by volume.",
"What is the volume of the second one in cubic miles?",
"What is the total area of the third one in square miles?",
"What is the volume of the second in the list in cubic miles?",
"What is the total area of the third in the list in square miles?",
}

expectedOutputs := []string{
Expand Down Expand Up @@ -1126,3 +1126,29 @@ func TestRunPythonWithMetadata(t *testing.T) {
t.Errorf("Unexpected output: %s", out)
}
}

func TestParseThenEvaluateWithMetadata(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
t.Fatalf("Error getting working directory: %v", err)
}

tools, err := g.Parse(context.Background(), wd+"/test/parse-with-metadata.gpt")
if err != nil {
t.Fatalf("Error parsing file: %v", err)
}

run, err := g.Evaluate(context.Background(), Options{}, tools[0].ToolNode.Tool.ToolDef)
if err != nil {
t.Fatalf("Error executing file: %v", err)
}

out, err := run.Text()
if err != nil {
t.Fatalf("Error reading output: %v", err)
}

if out != "200" {
t.Errorf("Unexpected output: %s", out)
}
}
44 changes: 22 additions & 22 deletions tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@ import (

// ToolDef struct represents a tool with various configurations.
type ToolDef struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
MaxTokens int `json:"maxTokens,omitempty"`
ModelName string `json:"modelName,omitempty"`
ModelProvider bool `json:"modelProvider,omitempty"`
JSONResponse bool `json:"jsonResponse,omitempty"`
Chat bool `json:"chat,omitempty"`
Temperature *float32 `json:"temperature,omitempty"`
Cache *bool `json:"cache,omitempty"`
InternalPrompt *bool `json:"internalPrompt"`
Arguments *openapi3.Schema `json:"arguments,omitempty"`
Tools []string `json:"tools,omitempty"`
GlobalTools []string `json:"globalTools,omitempty"`
GlobalModelName string `json:"globalModelName,omitempty"`
Context []string `json:"context,omitempty"`
ExportContext []string `json:"exportContext,omitempty"`
Export []string `json:"export,omitempty"`
Agents []string `json:"agents,omitempty"`
Credentials []string `json:"credentials,omitempty"`
Instructions string `json:"instructions,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
MaxTokens int `json:"maxTokens,omitempty"`
ModelName string `json:"modelName,omitempty"`
ModelProvider bool `json:"modelProvider,omitempty"`
JSONResponse bool `json:"jsonResponse,omitempty"`
Chat bool `json:"chat,omitempty"`
Temperature *float32 `json:"temperature,omitempty"`
Cache *bool `json:"cache,omitempty"`
InternalPrompt *bool `json:"internalPrompt"`
Arguments *openapi3.Schema `json:"arguments,omitempty"`
Tools []string `json:"tools,omitempty"`
GlobalTools []string `json:"globalTools,omitempty"`
GlobalModelName string `json:"globalModelName,omitempty"`
Context []string `json:"context,omitempty"`
ExportContext []string `json:"exportContext,omitempty"`
Export []string `json:"export,omitempty"`
Agents []string `json:"agents,omitempty"`
Credentials []string `json:"credentials,omitempty"`
Instructions string `json:"instructions,omitempty"`
Type string `json:"type,omitempty"`
MetaData map[string]string `json:"metadata,omitempty"`
}

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

0 comments on commit 4a254d9

Please sign in to comment.