-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool_definitions.go
More file actions
66 lines (57 loc) · 2.21 KB
/
Copy pathtool_definitions.go
File metadata and controls
66 lines (57 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"errors"
"fmt"
sdk "github.com/modelrelay/modelrelay/sdk/go"
"github.com/modelrelay/modelrelay/sdk/go/llm"
)
type fsReadFileArgs struct {
Path string `json:"path" description:"workspace-relative path"`
MaxBytes int64 `json:"max_bytes,omitempty" description:"maximum bytes to return"`
}
type fsListFilesArgs struct {
Path string `json:"path,omitempty" description:"workspace-relative directory"`
MaxEntries int64 `json:"max_entries,omitempty" description:"maximum entries to return"`
}
type fsSearchArgs struct {
Query string `json:"query" description:"search query"`
Path string `json:"path,omitempty" description:"workspace-relative directory"`
MaxMatches int64 `json:"max_matches,omitempty" description:"maximum matches to return"`
}
type fsEditArgs struct {
Path string `json:"path" description:"workspace-relative path"`
OldString string `json:"old_string" description:"exact string to find"`
NewString string `json:"new_string" description:"replacement string"`
ReplaceAll bool `json:"replace_all,omitempty" description:"replace all occurrences"`
}
func fsToolDefinitions() []llm.Tool {
return []llm.Tool{
sdk.MustFunctionToolFromType[fsReadFileArgs](sdk.ToolNameFSReadFile, "Read a file from the local workspace"),
sdk.MustFunctionToolFromType[fsListFilesArgs](sdk.ToolNameFSListFiles, "List files in the local workspace"),
sdk.MustFunctionToolFromType[fsSearchArgs](sdk.ToolNameFSSearch, "Search within the local workspace"),
sdk.MustFunctionToolFromType[fsEditArgs](sdk.ToolNameFSEdit, "Edit a file in the local workspace"),
}
}
func appendToolDefs(defs []llm.Tool, seen map[sdk.ToolName]struct{}, add ...llm.Tool) ([]llm.Tool, error) {
if seen == nil {
return nil, errors.New("tool name registry required")
}
for _, tool := range add {
name := toolNameForDefinition(tool)
if name == "" {
return nil, errors.New("tool definition missing name")
}
if _, exists := seen[name]; exists {
return nil, fmt.Errorf("duplicate tool name %q", name)
}
seen[name] = struct{}{}
defs = append(defs, tool)
}
return defs, nil
}
func toolNameForDefinition(tool llm.Tool) sdk.ToolName {
if tool.Function == nil {
return ""
}
return tool.Function.Name
}