chain

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

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

type ConversationalRetrieval struct {
	// contains filtered or unexported fields
}

ConversationalRetrieval is a chain implementation for conversational retrieval.

func NewConversationalRetrieval added in v0.0.16

func NewConversationalRetrieval(llm schema.LLM, retriever schema.Retriever, optFns ...func(o *ConversationalRetrievalOptions)) (*ConversationalRetrieval, error)

NewConversationalRetrieval creates a new instance of the ConversationalRetrieval chain.

func (ConversationalRetrieval) Call added in v0.0.16

Call executes the ConversationalRetrieval chain with the given context and inputs. It returns the outputs of the chain or an error, if any.

func (ConversationalRetrieval) Callbacks added in v0.0.16

func (c ConversationalRetrieval) Callbacks() []schema.Callback

Callbacks returns the callbacks associated with the chain.

func (ConversationalRetrieval) InputKeys added in v0.0.16

func (c ConversationalRetrieval) InputKeys() []string

InputKeys returns the expected input keys.

func (ConversationalRetrieval) Memory added in v0.0.16

Memory returns the memory associated with the chain.

func (ConversationalRetrieval) OutputKeys added in v0.0.16

func (c ConversationalRetrieval) OutputKeys() []string

OutputKeys returns the output keys the chain will return.

func (ConversationalRetrieval) Type added in v0.0.16

Type returns the type of the chain.

func (ConversationalRetrieval) Verbose added in v0.0.16

func (c ConversationalRetrieval) Verbose() bool

Verbose returns the verbosity setting of the chain.

type ConversationalRetrievalOptions added in v0.0.16

type ConversationalRetrievalOptions struct {
	*schema.CallbackOptions
	ReturnSourceDocuments   bool
	ReturnGeneratedQuestion bool
	CondenseQuestionPrompt  *prompt.Template
	StuffQAPrompt           *prompt.Template
	Memory                  schema.Memory
	InputKey                string
	OutputKey               string
}

ConversationalRetrievalOptions represents the options for the ConversationalRetrieval chain.

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.LLM, 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) 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 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 RefineDocuments added in v0.0.13

type RefineDocuments struct {
	// contains filtered or unexported fields
}

func NewRefineDocuments added in v0.0.13

func NewRefineDocuments(llmChain *LLM, refineLLMChain *LLM, optFns ...func(o *RefineDocumentsOptions)) (*RefineDocuments, error)

func NewRefineSummarization added in v0.0.13

func NewRefineSummarization(llm schema.LLM, optFns ...func(o *RefineSummarizationOptions)) (*RefineDocuments, error)

func (*RefineDocuments) Call added in v0.0.13

func (c *RefineDocuments) 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 (*RefineDocuments) Callbacks added in v0.0.13

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

Callbacks returns the callbacks associated with the chain.

func (*RefineDocuments) InputKeys added in v0.0.13

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

InputKeys returns the expected input keys.

func (*RefineDocuments) Memory added in v0.0.13

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

Memory returns the memory associated with the chain.

func (*RefineDocuments) OutputKeys added in v0.0.13

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

OutputKeys returns the output keys the chain will return.

func (*RefineDocuments) Type added in v0.0.13

func (c *RefineDocuments) Type() string

Type returns the type of the chain.

func (*RefineDocuments) Verbose added in v0.0.13

func (c *RefineDocuments) Verbose() bool

Verbose returns the verbosity setting of the chain.

type RefineDocumentsOptions

type RefineDocumentsOptions struct {
	*schema.CallbackOptions
	InputKey             string
	DocumentVariableName string
	InitialResponseName  string
	DocumentPrompt       *prompt.Template
	OutputKey            string
}

type RefineSummarizationOptions added in v0.0.13

type RefineSummarizationOptions struct {
	*schema.CallbackOptions
}

type RetrievalQA added in v0.0.2

type RetrievalQA struct {
	// contains filtered or unexported fields
}

func NewRetrievalQA added in v0.0.2

func NewRetrievalQA(llm schema.LLM, retriever schema.Retriever, optFns ...func(o *RetrievalQAOptions)) (*RetrievalQA, error)

func (*RetrievalQA) Call added in v0.0.2

func (c *RetrievalQA) 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 (*RetrievalQA) Callbacks added in v0.0.13

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

Callbacks returns the callbacks associated with the chain.

func (*RetrievalQA) InputKeys added in v0.0.2

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

InputKeys returns the expected input keys.

func (*RetrievalQA) Memory added in v0.0.13

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

Memory returns the memory associated with the chain.

func (*RetrievalQA) OutputKeys added in v0.0.2

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

OutputKeys returns the output keys the chain will return.

func (*RetrievalQA) Type added in v0.0.13

func (c *RetrievalQA) Type() string

Type returns the type of the chain.

func (*RetrievalQA) Verbose added in v0.0.13

func (c *RetrievalQA) Verbose() bool

Verbose returns the verbosity setting of the chain.

type RetrievalQAOptions added in v0.0.2

type RetrievalQAOptions struct {
	*schema.CallbackOptions
	StuffQAPrompt         *prompt.Template
	InputKey              string
	ReturnSourceDocuments bool
}

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

type StuffDocuments struct {
	// contains filtered or unexported fields
}

func NewStuffDocuments added in v0.0.13

func NewStuffDocuments(llmChain *LLM, optFns ...func(o *StuffDocumentsOptions)) (*StuffDocuments, error)

func NewStuffSummarization added in v0.0.13

func NewStuffSummarization(llm schema.LLM, optFns ...func(o *StuffSummarizationOptions)) (*StuffDocuments, error)

func (*StuffDocuments) Call added in v0.0.13

func (c *StuffDocuments) 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 (*StuffDocuments) Callbacks added in v0.0.13

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

Callbacks returns the callbacks associated with the chain.

func (*StuffDocuments) InputKeys added in v0.0.13

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

InputKeys returns the expected input keys.

func (*StuffDocuments) Memory added in v0.0.13

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

Memory returns the memory associated with the chain.

func (*StuffDocuments) OutputKeys added in v0.0.13

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

OutputKeys returns the output keys the chain will return.

func (*StuffDocuments) Type added in v0.0.13

func (c *StuffDocuments) Type() string

Type returns the type of the chain.

func (*StuffDocuments) Verbose added in v0.0.13

func (c *StuffDocuments) Verbose() bool

Verbose returns the verbosity setting of the chain.

type StuffDocumentsOptions

type StuffDocumentsOptions struct {
	*schema.CallbackOptions
	InputKey             string
	DocumentVariableName string
	Separator            string
}

type StuffSummarizationOptions added in v0.0.13

type StuffSummarizationOptions struct {
	*schema.CallbackOptions
}

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