chain

package
v0.0.47 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2023 License: MIT Imports: 15 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var (
	ErrNoInputValues        = errors.New("no input values")
	ErrInvalidInputValues   = errors.New("invalid input values")
	ErrInputValuesWrongType = errors.New("input key is of wrong type")
	ErrNoOutputParser       = errors.New("no output parser")
)

Functions

func IsChatModel added in v0.0.14

func IsChatModel(model schema.Model) bool

IsChatModel checks if the given model is of type schema.ChatModel.

func IsLLM added in v0.0.14

func IsLLM(model schema.Model) bool

IsLLM checks if the given model is of type schema.LLM.

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

type ConditionalFunc func(model schema.Model) bool

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 NewLLM added in v0.0.16

func NewLLM(llm schema.Model, prompt *prompt.Template, optFns ...func(o *LLMOptions)) (*LLM, error)

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) Callbacks added in v0.0.16

func (c *LLM) Callbacks() []schema.Callback

Callbacks returns the callbacks associated with the chain.

func (*LLM) GetNumTokens added in v0.0.39

func (c *LLM) GetNumTokens(text string) (uint, error)

func (*LLM) InputKeys added in v0.0.16

func (c *LLM) InputKeys() []string

InputKeys returns the expected input keys.

func (*LLM) Memory added in v0.0.16

func (c *LLM) Memory() schema.Memory

Memory returns the memory associated with the chain.

func (*LLM) OutputKeys added in v0.0.16

func (c *LLM) OutputKeys() []string

OutputKeys returns the output keys the chain will return.

func (*LLM) Prompt added in v0.0.16

func (c *LLM) Prompt() *prompt.Template

func (*LLM) Type added in v0.0.16

func (c *LLM) Type() string

Type returns the type of the chain.

func (*LLM) Verbose added in v0.0.16

func (c *LLM) Verbose() bool

Verbose returns the verbosity setting of the chain.

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) Callbacks added in v0.0.13

func (c *LLMBash) Callbacks() []schema.Callback

Callbacks returns the callbacks associated chain.

func (*LLMBash) InputKeys added in v0.0.11

func (c *LLMBash) InputKeys() []string

InputKeys returns the expected input keys.

func (*LLMBash) Memory added in v0.0.13

func (c *LLMBash) Memory() schema.Memory

Memory returns the memory associated with the chain.

func (*LLMBash) OutputKeys added in v0.0.11

func (c *LLMBash) OutputKeys() []string

OutputKeys returns the output keys the chain will return.

func (*LLMBash) Type added in v0.0.13

func (c *LLMBash) Type() string

Type returns the type of the chain.

func (*LLMBash) Verbose added in v0.0.13

func (c *LLMBash) Verbose() bool

Verbose returns the verbosity setting of the chain.

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

func (c *LLMMath) Callbacks() []schema.Callback

Callbacks returns the callbacks associated with the chain.

func (*LLMMath) InputKeys added in v0.0.11

func (c *LLMMath) InputKeys() []string

InputKeys returns the expected input keys.

func (*LLMMath) Memory added in v0.0.13

func (c *LLMMath) Memory() schema.Memory

Memory returns the memory associated with the chain.

func (*LLMMath) OutputKeys added in v0.0.11

func (c *LLMMath) OutputKeys() []string

OutputKeys returns the output keys the chain will return.

func (*LLMMath) Type added in v0.0.13

func (c *LLMMath) Type() string

Type returns the type of the chain.

func (*LLMMath) Verbose added in v0.0.13

func (c *LLMMath) Verbose() bool

Verbose returns the verbosity setting of the chain.

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 OpenAIClient interface {
	Moderations(ctx context.Context, request openai.ModerationRequest) (response openai.ModerationResponse, err error)
}

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

type PromptSelector interface {
	GetPrompt(model schema.Model) *prompt.Template
}

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 SequentialOptions struct {
	*schema.CallbackOptions
	Memory     schema.Memory
	OutputKeys []string
	ReturnAll  bool
}

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 SimpleSequentialOptions struct {
	*schema.CallbackOptions
	Memory       schema.Memory
	InputKey     string
	OutputKey    string
	StripOutputs bool
}

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

func (c *Transform) Callbacks() []schema.Callback

Callbacks returns the callbacks associated with the chain.

func (*Transform) InputKeys added in v0.0.17

func (c *Transform) InputKeys() []string

InputKeys returns the expected input keys.

func (*Transform) Memory added in v0.0.17

func (c *Transform) Memory() schema.Memory

Memory returns the memory associated with the chain.

func (*Transform) OutputKeys added in v0.0.17

func (c *Transform) OutputKeys() []string

OutputKeys returns the output keys the chain will return.

func (*Transform) Type added in v0.0.17

func (c *Transform) Type() string

Type returns the type of the chain.

func (*Transform) Verbose added in v0.0.17

func (c *Transform) Verbose() bool

Verbose returns the verbosity setting of the chain.

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
}

Jump to

Keyboard shortcuts

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