command

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Autopilots = []string{}

Autopilots the autopilots

View Source
var Commands = map[string]*Command{}

Commands the commands

Functions

func Exit

func Exit(sid string) error

Exit the command

func GetCommands

func GetCommands() ([]driver.Command, error)

GetCommands get all commands

func Load

func Load(cfg config.Config) error

Load load AIGC

func Match

func Match(sid string, query query.Param, input string) (string, error)

Match the command from the content

func SetStore

func SetStore(store Store)

SetStore the driver interface

Types

type Arg

type Arg struct {
	Name        string      `json:"name"`
	Type        string      `json:"type"`
	Description string      `json:"description,omitempty"`
	Default     interface{} `json:"default,omitempty"`
	Required    bool        `json:"required,omitempty"`
}

Arg the argument

type Command

type Command struct {
	ID          string           `json:"-" yaml:"-"`
	Name        string           `json:"name,omitempty"`
	Use         string           `json:"use,omitempty"`
	Connector   string           `json:"connector"`
	Process     string           `json:"process"`
	Prepare     Prepare          `json:"prepare"`
	Description string           `json:"description,omitempty"`
	Optional    Optional         `json:"optional,omitempty"`
	Args        []Arg            `json:"args,omitempty"`
	Actions     []message.Action `json:"actions,omitempty"`
	Stack       string           `json:"stack,omitempty"` // query stack
	Path        string           `json:"path,omitempty"`  // query path
	AI          aigc.AI          `json:"-" yaml:"-"`
}

Command the command struct

func LoadFile

func LoadFile(file string, id string) (*Command, error)

LoadFile load AIGC by file

func LoadSource

func LoadSource(data []byte, file, id string) (*Command, error)

LoadSource load AIGC

func (*Command) NewRequest

func (cmd *Command) NewRequest(ctx Context, conversation conversation.Conversation) (*Request, error)

NewRequest create a new request

type Context

type Context struct {
	Sid             string `json:"-" yaml:"-"`
	Stack           string `json:"stack,omitempty"`
	Path            string `json:"pathname,omitempty"`
	context.Context `json:"-" yaml:"-"`
}

Context the context

func ContextWithCancel

func ContextWithCancel(parent Context) (Context, context.CancelFunc)

ContextWithCancel create a new context

func ContextWithTimeout

func ContextWithTimeout(parent Context, timeout time.Duration) (Context, context.CancelFunc)

ContextWithTimeout create a new context

func NewContext

func NewContext(sid, payload string) Context

NewContext create a new context

func NewContextWithCancel

func NewContextWithCancel(sid, payload string) (Context, context.CancelFunc)

NewContextWithCancel create a new context with cancel

func NewContextWithTimeout

func NewContextWithTimeout(sid, payload string, timeout time.Duration) (Context, context.CancelFunc)

NewContextWithTimeout create a new context with timeout

type Optional

type Optional struct {
	Autopilot   bool `json:"autopilot,omitempty"`
	Confirm     bool `json:"confirm,omitempty"`
	MaxAttempts int  `json:"maxAttempts,omitempty"` // default 10
}

Optional optional

type Prepare

type Prepare struct {
	Before  string                 `json:"before,omitempty"`
	After   string                 `json:"after,omitempty"`
	Prompts []Prompt               `json:"prompts"`
	Option  map[string]interface{} `json:"option"`
}

Prepare the prepare struct

type Prompt

type Prompt struct {
	Role    string `json:"role"`
	Content string `json:"content"`
	Name    string `json:"name,omitempty"`
}

Prompt a prompt

func (Prompt) Replace

func (prompt Prompt) Replace(data maps.MapStrAny) Prompt

Replace the prompt with the context

type Request

type Request struct {
	*Command
	// contains filtered or unexported fields
}

Request the command request

func (*Request) Done

func (req *Request) Done()

Done the request done

func (*Request) Run

func (req *Request) Run(messages []map[string]interface{}, cb func(msg *message.JSON) int) error

Run the command

type Store

type Store interface {
	Match(query query.Param, content string) (string, error)
	Set(key string, cmd driver.Command) error
	Get(key string) (driver.Command, bool)
	Del(key string)
	SetRequest(sid, id, cid string) error
	GetRequest(sid string) (string, string, bool)
	DelRequest(sid string)
	GetCommands() ([]driver.Command, error)
}

Store the command driver

var DefaultStore Store

DefaultStore the default store driver

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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