Documentation
¶
Index ¶
- Constants
- Variables
- func AddDefinedSystemPrompt(prompt string)
- func AddDefinedTool(usage string, entrypoint string) error
- func ClearDefinedSystemPrompts()
- func ClearDefinedTools()
- func CombineFields(fields []string) (string, error)
- func FindExecutableNames(PATH string, wd string) ([]string, error)
- func GetAllConfig() map[ConfigName]string
- func GetConfig(name ConfigName) string
- func GetDefinedSystemPrompts() string
- func GetDefinedTools() map[string]*DefinedTool
- func GetIntConfig(name ConfigName) (value int, ok bool)
- func IsInteractive(writer io.Writer) bool
- func LookPath(file string, wd string, PATH string) (string, error)
- func NewCapturedStdIO(shell *Shell, writer io.Writer) (*os.File, error)
- func ReaderDescriptor(reader io.Reader) (*os.File, error)
- func SetConfig(name ConfigName, value string)
- func WriterDescriptor(writer io.Writer) (*os.File, error)
- type AIAssistantAnswer
- type AIExecution
- type ChanIO
- type CommandExecution
- func (c *CommandExecution) AnswerText() string
- func (c *CommandExecution) AppendQA(qa *AIExecution)
- func (c *CommandExecution) Buffer() *strings.Builder
- func (c *CommandExecution) Cancel()
- func (c *CommandExecution) ColorSupported() bool
- func (c *CommandExecution) Context() context.Context
- func (c *CommandExecution) Incomplete() bool
- func (c *CommandExecution) Interactive() bool
- func (ce *CommandExecution) NewSubCommandExecution(fields []string, hc *interp.HandlerContext) *SubCommandExecution
- func (c *CommandExecution) QA() []*AIExecution
- func (c *CommandExecution) Terminated() bool
- type ConfigName
- type DefinedTool
- type FragmentCompleter
- type FragmentCompleterFunc
- type Shell
- func (s *Shell) AbsoluteFileName() string
- func (s *Shell) Dir() string
- func (s *Shell) Eval(ce *CommandExecution, code []byte, modifierFunc func(sce *SubCommandExecution)) error
- func (s *Shell) FileName() string
- func (s *Shell) FindExecutableNames() ([]string, error)
- func (s *Shell) LookPath(file string) (string, error)
- func (s *Shell) PrintError(writer io.Writer, err error)
- func (s *Shell) Start(ctx context.Context) error
- func (s *Shell) State() *ShellState
- func (s *Shell) Use(plugin ...ShellPlugin) error
- type ShellCompleter
- type ShellMode
- type ShellOption
- type ShellPlugin
- type ShellState
- func (s *ShellState) Arch() string
- func (s *ShellState) CurrentExecution() *CommandExecution
- func (s *ShellState) Mode() ShellMode
- func (s *ShellState) OS() string
- func (s *ShellState) SetCurrentExecution(ce *CommandExecution)
- func (s *ShellState) SetMode(mode ShellMode)
- func (s *ShellState) User() *user.User
- type SubCommandExecution
- func (c *SubCommandExecution) Cmd() string
- func (c *SubCommandExecution) ColorSupported() bool
- func (sce *SubCommandExecution) DefaultExecHandler() error
- func (c *SubCommandExecution) Error() error
- func (c *SubCommandExecution) Fields() []string
- func (c *SubCommandExecution) Inherit(parent *SubCommandExecution)
- func (c *SubCommandExecution) Interactive() bool
- func (c *SubCommandExecution) Mode() ShellMode
- func (c *SubCommandExecution) QA() *AIExecution
- func (c *SubCommandExecution) SetFields(fields []string)
- func (c *SubCommandExecution) SetMode(mode ShellMode)
- func (c *SubCommandExecution) Stdai() io.Writer
- func (c *SubCommandExecution) Stderr() io.Writer
- func (c *SubCommandExecution) Stdin() io.Reader
- func (c *SubCommandExecution) Stdout() io.Writer
Constants ¶
View Source
const ( RCFileName = ".aishrc" HistoryFileName = ".aish_history" )
View Source
const ( ColorReset = "\033[0m" ColorRed = "\033[31m" ColorGreen = "\033[32m" ColorYellow = "\033[33m" ColorBlue = "\033[34m" ColorPurple = "\033[35m" ColorCyan = "\033[36m" ColorWhite = "\033[37m" ColorGray = "\033[90m" // BG colors BgBlue = "\033[44m" BgGreen = "\033[42m" BgRed = "\033[41m" BgYellow = "\033[43m" // 样式 Bold = "\033[1m" Italic = "\033[3m" Underline = "\033[4m" )
ANSI color code
View Source
const DefaultFileName = "aish"
Variables ¶
View Source
var ConfigKeys = []ConfigName{ ConfigOpenAIAPIKey, ConfigOpenAIModel, ConfigOpenAIBaseURL, ConfigMaxIterations, ConfigMaxHistory, }
View Source
var ErrPanic = errors.New("panic")
Functions ¶
func AddDefinedSystemPrompt ¶
func AddDefinedSystemPrompt(prompt string)
func AddDefinedTool ¶
func ClearDefinedSystemPrompts ¶
func ClearDefinedSystemPrompts()
func ClearDefinedTools ¶
func ClearDefinedTools()
func CombineFields ¶
func GetAllConfig ¶
func GetAllConfig() map[ConfigName]string
func GetConfig ¶
func GetConfig(name ConfigName) string
func GetDefinedSystemPrompts ¶
func GetDefinedSystemPrompts() string
func GetDefinedTools ¶
func GetDefinedTools() map[string]*DefinedTool
func GetIntConfig ¶
func GetIntConfig(name ConfigName) (value int, ok bool)
func IsInteractive ¶
func SetConfig ¶
func SetConfig(name ConfigName, value string)
Types ¶
type AIAssistantAnswer ¶
type AIAssistantAnswer struct {
Text string `json:"text"`
ToolCall *openai.ChatCompletionMessageToolCall `json:"tool_call"`
}
type AIExecution ¶
type AIExecution struct {
UnderToolCall *openai.ChatCompletionMessageToolCall
Question string
Answers []AIAssistantAnswer
// contains filtered or unexported fields
}
func (*AIExecution) IsRoot ¶
func (e *AIExecution) IsRoot() bool
func (*AIExecution) Trace ¶
func (e *AIExecution) Trace() []*AIExecution
type ChanIO ¶
type ChanIO struct {
// contains filtered or unexported fields
}
type CommandExecution ¶
type CommandExecution struct {
// contains filtered or unexported fields
}
func GetCommandExecution ¶
func GetCommandExecution(ctx context.Context) (*CommandExecution, bool)
func (*CommandExecution) AnswerText ¶
func (c *CommandExecution) AnswerText() string
func (*CommandExecution) AppendQA ¶
func (c *CommandExecution) AppendQA(qa *AIExecution)
func (*CommandExecution) Buffer ¶
func (c *CommandExecution) Buffer() *strings.Builder
func (*CommandExecution) Cancel ¶
func (c *CommandExecution) Cancel()
func (*CommandExecution) ColorSupported ¶
func (c *CommandExecution) ColorSupported() bool
func (*CommandExecution) Context ¶
func (c *CommandExecution) Context() context.Context
func (*CommandExecution) Incomplete ¶
func (c *CommandExecution) Incomplete() bool
func (*CommandExecution) Interactive ¶
func (c *CommandExecution) Interactive() bool
func (*CommandExecution) NewSubCommandExecution ¶
func (ce *CommandExecution) NewSubCommandExecution(fields []string, hc *interp.HandlerContext) *SubCommandExecution
func (*CommandExecution) QA ¶
func (c *CommandExecution) QA() []*AIExecution
func (*CommandExecution) Terminated ¶
func (c *CommandExecution) Terminated() bool
type ConfigName ¶
type ConfigName string
const ( ConfigOpenAIAPIKey ConfigName = "openai.api_key" ConfigOpenAIModel ConfigName = "openai.model" ConfigOpenAIBaseURL ConfigName = "openai.base_url" ConfigMaxIterations ConfigName = "max_iter" ConfigMaxHistory ConfigName = "max_history" ConfigMaxMessageLength ConfigName = "max_message_length" )
type DefinedTool ¶
func GetDefinedTool ¶
func GetDefinedTool(name string) (tool *DefinedTool, ok bool)
type FragmentCompleter ¶
type FragmentCompleter struct {
// contains filtered or unexported fields
}
func NewFragmentCompleter ¶
func NewFragmentCompleter(do FragmentCompleterFunc) *FragmentCompleter
type FragmentCompleterFunc ¶
type Shell ¶
type Shell struct {
// contains filtered or unexported fields
}
func NewShell ¶
func NewShell(opts ...ShellOption) (*Shell, error)
func (*Shell) AbsoluteFileName ¶
func (*Shell) Eval ¶
func (s *Shell) Eval(ce *CommandExecution, code []byte, modifierFunc func(sce *SubCommandExecution)) error
func (*Shell) FindExecutableNames ¶
func (*Shell) State ¶
func (s *Shell) State() *ShellState
func (*Shell) Use ¶
func (s *Shell) Use(plugin ...ShellPlugin) error
type ShellCompleter ¶
type ShellCompleter struct {
// contains filtered or unexported fields
}
func NewShellCompleter ¶
func NewShellCompleter(shell *Shell) *ShellCompleter
type ShellOption ¶
type ShellOption func(*Shell)
func WithEnviron ¶
func WithEnviron(environ []string) ShellOption
func WithFileName ¶
func WithFileName(fileName string, absoluteFileName string) ShellOption
func WithParams ¶
func WithParams(params []string) ShellOption
type ShellPlugin ¶
type ShellPlugin interface {
ID() string
// Shell related
Install(shell *Shell) error
AutoComplete(line []rune, pos int, shell *Shell) (newLine [][]rune, length int)
// CommandExecution related
PrepareContext(ce *CommandExecution, shell *Shell) (context.Context, error)
GeneratePrompt(ce *CommandExecution, shell *Shell) (ok bool, prompt string, err error)
End(ce *CommandExecution, shell *Shell) error
// SubCommandExecution related
BeforeExecute(ce *CommandExecution, sce *SubCommandExecution, shell *Shell) error
Execute(ce *CommandExecution, sce *SubCommandExecution, shell *Shell) (ok bool, err error)
AfterExecute(ce *CommandExecution, sce *SubCommandExecution, shell *Shell) error
}
type ShellState ¶
type ShellState struct {
// contains filtered or unexported fields
}
func NewDefaultShellState ¶
func NewDefaultShellState() (*ShellState, error)
func (*ShellState) Arch ¶
func (s *ShellState) Arch() string
func (*ShellState) CurrentExecution ¶
func (s *ShellState) CurrentExecution() *CommandExecution
func (*ShellState) Mode ¶
func (s *ShellState) Mode() ShellMode
func (*ShellState) OS ¶
func (s *ShellState) OS() string
func (*ShellState) SetCurrentExecution ¶
func (s *ShellState) SetCurrentExecution(ce *CommandExecution)
func (*ShellState) SetMode ¶
func (s *ShellState) SetMode(mode ShellMode)
func (*ShellState) User ¶
func (s *ShellState) User() *user.User
type SubCommandExecution ¶
type SubCommandExecution struct {
// contains filtered or unexported fields
}
func (*SubCommandExecution) Cmd ¶
func (c *SubCommandExecution) Cmd() string
func (*SubCommandExecution) ColorSupported ¶
func (c *SubCommandExecution) ColorSupported() bool
func (*SubCommandExecution) DefaultExecHandler ¶
func (sce *SubCommandExecution) DefaultExecHandler() error
func (*SubCommandExecution) Error ¶
func (c *SubCommandExecution) Error() error
func (*SubCommandExecution) Fields ¶
func (c *SubCommandExecution) Fields() []string
func (*SubCommandExecution) Inherit ¶
func (c *SubCommandExecution) Inherit(parent *SubCommandExecution)
func (*SubCommandExecution) Interactive ¶
func (c *SubCommandExecution) Interactive() bool
func (*SubCommandExecution) Mode ¶
func (c *SubCommandExecution) Mode() ShellMode
func (*SubCommandExecution) QA ¶
func (c *SubCommandExecution) QA() *AIExecution
func (*SubCommandExecution) SetFields ¶
func (c *SubCommandExecution) SetFields(fields []string)
func (*SubCommandExecution) SetMode ¶
func (c *SubCommandExecution) SetMode(mode ShellMode)
func (*SubCommandExecution) Stdai ¶
func (c *SubCommandExecution) Stdai() io.Writer
Used to write content that only visible to AI
func (*SubCommandExecution) Stderr ¶
func (c *SubCommandExecution) Stderr() io.Writer
Used to write error content that visible to both user and AI
func (*SubCommandExecution) Stdin ¶
func (c *SubCommandExecution) Stdin() io.Reader
func (*SubCommandExecution) Stdout ¶
func (c *SubCommandExecution) Stdout() io.Writer
Used to write content that visible to both user and AI
Click to show internal directories.
Click to hide internal directories.