tools

package
v0.0.0-...-a504b28 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: MIT Imports: 4 Imported by: 0

README

tools

This is an implementation of a Tools interface for LLM's to interact with. Tools are entirely arbitrary and can do whatever you want, and just have a very simple API:

type Tool interface {
	Name() string
	Description() string
	Run(ctx context.Context, input interface{}) (interface{}, error)
}

A simple implementation would then be something like

type CalculatorInput struct {
	Expression  string                 `json:"expression" jsonschema:"required" jsonschema_description:"mathematical expression to evaluate"`
	Environment map[string]interface{} `json:"environment,omitempty" jsonschema_description:"optional environment variables to use when evaluating the expression"`
}

type CalculatorTool struct{}

// Run evaluates a mathematical expression and returns it as a string.
func (c *CalculatorTool) Run(ctx context.Context, input interface{}) (interface{}, error) {
    // do stuff
}

Note that the input struct has a lot of JSON Schema mappings -- this is so that we can feed the description directly to OpenAI!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CalculatorInput

type CalculatorInput struct {
	Expression  string                 `json:"expression" jsonschema:"required" jsonschema_description:"mathematical expression to evaluate"`
	Environment map[string]interface{} `json:"environment,omitempty" jsonschema_description:"optional environment variables to use when evaluating the expression"`
}

type CalculatorTool

type CalculatorTool struct{}

func (*CalculatorTool) Description

func (c *CalculatorTool) Description() string

func (*CalculatorTool) Name

func (c *CalculatorTool) Name() string

func (*CalculatorTool) Run

func (c *CalculatorTool) Run(ctx context.Context, input interface{}) (interface{}, error)

Run evaluates a mathematical expression and returns it as a string.

type Tool

type Tool interface {
	Name() string
	Description() string
	Run(ctx context.Context, input interface{}) (interface{}, error)
}

Tool is an incredibly generic interface for a tool that an LLM can use.

Jump to

Keyboard shortcuts

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