tool

package
v0.0.0-...-20e2264 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CodeTools map[string]*CodeTool = make(map[string]*CodeTool)

CodeTools 工具注册表

Functions

func Register

func Register(name string, tool *CodeTool)

Register 注册工具

func WithRepo

func WithRepo(repo Repo)

WithRepo ...

Types

type APITool

type APITool struct {
	// Bundle APIToolBundle
	APIToolBundle
}

APITool 结构体,用于表示基于API的工具

func (*APITool) Description

func (t *APITool) Description() string

Description 返回工具名称

func (*APITool) Invoke

func (t *APITool) Invoke(ctx context.Context, params map[string]any) (string, error)

Invoke 调用工具

func (*APITool) Kind

func (t *APITool) Kind() string

Kind 返回工具类型

func (*APITool) Name

func (t *APITool) Name() string

Name 返回工具名称

func (*APITool) Parameters

func (t *APITool) Parameters() map[string]any

Parameters 返回工具名称

func (*APITool) Stream

func (t *APITool) Stream(ctx context.Context, params map[string]any) (<-chan any, error)

Stream 调用工具

func (*APITool) ToolName

func (t *APITool) ToolName() string

ToolName 返回工具名称

type APIToolBundle

type APIToolBundle struct {
	Meta
	Type                int
	AuthenticationType  string
	AuthenticationValue string
	PostCode            string      `json:"post_code"`              // 代码
	ServerURL           string      `json:"server_url"`             // 服务器URL
	Method              string      `json:"method"`                 // 方法
	Summary             string      `json:"summary,omitempty"`      // 摘要,可选
	Body                string      `json:"body"`                   // body
	OperationID         string      `json:"operation_id,omitempty"` // 操作ID,可选
	Parameters          []Parameter `json:"parameters,omitempty"`   // 参数,可选
	Author              string      `json:"author"`                 // 作者
	Icon                string      `json:"icon,omitempty"`         // 图标,可选

}

APIToolBundle 结构体,用于存储基于API的工具的schema信息

type CodeTool

type CodeTool struct {
	Meta
	Invokex func(context.Context, map[string]any) (string, error)
	Streamx func(context.Context, map[string]any) (chan any, error)
}

CodeTool 结构体,用于表示基于API的工具

func GetCodeTool

func GetCodeTool(name string) *CodeTool

GetCodeTool 获取工具元信息

func (*CodeTool) Description

func (t *CodeTool) Description() string

Description 返回工具名称

func (*CodeTool) Invoke

func (t *CodeTool) Invoke(ctx context.Context, args map[string]any) (string, error)

Invoke 调用工具

func (*CodeTool) Kind

func (t *CodeTool) Kind() string

Kind 返回工具类型

func (*CodeTool) Name

func (t *CodeTool) Name() string

Name 返回工具名称

func (*CodeTool) Parameters

func (t *CodeTool) Parameters() map[string]any

Parameters 返回工具参数

func (*CodeTool) Stream

func (t *CodeTool) Stream(ctx context.Context, args map[string]any) (<-chan any, error)

Stream 调用工具

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) Instantiate

func (f *Factory) Instantiate(providerID int64, providerKind string, name string) Tool

Instantiate ...

type Meta

type Meta struct {
	ID          int64  // 引用的工具ID
	Kind        string // 引用的工具类型
	Operation   string // 操作名称(唯一)
	Name        string
	Description string
	Parameters  []Parameter
}

Meta ...

type NilTool

type NilTool struct {
	Target string
	ID     int64
}

NilTool 无工具

func (*NilTool) Description

func (t *NilTool) Description() string

Description 工具名称

func (*NilTool) Invoke

func (t *NilTool) Invoke(ctx context.Context, params map[string]any) (string, error)

Invoke 调用工具

func (*NilTool) Kind

func (t *NilTool) Kind() string

Kind 工具类型

func (*NilTool) Name

func (t *NilTool) Name() string

Name 工具名称

func (*NilTool) Parameters

func (t *NilTool) Parameters() map[string]any

Parameters 工具名称

func (*NilTool) Stream

func (t *NilTool) Stream(ctx context.Context, params map[string]any) (<-chan any, error)

Stream 流式调用工具

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 Repo

type Repo interface {
	FetchAPITool(context.Context, int64, string) (*APIToolBundle, error)
}

Repo 工具仓库

type Tool

type Tool interface {
	Name() string
	Description() string
	Parameters() map[string]any
	Kind() string
	Invoke(context.Context, map[string]any) (string, error)
	Stream(context.Context, map[string]any) (<-chan any, error)
}

Tool 工具接口

func Instantiate

func Instantiate(providerID int64, providerKind string, name string) Tool

Instantiate ...

func NewAPITool

func NewAPITool(m APIToolBundle) Tool

NewAPITool ...

func NewCodeTool

func NewCodeTool(name string) Tool

NewCodeTool TODO

Directories

Path Synopsis
ai

Jump to

Keyboard shortcuts

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