tool

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig config
View Source
var NilTool = &Tool{
	Name:        "nil",
	Description: "nil tool",
	Kind:        "code",
	invoke: func(ctx context.Context, args string) (string, error) {
		return "", fmt.Errorf("not implement")
	},
}

Functions

func DefaultSchemaCustomizer added in v0.1.3

func DefaultSchemaCustomizer(name string, t reflect.Type, tag reflect.StructTag, schema *openapi3.Schema) error

DefaultSchemaCustomizer is the default schema customizer when using reflect to infer tool parameter from tagged go struct. Supported struct tags: 1. jsonschema: "description=xxx" 2. jsonschema: "enum=xxx,enum=yyy,enum=zzz" 3. jsonschema: "required" 4. can also use json: "xxx,omitempty" to mark the field as not required, which means an absence of 'omitempty' in json tag means the field is required. If this DefaultSchemaCustomizer is not sufficient or suitable to your specific need, define your own SchemaCustomizerFn and pass it to WithSchemaCustomizer during InferTool or InferStreamTool.

func Register

func Register(t *Tool)

Register 注册工具

func WithConfig

func WithConfig(c map[string]any) error

func WithRepo

func WithRepo(repo Repo)

WithRepo ...

Types

type Event

type Event struct {
	Name string
	Type string
	Data any
}

Event 事件

type Factory

type Factory struct {
	// contains filtered or unexported fields
}

Factory 工具工厂

func NewFactory

func NewFactory(repo Repo) *Factory

NewFactory ...

func (*Factory) Spawn

func (f *Factory) Spawn(name string) *Tool

Spawn ...

type InvokeFunc added in v0.1.3

type InvokeFunc func(context.Context, string) (string, error)

type Option added in v0.0.9

type Option func(*Tool)

func WithDescription added in v0.0.9

func WithDescription(description string) Option

func WithFunction added in v0.0.9

func WithFunction(function func(ctx context.Context, args string) (string, error)) Option

func WithKind added in v0.0.9

func WithKind(kind string) Option

func WithName added in v0.0.9

func WithName(name string) Option

func WithParameters added in v0.0.9

func WithParameters(parameters ...any) Option

type Parameter

type Parameter struct {
	Name             string
	Label            string
	HumanDescription string
	Placeholder      string
	Type             ParameterType
	LLMDescrition    string
	Required         bool
	Default          any
	Min              float64
	Max              float64
	Options          []string
}

Parameter 用于描述API参数的结构体

type ParameterType

type ParameterType string

ParameterType 枚举类型

const (
	Array       ParameterType = "array"
	String      ParameterType = "string"
	Number      ParameterType = "number"
	Boolean     ParameterType = "boolean"
	Select      ParameterType = "select"
	SecretInput ParameterType = "secret-input"
	File        ParameterType = "file"
)

type ParamsOneOf added in v0.1.3

type ParamsOneOf struct {
	// contains filtered or unexported fields
}

func (*ParamsOneOf) Parameters added in v0.1.3

func (p *ParamsOneOf) Parameters() any

type Repo

type Repo interface {
}

Repo 工具仓库

type Tool

type Tool struct {
	ID           int64  // 引用的工具ID
	Kind         string // 引用的工具类型
	Name         string
	Description  string
	*ParamsOneOf `json:"parameters,omitempty"` // 参数,可选

	AuthenticationType  string
	AuthenticationValue string
	ServerURL           string `json:"server_url"` // 服务器URL
	Method              string `json:"method"`     // 方法
	Body                string `json:"body"`       // body
	// contains filtered or unexported fields
}

func New added in v0.0.9

func New(opts ...Option) *Tool

func NewWithToolFunc added in v0.1.3

func NewWithToolFunc[T, D any](name string, description string, function ToolFunc[T, D]) (*Tool, error)

func Spawn

func Spawn(name string) *Tool

Spawn ...

func (*Tool) Invoke

func (t *Tool) Invoke(ctx context.Context, params string) (string, error)

func (*Tool) WithInvokeFunc added in v0.1.3

func (t *Tool) WithInvokeFunc(invoke InvokeFunc) *Tool

func (*Tool) WithParameters added in v0.1.3

func (t *Tool) WithParameters(parameters ...Parameter) *Tool

type ToolFunc added in v0.1.3

type ToolFunc[T, D any] func(ctx context.Context, input T) (output D, err error)

Directories

Path Synopsis
dom

Jump to

Keyboard shortcuts

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