Documentation
¶
Index ¶
- Constants
- type Flow
- func (flow *Flow) GetVariable(key string) (any, bool)
- func (flow *Flow) GetVariables() map[string]any
- func (flow *Flow) NewFlowContext(flowContext string, memory any) *FlowContext
- func (flow *Flow) Run(initialFlowContext FlowContext) (*FlowContext, error)
- func (flow *Flow) RunWithInput(input string) (*FlowContext, error)
- func (flow *Flow) RunWithInputAndVariables(input string, variables map[string]any) (*FlowContext, error)
- func (flow *Flow) RunWithMemory(memory ShortTermMemory) (*FlowContext, error)
- func (flow *Flow) RunWithVariables(variables map[string]any) (*FlowContext, error)
- func (flow *Flow) SetVariable(key string, value any)
- type FlowContext
- func (fc *FlowContext) GetVariable(name string) any
- func (fc *FlowContext) GetVariableBool(name string, defaultValue bool) bool
- func (fc *FlowContext) GetVariableInt(name string, defaultValue int) int
- func (fc *FlowContext) GetVariableString(name string, defaultValue string) string
- func (fc *FlowContext) SetVariable(name string, value any)
- func (fc *FlowContext) UnmarshalJsonText(entity any) error
- func (fc *FlowContext) WithVariable(name string, value any) *FlowContext
- type ShortTermMemory
- type Step
- type StepExecutor
- type StepValidator
Constants ¶
const (
DefaultMaxRetryTimes = 3
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Flow ¶
type Flow struct {
Name string
Steps []Step
// The default ClientImpl for the flow
ClientImpl llm.Client
// Variables are key-value pairs that will be available to all steps in the flow
Variables map[string]any
}
func (*Flow) GetVariable ¶
GetVariable gets the value of a variable and returns whether it exists
func (*Flow) GetVariables ¶
RunWithVariables runs the flow with the provided variables. This is a convenience method for creating a flow context with variables and running the flow.
Parameters:
- variables: Map of variable names to values to use in the flow context
Returns:
- The updated flow context after flow execution
- Any error encountered during flow execution
GetVariables returns all variables in the flow
func (*Flow) NewFlowContext ¶
func (flow *Flow) NewFlowContext(flowContext string, memory any) *FlowContext
func (*Flow) Run ¶
func (flow *Flow) Run(initialFlowContext FlowContext) (*FlowContext, error)
func (*Flow) RunWithInput ¶
func (flow *Flow) RunWithInput(input string) (*FlowContext, error)
func (*Flow) RunWithInputAndVariables ¶
func (flow *Flow) RunWithInputAndVariables(input string, variables map[string]any) (*FlowContext, error)
RunWithInputAndVariables runs the flow with the provided input text and variables. This is a convenience method for creating a flow context with text and variables and running the flow.
Parameters:
- input: The input text to use in the flow context
- variables: Map of variable names to values to use in the flow context
Returns:
- The updated flow context after flow execution
- Any error encountered during flow execution
func (*Flow) RunWithMemory ¶
func (flow *Flow) RunWithMemory(memory ShortTermMemory) (*FlowContext, error)
RunWithMemory runs the flow with the provided memory object. This is a convenience method for creating a flow context with memory and running the flow.
Parameters:
- memory: The memory object to use in the flow context
Returns:
- The updated flow context after flow execution
- Any error encountered during flow execution
func (*Flow) RunWithVariables ¶
func (flow *Flow) RunWithVariables(variables map[string]any) (*FlowContext, error)
func (*Flow) SetVariable ¶
SetVariable sets the value of a variable
type FlowContext ¶
type FlowContext struct {
Text string
Memory ShortTermMemory
Variables map[string]any
Flow *Flow
ImageURLs []string
Think string // Stores thinking content extracted from <think> tags in model output
}
FlowContext is the flowContext for a flow. It will be passed to each flow step. The Text field provides the input and output string for a step. For example, before the step runs, the "Text" field is the input string (which might be formatted by the template formatter). After the step runs, the "Text" field is the output string. The Data field could be any data you want to pass between steps.
func NewFlowContext ¶
func NewFlowContext(flowContext string, memory any) *FlowContext
func (*FlowContext) GetVariable ¶
func (fc *FlowContext) GetVariable(name string) any
GetVariable gets the value of a variable. Returns nil if the variable doesn't exist
func (*FlowContext) GetVariableBool ¶
func (fc *FlowContext) GetVariableBool(name string, defaultValue bool) bool
GetVariableBool gets the boolean value of a variable. Returns the defaultValue if the variable doesn't exist or is not a boolean
func (*FlowContext) GetVariableInt ¶
func (fc *FlowContext) GetVariableInt(name string, defaultValue int) int
GetVariableInt gets the integer value of a variable. Returns the defaultValue if the variable doesn't exist or is not an integer
func (*FlowContext) GetVariableString ¶
func (fc *FlowContext) GetVariableString(name string, defaultValue string) string
GetVariableString gets the string value of a variable. Returns the defaultValue if the variable doesn't exist or is not a string
func (*FlowContext) SetVariable ¶
func (fc *FlowContext) SetVariable(name string, value any)
SetVariable sets the value of a variable
func (*FlowContext) UnmarshalJsonText ¶
func (fc *FlowContext) UnmarshalJsonText(entity any) error
func (*FlowContext) WithVariable ¶
func (fc *FlowContext) WithVariable(name string, value any) *FlowContext
WithVariable creates a copy of FlowContext with a new variable set The original FlowContext is not modified
type ShortTermMemory ¶
type ShortTermMemory any
type Step ¶
type Step struct {
ClientImpl llm.Client
Executor StepExecutor
Validator StepValidator
MaxRetryTimes int
Name string
// contains filtered or unexported fields
}
func NewStep ¶
func NewStep(executor StepExecutor, validator StepValidator, client llm.Client) *Step
func NewStepWithValidator ¶
func NewStepWithValidator(stepConfig any, executor StepExecutor, validator StepValidator, client llm.Client, validateClient llm.Client) *Step
Create a new flow step with executor and validator. Parameters:
- stepConfig: the configuration of the step. This parameter is used to pass parameters to the executor and validator. This can be a flexible type object which will be used by the executor and validator. We provide a default StepConfig in Anyi, see [LLMFlowStepConfig] for more details.
- executor: the executor of the step. See StepExecutor for more details.
- validator: the validator of the step. Set this parameter to nil if you don't want to validate the step output. See StepValidator for more details.
- client: the default client of the step. If set to nil, the default client of the flow will be used.
- validateClient: the client used to validate the step output. If set to nil, the default client of the step will be used. If the step doesn't have a default client, the default client of the flow will be used.
type StepExecutor ¶
type StepExecutor interface {
Init() error
Run(flowContext FlowContext, Step *Step) (*FlowContext, error)
}