Help us shape the future of Go! Take the 2026 Go Developer Survey

tool

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Describe

func Describe(ctx context.Context, h Handler) (string, error)

Describe gets a tool description, or an empty string if the tool doesn't provide additional description.

func DescribeCall added in v0.0.4

func DescribeCall(functionName, functionArgs, functionDescr string) string

Types

type DescriptionSource

type DescriptionSource interface {
	// Describe gets a string that describes, what the tool is about
	// to do when executed with given arguments.
	Describe(ctx context.Context) (string, error)
}

type Function

type Function struct {
	// The name of the function to be called. Must be a-z, A-Z, 0-9, or
	// contain underscores and dashes, with a maximum length of 64.
	Name string `json:"name" validate:"required"`
	// A description of what the function does, used by the model to
	// choose when and how to call the function.
	Description string `json:"description,omitempty"`
	// The parameters the functions accepts, described as a JSON Schema object.
	Parameters map[string]any `json:"parameters" validate:"required"`
}

func MustUnmarshalFn

func MustUnmarshalFn(data []byte) Function

MustUnmarshalFn unmarshals a JSON-encoded tool function and panics on error.

func UnmarshalFn

func UnmarshalFn(data []byte) (Function, error)

UnmarshalFn unmarshals a JSON-encoded tool function and returns a ToolFunction struct.

type Handler

type Handler interface {
	Execute(ctx context.Context) (any, error)
}

Handler defines an interface for executing tools.

type Tool

type Tool struct {
	// The type of the tool. Currently, only `function` is supported.
	Type string `json:"type" validate:"required,oneof=function"`
	// Description of the function.
	Function *Function `json:"function,omitempty"`
}

func MustUnmarshalTool

func MustUnmarshalTool(data []byte) Tool

MustUnmarshalTool unmarshals a JSON-encoded tool and panics on error.

func UnmarshalTool

func UnmarshalTool(data []byte) (Tool, error)

UnmarshalTool unmarshals a JSON-encoded tool and returns a Tool struct.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL