Documentation ¶
Overview ¶
Package chain enables the creation and execution of chains, which are sequences of calls to LLMs or other utilities. It provides a standardized interface for working with chains and allows for seamless integration with various tools and services.
Index ¶
- Variables
- func IsChatModel(model schema.Model) bool
- func IsLLM(model schema.Model) bool
- type Conditional
- type ConditionalFunc
- type ConditionalPromptSelector
- type Conversation
- func (c *Conversation) Call(ctx context.Context, inputs schema.ChainValues, ...) (schema.ChainValues, error)
- func (c *Conversation) Callbacks() []schema.Callback
- func (c *Conversation) InputKeys() []string
- func (c *Conversation) Memory() schema.Memory
- func (c *Conversation) OutputKeys() []string
- func (c *Conversation) Prompt() *prompt.Template
- func (c *Conversation) Type() string
- func (c *Conversation) Verbose() bool
- type ConversationOptions
- type LLM
- func (c *LLM) Call(ctx context.Context, inputs schema.ChainValues, ...) (schema.ChainValues, error)
- func (c *LLM) Callbacks() []schema.Callback
- func (c *LLM) GetNumTokens(text string) (uint, error)
- func (c *LLM) InputKeys() []string
- func (c *LLM) Memory() schema.Memory
- func (c *LLM) OutputKeys() []string
- func (c *LLM) Prompt() *prompt.Template
- func (c *LLM) Type() string
- func (c *LLM) Verbose() bool
- type LLMBash
- func (c *LLMBash) Call(ctx context.Context, values schema.ChainValues, ...) (schema.ChainValues, error)
- func (c *LLMBash) Callbacks() []schema.Callback
- func (c *LLMBash) InputKeys() []string
- func (c *LLMBash) Memory() schema.Memory
- func (c *LLMBash) OutputKeys() []string
- func (c *LLMBash) Type() string
- func (c *LLMBash) Verbose() bool
- type LLMBashOptions
- type LLMMath
- func (c *LLMMath) Call(ctx context.Context, values schema.ChainValues, ...) (schema.ChainValues, error)
- func (c *LLMMath) Callbacks() []schema.Callback
- func (c *LLMMath) InputKeys() []string
- func (c *LLMMath) Memory() schema.Memory
- func (c *LLMMath) OutputKeys() []string
- func (c *LLMMath) Type() string
- func (c *LLMMath) Verbose() bool
- type LLMMathOptions
- type LLMOptions
- type OpenAIClient
- type OpenAIModerateFunc
- type OpenAIModeration
- func (c *OpenAIModeration) Call(ctx context.Context, inputs schema.ChainValues, ...) (schema.ChainValues, error)
- func (c *OpenAIModeration) Callbacks() []schema.Callback
- func (c *OpenAIModeration) InputKeys() []string
- func (c *OpenAIModeration) Memory() schema.Memory
- func (c *OpenAIModeration) OutputKeys() []string
- func (c *OpenAIModeration) Prompt() *prompt.Template
- func (c *OpenAIModeration) Type() string
- func (c *OpenAIModeration) Verbose() bool
- type OpenAIModerationOptions
- type PromptSelector
- type Sequential
- func (c *Sequential) Call(ctx context.Context, inputs schema.ChainValues, ...) (schema.ChainValues, error)
- func (c *Sequential) Callbacks() []schema.Callback
- func (c *Sequential) InputKeys() []string
- func (c *Sequential) Memory() schema.Memory
- func (c *Sequential) OutputKeys() []string
- func (c *Sequential) Type() string
- func (c *Sequential) Verbose() bool
- type SequentialOptions
- type SimpleSequential
- func (c *SimpleSequential) Call(ctx context.Context, inputs schema.ChainValues, ...) (schema.ChainValues, error)
- func (c *SimpleSequential) Callbacks() []schema.Callback
- func (c *SimpleSequential) InputKeys() []string
- func (c *SimpleSequential) Memory() schema.Memory
- func (c *SimpleSequential) OutputKeys() []string
- func (c *SimpleSequential) Type() string
- func (c *SimpleSequential) Verbose() bool
- type SimpleSequentialOptions
- type Transform
- func (c *Transform) Call(ctx context.Context, inputs schema.ChainValues, ...) (schema.ChainValues, error)
- func (c *Transform) Callbacks() []schema.Callback
- func (c *Transform) InputKeys() []string
- func (c *Transform) Memory() schema.Memory
- func (c *Transform) OutputKeys() []string
- func (c *Transform) Type() string
- func (c *Transform) Verbose() bool
- type TransformFunc
- type TransformOptions
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func IsChatModel ¶ added in v0.0.14
IsChatModel checks if the given model is of type schema.ChatModel.
Types ¶
type Conditional ¶ added in v0.0.14
type Conditional struct { Condition ConditionalFunc Prompt *prompt.Template }
Conditional represents a conditional prompt configuration.
type ConditionalFunc ¶ added in v0.0.14
ConditionalFunc represents a function that evaluates a condition based on a model.
type ConditionalPromptSelector ¶ added in v0.0.14
type ConditionalPromptSelector struct { DefaultPrompt *prompt.Template Conditionals []Conditional }
ConditionalPromptSelector is a prompt selector that selects prompts based on conditions.
func (*ConditionalPromptSelector) GetPrompt ¶ added in v0.0.14
func (cps *ConditionalPromptSelector) GetPrompt(model schema.Model) *prompt.Template
GetPrompt selects a prompt template based on the provided model. It evaluates the conditions in order and returns the prompt associated with the first matching condition, or returns the default prompt if no condition is met.
type Conversation ¶ added in v0.0.10
type Conversation struct {
// contains filtered or unexported fields
}
func NewConversation ¶ added in v0.0.10
func NewConversation(llm schema.LLM, optFns ...func(o *ConversationOptions)) (*Conversation, error)
func (*Conversation) Call ¶ added in v0.0.10
func (c *Conversation) Call(ctx context.Context, inputs schema.ChainValues, optFns ...func(o *schema.CallOptions)) (schema.ChainValues, error)
Call executes the ConversationalRetrieval chain with the given context and inputs. It returns the outputs of the chain or an error, if any.
func (*Conversation) Callbacks ¶ added in v0.0.13
func (c *Conversation) Callbacks() []schema.Callback
Callbacks returns the callbacks associated with the chain.
func (*Conversation) InputKeys ¶ added in v0.0.10
func (c *Conversation) InputKeys() []string
InputKeys returns the expected input keys.
func (*Conversation) Memory ¶ added in v0.0.13
func (c *Conversation) Memory() schema.Memory
Memory returns the memory associated with the chain.
func (*Conversation) OutputKeys ¶ added in v0.0.10
func (c *Conversation) OutputKeys() []string
OutputKeys returns the output keys the chain will return.
func (*Conversation) Prompt ¶ added in v0.0.10
func (c *Conversation) Prompt() *prompt.Template
func (*Conversation) Type ¶ added in v0.0.13
func (c *Conversation) Type() string
Type returns the type of the chain.
func (*Conversation) Verbose ¶ added in v0.0.13
func (c *Conversation) Verbose() bool
Verbose returns the verbosity setting of the chain.
type ConversationOptions ¶ added in v0.0.10
type ConversationOptions struct { *schema.CallbackOptions Prompt *prompt.Template Memory schema.Memory OutputKey string OutputParser schema.OutputParser[any] // ReturnFinalOnly determines whether to return only the final parsed result or include extra generation information. // When set to true (default), the field will return only the final parsed result. // If set to false, the field will include additional information about the generation along with the final parsed result. ReturnFinalOnly bool }
type LLM ¶ added in v0.0.16
type LLM struct {
// contains filtered or unexported fields
}
func (*LLM) Call ¶ added in v0.0.16
func (c *LLM) Call(ctx context.Context, inputs schema.ChainValues, optFns ...func(o *schema.CallOptions)) (schema.ChainValues, error)
Call executes the ConversationalRetrieval chain with the given context and inputs. It returns the outputs of the chain or an error, if any.
func (*LLM) OutputKeys ¶ added in v0.0.16
OutputKeys returns the output keys the chain will return.
type LLMBash ¶ added in v0.0.11
type LLMBash struct {
// contains filtered or unexported fields
}
func NewLLMBash ¶ added in v0.0.11
func NewLLMBash(llm schema.LLM, optFns ...func(o *LLMBashOptions)) (*LLMBash, error)
func (*LLMBash) Call ¶ added in v0.0.11
func (c *LLMBash) Call(ctx context.Context, values schema.ChainValues, optFns ...func(o *schema.CallOptions)) (schema.ChainValues, error)
Call executes the ConversationalRetrieval chain with the given context and inputs. It returns the outputs of the chain or an error, if any.
func (*LLMBash) OutputKeys ¶ added in v0.0.11
OutputKeys returns the output keys the chain will return.
type LLMBashOptions ¶ added in v0.0.11
type LLMBashOptions struct { *schema.CallbackOptions InputKey string OutputKey string }
type LLMMath ¶ added in v0.0.11
type LLMMath struct {
// contains filtered or unexported fields
}
func NewLLMMath ¶ added in v0.0.11
func NewLLMMath(llm schema.LLM, optFns ...func(o *LLMMathOptions)) (*LLMMath, error)
func (*LLMMath) Call ¶ added in v0.0.11
func (c *LLMMath) Call(ctx context.Context, values schema.ChainValues, optFns ...func(o *schema.CallOptions)) (schema.ChainValues, error)
Call executes the ConversationalRetrieval chain with the given context and inputs. It returns the outputs of the chain or an error, if any.
func (*LLMMath) Callbacks ¶ added in v0.0.13
Callbacks returns the callbacks associated with the chain.
func (*LLMMath) OutputKeys ¶ added in v0.0.11
OutputKeys returns the output keys the chain will return.
type LLMMathOptions ¶ added in v0.0.11
type LLMMathOptions struct { *schema.CallbackOptions InputKey string OutputKey string }
type LLMOptions ¶ added in v0.0.16
type LLMOptions struct { *schema.CallbackOptions Memory schema.Memory OutputKey string OutputParser schema.OutputParser[any] // ReturnFinalOnly determines whether to return only the final parsed result or include extra generation information. // When set to true (default), the field will return only the final parsed result. // If set to false, the field will include additional information about the generation along with the final parsed result. ReturnFinalOnly bool }
type OpenAIClient ¶ added in v0.0.31
type OpenAIModerateFunc ¶ added in v0.0.31
type OpenAIModerateFunc func(id, model string, result openai.Result) (schema.ChainValues, error)
type OpenAIModeration ¶ added in v0.0.31
type OpenAIModeration struct {
// contains filtered or unexported fields
}
func NewOpenAIModeration ¶ added in v0.0.31
func NewOpenAIModeration(apiKey string, optFns ...func(o *OpenAIModerationOptions)) (*OpenAIModeration, error)
func NewOpenAIModerationFromClient ¶ added in v0.0.31
func NewOpenAIModerationFromClient(client OpenAIClient, optFns ...func(o *OpenAIModerationOptions)) (*OpenAIModeration, error)
func (*OpenAIModeration) Call ¶ added in v0.0.31
func (c *OpenAIModeration) Call(ctx context.Context, inputs schema.ChainValues, optFns ...func(o *schema.CallOptions)) (schema.ChainValues, error)
func (*OpenAIModeration) Callbacks ¶ added in v0.0.31
func (c *OpenAIModeration) Callbacks() []schema.Callback
Callbacks returns the callbacks associated with the chain.
func (*OpenAIModeration) InputKeys ¶ added in v0.0.31
func (c *OpenAIModeration) InputKeys() []string
InputKeys returns the expected input keys.
func (*OpenAIModeration) Memory ¶ added in v0.0.31
func (c *OpenAIModeration) Memory() schema.Memory
Memory returns the memory associated with the chain.
func (*OpenAIModeration) OutputKeys ¶ added in v0.0.31
func (c *OpenAIModeration) OutputKeys() []string
OutputKeys returns the output keys the chain will return.
func (*OpenAIModeration) Prompt ¶ added in v0.0.31
func (c *OpenAIModeration) Prompt() *prompt.Template
func (*OpenAIModeration) Type ¶ added in v0.0.31
func (c *OpenAIModeration) Type() string
Type returns the type of the chain.
func (*OpenAIModeration) Verbose ¶ added in v0.0.31
func (c *OpenAIModeration) Verbose() bool
Verbose returns the verbosity setting of the chain.
type OpenAIModerationOptions ¶ added in v0.0.31
type OpenAIModerationOptions struct { *schema.CallbackOptions ModelName string InputKey string OutputKey string OpenAIModerateFunc OpenAIModerateFunc }
type PromptSelector ¶ added in v0.0.14
PromptSelector is an interface for selecting prompts based on a model.
type Sequential ¶ added in v0.0.21
type Sequential struct {
// contains filtered or unexported fields
}
func NewSequential ¶ added in v0.0.21
func NewSequential(chains []schema.Chain, inputKeys []string, optFns ...func(o *SequentialOptions)) (*Sequential, error)
func (*Sequential) Call ¶ added in v0.0.21
func (c *Sequential) Call(ctx context.Context, inputs schema.ChainValues, optFns ...func(o *schema.CallOptions)) (schema.ChainValues, error)
Call executes the Sequential chain with the given context and inputs. It returns the outputs of the chain or an error, if any.
func (*Sequential) Callbacks ¶ added in v0.0.21
func (c *Sequential) Callbacks() []schema.Callback
Callbacks returns the callbacks associated with the chain.
func (*Sequential) InputKeys ¶ added in v0.0.21
func (c *Sequential) InputKeys() []string
InputKeys returns the expected input keys.
func (*Sequential) Memory ¶ added in v0.0.21
func (c *Sequential) Memory() schema.Memory
Memory returns the memory associated with the chain.
func (*Sequential) OutputKeys ¶ added in v0.0.21
func (c *Sequential) OutputKeys() []string
OutputKeys returns the output keys the chain will return.
func (*Sequential) Type ¶ added in v0.0.21
func (c *Sequential) Type() string
Type returns the type of the chain.
func (*Sequential) Verbose ¶ added in v0.0.21
func (c *Sequential) Verbose() bool
Verbose returns the verbosity setting of the chain.
type SequentialOptions ¶ added in v0.0.21
type SimpleSequential ¶ added in v0.0.21
type SimpleSequential struct {
// contains filtered or unexported fields
}
func NewSimpleSequential ¶ added in v0.0.21
func NewSimpleSequential(chains []schema.Chain, optFns ...func(o *SimpleSequentialOptions)) (*SimpleSequential, error)
func (*SimpleSequential) Call ¶ added in v0.0.21
func (c *SimpleSequential) Call(ctx context.Context, inputs schema.ChainValues, optFns ...func(o *schema.CallOptions)) (schema.ChainValues, error)
Call executes the SimpleSequential chain with the given context and inputs. It returns the outputs of the chain or an error, if any.
func (*SimpleSequential) Callbacks ¶ added in v0.0.21
func (c *SimpleSequential) Callbacks() []schema.Callback
Callbacks returns the callbacks associated with the chain.
func (*SimpleSequential) InputKeys ¶ added in v0.0.21
func (c *SimpleSequential) InputKeys() []string
InputKeys returns the expected input keys.
func (*SimpleSequential) Memory ¶ added in v0.0.21
func (c *SimpleSequential) Memory() schema.Memory
Memory returns the memory associated with the chain.
func (*SimpleSequential) OutputKeys ¶ added in v0.0.21
func (c *SimpleSequential) OutputKeys() []string
OutputKeys returns the output keys the chain will return.
func (*SimpleSequential) Type ¶ added in v0.0.21
func (c *SimpleSequential) Type() string
Type returns the type of the chain.
func (*SimpleSequential) Verbose ¶ added in v0.0.21
func (c *SimpleSequential) Verbose() bool
Verbose returns the verbosity setting of the chain.
type SimpleSequentialOptions ¶ added in v0.0.21
type Transform ¶ added in v0.0.17
type Transform struct {
// contains filtered or unexported fields
}
func NewTransform ¶ added in v0.0.17
func NewTransform(inputKeys, outputKeys []string, transform TransformFunc, optFns ...func(o *TransformOptions)) (*Transform, error)
func (*Transform) Call ¶ added in v0.0.17
func (c *Transform) Call(ctx context.Context, inputs schema.ChainValues, optFns ...func(o *schema.CallOptions)) (schema.ChainValues, error)
Call executes the ConversationalRetrieval chain with the given context and inputs. It returns the outputs of the chain or an error, if any.
func (*Transform) Callbacks ¶ added in v0.0.17
Callbacks returns the callbacks associated with the chain.
func (*Transform) OutputKeys ¶ added in v0.0.17
OutputKeys returns the output keys the chain will return.
type TransformFunc ¶ added in v0.0.6
type TransformFunc func(ctx context.Context, inputs schema.ChainValues, optFns ...func(o *schema.CallOptions)) (schema.ChainValues, error)
type TransformOptions ¶ added in v0.0.17
type TransformOptions struct {
*schema.CallbackOptions
}