Documentation ¶
Index ¶
- func LogNode(n Node, color string, format string, kwargs ...any)
- func RouterSimpleDeciderFunc(ctx context.Context, input Input, def Node, chains map[string]Node) (Node, Input, error)
- type BaseNode
- type ChatMemory
- func (c *ChatMemory) AddBotMessage(content string)
- func (c *ChatMemory) AddUserMessage(content string)
- func (c *ChatMemory) BotName() string
- func (c *ChatMemory) Execute(ctx context.Context, input Input) (string, error)
- func (c *ChatMemory) History() []string
- func (c *ChatMemory) System() string
- func (c *ChatMemory) UserName() string
- func (c *ChatMemory) WithStorage(storage *[]string) *ChatMemory
- type Error
- type Func
- type Info
- type Input
- func (i Input) Debug() bool
- func (i Input) Get(key string) any
- func (i Input) Input() string
- func (i Input) LLMOptions() []engine.LLMOption
- func (i Input) ResetLLMOptions() Input
- func (i Input) Scratchpad() string
- func (i Input) Set(k string, v any) Input
- func (i Input) WithDebug(debug bool) Input
- func (i Input) WithInput(in string) Input
- func (i Input) WithLLMOptions(options ...engine.LLMOption) Input
- func (i Input) WithScratchpad(scratchpad string) Input
- type LLM
- type Node
- type Prompt
- type PromptError
- type Router
- type RouterDeciderFunc
- type RouterSimpleInput
- type Subchain
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BaseNode ¶
type BaseNode struct {
// contains filtered or unexported fields
}
BaseNode is the generic implementation of a the Node interface. It is usually embedded into every kind of nodes.
func (*BaseNode) Chain ¶
Chain chains the receiver with the given Node. When the receiver is executed, its generated output will be fed into the given Node. You cannot unlink a node. If you try to chain an already chained node the function will panic.
func (*BaseNode) Execute ¶
Execute starts the execution process of the chain, starting from the receiver. The given Input will be passed as is to the next Node, which will pass it on to the next, and so on. It will return the final output generated by the last Node in the chain.
This does not do anything per se. It just provides the basic chaining mechanism to other kind of Nodes.
type ChatMemory ¶
type ChatMemory struct { *BaseNode // contains filtered or unexported fields }
ChatMemory holds information about chat history. This will be rewritten as this does not belong here.
func NewChatMemory ¶
func NewChatMemory(info Info, system string, botname string, username string) *ChatMemory
NewChatMemory returns a new ChatMemory with the provided information.
func (*ChatMemory) AddBotMessage ¶
func (c *ChatMemory) AddBotMessage(content string)
AddBotMessage add a new bot message to the history
func (*ChatMemory) AddUserMessage ¶
func (c *ChatMemory) AddUserMessage(content string)
AddUserMessage add a new user message to the history
func (*ChatMemory) BotName ¶
func (c *ChatMemory) BotName() string
BotName returns the current botname.
func (*ChatMemory) History ¶
func (c *ChatMemory) History() []string
History returns the current history.
func (*ChatMemory) System ¶
func (c *ChatMemory) System() string
System returns the current system name.
func (*ChatMemory) UserName ¶
func (c *ChatMemory) UserName() string
UserName returns the current username.
func (*ChatMemory) WithStorage ¶
func (c *ChatMemory) WithStorage(storage *[]string) *ChatMemory
WithStorage sets the storage backend. Yeah it's an array.. I told you this will be rewritten.
type Error ¶
An Error represents an error returned by a node.
type Func ¶
type Func struct { *BaseNode // contains filtered or unexported fields }
A Func is a node that will run a given function as its execution method.
type Info ¶
Info holds the basic information about a Node. Every Node info can be accessed by calling node.Info(). This can be used to help identify a chain so it can be called by an agent.
type Input ¶
type Input struct {
// contains filtered or unexported fields
}
Input represents the data passed to a Node.
func NewInput ¶
NewInput returns a new Input with the given string and llm.Options. Note that the llm.Option will be carried out until it reaches a LLM Node. After that they will be discarded.
func (Input) LLMOptions ¶
LLMOptions returns the current llm.Options.
func (Input) ResetLLMOptions ¶
ResetLLMOptions returns a copy of the Input after removing all llm.Options. This is called by the LLM nodes.
func (Input) Scratchpad ¶
Scratchpad returns the current scratchpad.
func (Input) WithDebug ¶
WithDebug returns a copy of the receiver with the Debug flag activated. The Node will usually print detailed information about them when they deal with an input with Debug set to true.
func (Input) WithLLMOptions ¶
WithLLMOptions returns a copy of the receiver with the given llm.Options added to it.
func (Input) WithScratchpad ¶
WithScratchpad returns a copy of the receiver with the given scratchpad added.
type LLM ¶
type LLM struct { *BaseNode // contains filtered or unexported fields }
LLM is a node responsible for running its input into an inference engine.
type Node ¶
type Node interface { Info() Info Chain(Node) Next() Node Execute(context.Context, Input) (string, error) }
Node is the base object of the framework.
A Node can be chained to another node. Together they form a chain.
[prompt:genstory] -> [llm:mistral] -> [prompt:summarize] -> [llm:zephyr]
A chain can contains nest chains:
[prompt:search] -> [ [prompt:summarize] -> [llm] ] -> [func:format] -> [llm]
A node can be executed by calling its Execute method. The execution is given a context.Context and an Input. It returns a string and an eventual error. This output will then be fed to the next Node in the chain. This process continues until the execution reaches a node with no Next() Node. Then the output is unstacked and returned by the initial executed Node.
type Prompt ¶
type Prompt struct { *BaseNode // contains filtered or unexported fields }
A Prompt is a Node that is responsible for generating a prompt from a template using the informations contained in the given input.
func NewPrompt ¶
NewPrompt returns a new *Prompt with the given template and ll.Options. The llm.Options will always be appended to the input, before the input's own LLMOptions. So input's options will take precedence.
func (*Prompt) WithMaxRetries ¶
WithMaxRetries sets the maximum number of retries the prompt is willing to make when the execution returns a PromptError.
type PromptError ¶
PromptError represents an error in the generated text generation. The scratchpad will be used by the Prompt to fill the input.Scratchpad before retrying.
func NewPromptError ¶
func NewPromptError(scratchpad string, err error) PromptError
NewPromptError returns a PromptError.
func (PromptError) Error ¶
func (e PromptError) Error() string
Error implements the error interface.
func (PromptError) Unwrap ¶
func (e PromptError) Unwrap() error
Unwrap implements the error interface.
type Router ¶
type Router struct { *BaseNode // contains filtered or unexported fields }
A Router is a node that can route its Input to one of several chains. The decision is made by a RouterDeciderFunc.
func NewRouter ¶
func NewRouter( info Info, decider RouterDeciderFunc, defaultChain Node, chains ...Node, ) *Router
NewRouter returns a new Router.
type RouterDeciderFunc ¶
RouterDeciderFunc is the type of the function used by the Router. It is responsible for making a decision on which chains the router should send the input to. It is given the Router's context, the Input as well as a map of available subchains, keyed by their name. It must return which Node to use and which Input to pass to it.
type RouterSimpleInput ¶
type RouterSimpleInput struct { Params map[string]any `json:"params,omitempty"` Name string `json:"name"` Input string `json:"input,omitempty"` }
RouterSimpleInput is the data structure that will be used to decide how to router the traffic by the RouterSimpleDeciderFunc.
type Subchain ¶
type Subchain struct { *BaseNode // contains filtered or unexported fields }
A Subchain is a Node that holds a separate set of Nodes.
It can be considered as a single Node.
[node] -> [[node]->[node]->[node]] -> [node]
It can be useful to handle a separate set of Input or llm.Options. Subchains can also be used in Router nodes, that will execute a certain Subchain based on a condition.
[classify] -> [llm] -> [router] ?-> [summarize] ->[llm1] ?-> [search] -> [llm2] ?-> [generate] -> [llm3]
Subchain embeds the BaseNode and can be used as any other node.
func NewSubchain ¶
NewSubchain creates a new Subchain with the given Info and given Nodes. The function will chain all of them in order. The given Node must not be already chained or it will panic.
func NewSubchainWithName ¶
NewSubchainWithName is a convenience function to create a named Subchain.