Documentation
¶
Overview ¶
Package tools provides a FunctionRegistry that can register and execute ordinary functions *and* methods on structs.
Index ¶
- func ExecTool(funcName string, args map[string]any) (any, error)
- type FS
- func (fs *FS) ToolGetCurrentWorkingDirectory() (string, error)
- func (fs *FS) ToolGrepText(text string, includeHiddenFiles bool, caseSensitive bool, dir string) (string, error)
- func (fs *FS) ToolReadFile(filePath string) (string, error)
- func (fs *FS) ToolTree(dir string, maxDepth int) (string, error)
- type Function
- type FunctionDefinition
- type FunctionInfo
- type FunctionRegistry
- type ParamInfo
- type Property
- type Tool
- type ToolCall
- type ToolFunctionParameters
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FS ¶ added in v0.1.6
type FS struct {
WD string
}
func (*FS) ToolGetCurrentWorkingDirectory ¶ added in v0.1.6
ToolGetCurrentWorkingDirectory returns the current working directory(or so called project directory). It's typically use for when it's asked to do operations regarding local filesystem, file operations, statistics, etc.
func (*FS) ToolGrepText ¶ added in v0.1.6
func (fs *FS) ToolGrepText(text string, includeHiddenFiles bool, caseSensitive bool, dir string) (string, error)
ToolGrepText returns ripgrep output for given text in the given dir
text: pattern to search includeHiddenFiles: bool flag to determine if hidden files are included or not. rg option `-.` is used when enabled caseSensitive: bool flag to determine if search is performed dace sensitive or not. rg option `-sis used when enabled dir: relative directory path to CWD, to perform ripgrep in `CWD/dir`.
func (*FS) ToolReadFile ¶ added in v0.1.6
ToolReadFile returns the entire contents of the file at the given path. The path is treated as relative to the current working directory.
filePath: relative path to the CWD
type Function ¶
type Function struct {
Name string `json:"name"`
Arguments json.RawMessage `json:"arguments,omitempty"`
}
type FunctionDefinition ¶
type FunctionDefinition struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters ToolFunctionParameters `json:"parameters"`
}
type FunctionInfo ¶
type FunctionInfo struct {
// contains filtered or unexported fields
}
FunctionInfo stores everything needed to execute a registered function/method.
type FunctionRegistry ¶
type FunctionRegistry struct {
// contains filtered or unexported fields
}
FunctionRegistry keeps a map of registered functions/methods.
func NewFunctionRegistry ¶
func NewFunctionRegistry() *FunctionRegistry
NewFunctionRegistry returns an empty registry.
func (*FunctionRegistry) ExecFunc ¶
ExecFunc executes a registered function/method with named parameters. Methods receive their receiver automatically.
func (*FunctionRegistry) RegisterFunction ¶
func (fr *FunctionRegistry) RegisterFunction(name string, fn any) error
RegisterFunction registers a standalone function.
func (*FunctionRegistry) RegisterMethods ¶ added in v0.1.6
func (fr *FunctionRegistry) RegisterMethods(instance any) ([]string, error)
RegisterMethods registers every exported method on 'instance'. Works for both value and pointer receivers.
type Tool ¶
type Tool struct {
Type string `json:"type"` // always = "function"
Function FunctionDefinition `json:"function"`
}