Skip to content

Commit

Permalink
Merge pull request #749 from ibuildthecloud/move-metadata
Browse files Browse the repository at this point in the history
chore: move metadata field to tooldef struct
  • Loading branch information
ibuildthecloud authored Aug 8, 2024
2 parents 4c16a4c + 26476d2 commit 9e770b9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
21 changes: 18 additions & 3 deletions pkg/types/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,16 @@ func (p Parameters) ToolRefNames() []string {

type ToolDef struct {
Parameters `json:",inline"`
Instructions string `json:"instructions,omitempty"`
BuiltinFunc BuiltinFunc `json:"-"`
Instructions string `json:"instructions,omitempty"`
BuiltinFunc BuiltinFunc `json:"-"`
MetaData map[string]string `json:"metaData,omitempty"`
}

type Tool struct {
ToolDef `json:",inline"`

ID string `json:"id,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 Expand Up @@ -489,6 +489,21 @@ func (t ToolDef) String() string {
_, _ = fmt.Fprintln(buf, t.Instructions)
}

if t.Name != "" {
keys := maps.Keys(t.MetaData)
sort.Strings(keys)
for _, key := range keys {
buf.WriteString("---\n")
buf.WriteString("!metadata:")
buf.WriteString(t.Name)
buf.WriteString(":")
buf.WriteString(key)
buf.WriteString("\n")
buf.WriteString(t.MetaData[key])
buf.WriteString("\n")
}
}

return buf.String()
}

Expand Down
16 changes: 16 additions & 0 deletions pkg/types/tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ func TestToolDef_String(t *testing.T) {
ExportCredentials: []string{"ExportCredential1", "ExportCredential2"},
Type: ToolTypeContext,
},
MetaData: map[string]string{
"package.json": `{
// blah blah some ugly JSON
}
`,
"requirements.txt": `requests=5`,
},
Instructions: "This is a sample instruction",
}

Expand Down Expand Up @@ -68,6 +75,15 @@ Share Credential: ExportCredential2
Chat: true
This is a sample instruction
---
!metadata:Tool Sample:package.json
{
// blah blah some ugly JSON
}
---
!metadata:Tool Sample:requirements.txt
requests=5
`).Equal(t, tool.String())
}

Expand Down

0 comments on commit 9e770b9

Please sign in to comment.