nlcall

package module
v0.0.0-...-de63469 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: MIT Imports: 8 Imported by: 0

README

nlcall

👾 Call golang function by nature language, a demonstration.

agent := llm.NewLlmAgent(client)
for _, f := range []any{
    add, greet, weather, lengthOfLongestSubstring, mul, no,
} {
    if _, err := agent.RegisterFn(ctx, f, nlcall.WithLoadDefDir(dir)); err != nil {
        log.Fatal(err)
    }
}
fn, err := agent.AssignCallable(ctx, "1*3*34234*991238=?")
if err != nil {
    log.Fatal(err)
}
res := fn()
fmt.Println(res)

How it works

  • LLM to generate:
    • def doc
    • structured calling data
  • reflection
  • engineering

Thanks

zomi team

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyUserInputErr = errors.New("empty user input")
)

Functions

This section is empty.

Types

type Agent

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

func NewAgent

func NewAgent(resolver Resolver, definer Definer) *Agent

func (*Agent) AssignCallable

func (a *Agent) AssignCallable(ctx context.Context, userInput string) (callable function.Callable, err error)

func (*Agent) AssignFunc

func (a *Agent) AssignFunc(ctx context.Context, userInput string) (f *function.Function, rawParams []string, err error)

AssignFunc assigns the user input to the corresponding function.Function

func (*Agent) GetFunc

func (a *Agent) GetFunc(funcName string) (*function.Function, error)

GetFunc looks up the registered function by name

func (*Agent) RegisterFn

func (a *Agent) RegisterFn(ctx context.Context, fn any, opts ...RegisterOption) (*function.Function, error)

RegisterFn registers a golang function can be called the golang fn definition can be generated by the Definer according to options ignore idx in this case will not be considered

func (*Agent) RegisterFunc

func (a *Agent) RegisterFunc(f *function.Function) error

RegisterFunc registers a function.Function to be called

type Definer

type Definer interface {
	Define(ctx context.Context, fn any) (*function.Definition, error)
}

Definer defines a function from golang func

type FuncCallErr

type FuncCallErr struct {
	Msg string
}

func (FuncCallErr) Error

func (e FuncCallErr) Error() string

type FuncCreateErr

type FuncCreateErr struct {
	Msg string
}

func (FuncCreateErr) Error

func (e FuncCreateErr) Error() string

type FuncStrParseErr

type FuncStrParseErr struct {
	Msg string
}

func (FuncStrParseErr) Error

func (e FuncStrParseErr) Error() string

type RegisterOption

type RegisterOption func(*RegisterOpts)

func WithLoadDefDir

func WithLoadDefDir(path string) RegisterOption

func WithOverwrite

func WithOverwrite(overwrite bool) RegisterOption

func WithSaveDefDir

func WithSaveDefDir(path string) RegisterOption

type RegisterOpts

type RegisterOpts struct {
	LoadDefDir string // the dir to load function definition
	SaveDefDir string // the dir to save function definition
	Overwrite  bool   // whether to overwrite the existing definition
}

type Resolver

type Resolver interface {
	AddFunc(def *function.Function) bool
	Resolve(ctx context.Context, userInput string) (call *function.Call, err error)
}

Resolver resolves the user input to a function name and its parameters

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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