Documentation ¶
Overview ¶
Package chains contains a standard interface for chains, a number of built-in chains and functions for calling and running chains.
Index ¶
- Variables
- func Apply(ctx context.Context, c Chain, inputValues []map[string]any, maxWorkers int, ...) ([]map[string]any, error)
- func Call(ctx context.Context, c Chain, inputValues map[string]any, ...) (map[string]any, error)
- func GetLLMCallOptions(options ...ChainCallOption) []llms.CallOption
- func Predict(ctx context.Context, c Chain, inputValues map[string]any, ...) (string, error)
- func Run(ctx context.Context, c Chain, input any, options ...ChainCallOption) (string, error)
- type APIChain
- type Chain
- type ChainCallOption
- func WithCallback(callbackHandler callbacks.Handler) ChainCallOption
- func WithMaxLength(maxLength int) ChainCallOption
- func WithMaxTokens(maxTokens int) ChainCallOption
- func WithMinLength(minLength int) ChainCallOption
- func WithModel(model string) ChainCallOption
- func WithRepetitionPenalty(repetitionPenalty float64) ChainCallOption
- func WithSeed(seed int) ChainCallOption
- func WithStopWords(stopWords []string) ChainCallOption
- func WithStreamingFunc(streamingFunc func(ctx context.Context, chunk []byte) error) ChainCallOption
- func WithTemperature(temperature float64) ChainCallOption
- func WithTopK(topK int) ChainCallOption
- func WithTopP(topP float64) ChainCallOption
- type ConditionalPromptSelector
- type Constitutional
- type ConstitutionalExample
- type ConstitutionalPrinciple
- type ConversationalRetrievalQA
- func (c ConversationalRetrievalQA) Call(ctx context.Context, values map[string]any, options ...ChainCallOption) (map[string]any, error)
- func (c ConversationalRetrievalQA) GetInputKeys() []string
- func (c ConversationalRetrievalQA) GetMemory() schema.Memory
- func (c ConversationalRetrievalQA) GetOutputKeys() []string
- type HTTPRequest
- type LLMChain
- func (c LLMChain) Call(ctx context.Context, values map[string]any, options ...ChainCallOption) (map[string]any, error)
- func (c LLMChain) GetCallbackHandler() callbacks.Handler
- func (c LLMChain) GetInputKeys() []string
- func (c LLMChain) GetMemory() schema.Memory
- func (c LLMChain) GetOutputKeys() []string
- type LLMMathChain
- type MapReduceDocuments
- type MapRerankDocuments
- type Pair
- type PromptSelector
- type RefineDocuments
- type RetrievalQA
- type SQLDatabaseChain
- type SequentialChain
- type SequentialChainOption
- type SimpleSequentialChain
- func (c *SimpleSequentialChain) Call(ctx context.Context, inputs map[string]any, options ...ChainCallOption) (map[string]any, error)
- func (c *SimpleSequentialChain) GetInputKeys() []string
- func (c *SimpleSequentialChain) GetMemory() schema.Memory
- func (c *SimpleSequentialChain) GetOutputKeys() []string
- type StuffDocuments
- type Transform
- type TransformFunc
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("result not found") ErrConvert = errors.New("cannot convert to string") )
var ( // ErrInvalidInputValues is returned if the input values to a chain is invalid. ErrInvalidInputValues = errors.New("invalid input values") // ErrMissingInputValues is returned when some expected input values keys to // a chain is missing. ErrMissingInputValues = errors.New("missing key in input values") // ErrInputValuesWrongType is returned if an input value to a chain is of // wrong type. ErrInputValuesWrongType = errors.New("input key is of wrong type") // ErrMissingMemoryKeyValues is returned when some expected input values keys to // a chain is missing. ErrMissingMemoryKeyValues = errors.New("missing memory key in input values") // ErrMemoryValuesWrongType is returned if the memory value to a chain is of // wrong type. ErrMemoryValuesWrongType = errors.New("memory key is of wrong type") // ErrInvalidOutputValues is returned when expected output keys to a chain does // not match the actual keys in the return output values map. ErrInvalidOutputValues = errors.New("missing key in output values") // ErrMultipleInputsInRun is returned in the run function if the chain expects // more then one input values. ErrMultipleInputsInRun = errors.New("run not supported in chain with more then one expected input") // ErrMultipleOutputsInRun is returned in the run function if the chain expects // more then one output values. ErrMultipleOutputsInRun = errors.New("run not supported in chain with more then one expected output") // ErrWrongOutputTypeInRun is returned in the run function if the chain returns // a value that is not a string. ErrWrongOutputTypeInRun = errors.New("run not supported in chain that returns value that is not string") // ErrOutputNotStringInPredict is returned if a chain does not return a string // in the predict function. ErrOutputNotStringInPredict = errors.New("predict is not supported with a chain that does not return a string") // ErrMultipleOutputsInPredict is returned if a chain has multiple return values // in predict. ErrMultipleOutputsInPredict = errors.New("predict is not supported with a chain that returns multiple values") // ErrChainInitialization is returned if a chain is not initialized appropriately. ErrChainInitialization = errors.New("error initializing chain") )
var ( ErrInvalidInputNumberInSimpleSeq = errors.New("single input expected for chains supplied to SimpleSequentialChain") ErrInvalidOutputNumberInSimpleSeq = errors.New("single output expected for chains supplied to SimpleSequentialChain") )
Functions ¶
func Apply ¶
func Apply(ctx context.Context, c Chain, inputValues []map[string]any, maxWorkers int, options ...ChainCallOption) ([]map[string]any, error)
Apply executes the chain for each of the inputs asynchronously.
func Call ¶
func Call(ctx context.Context, c Chain, inputValues map[string]any, options ...ChainCallOption) (map[string]any, error)
Call is the standard function used for executing chains.
func GetLLMCallOptions ¶ added in v0.1.10
func GetLLMCallOptions(options ...ChainCallOption) []llms.CallOption
Types ¶
type APIChain ¶
type APIChain struct { RequestChain *LLMChain AnswerChain *LLMChain Request HTTPRequest }
func NewAPIChain ¶
func NewAPIChain(llm llms.Model, request HTTPRequest) APIChain
NewAPIChain creates a new APIChain object.
It takes a language model (llm) and an HTTPRequest (request) as parameters. It returns an APIChain object.
func (APIChain) Call ¶
func (a APIChain) Call(ctx context.Context, values map[string]any, opts ...ChainCallOption) (map[string]any, error)
Call executes the APIChain and returns the result.
It takes a context.Context object, a map[string]any values, and optional ChainCallOption values as input parameters. It returns a map[string]any and an error as output.
func (APIChain) GetInputKeys ¶
GetInputKeys returns the input keys of the APIChain.
No parameters. Returns a slice of strings, which contains the output keys.
func (APIChain) GetMemory ¶
GetMemory returns the memory of the APIChain.
This function does not take any parameters. It returns a schema.Memory object.
func (APIChain) GetOutputKeys ¶
GetOutputKeys returns the output keys of the APIChain.
It does not take any parameters. It returns a slice of strings, which contains the output keys.
type Chain ¶
type Chain interface { // Call runs the logic of the chain and returns the output. This method should // not be called directly. Use rather the Call, Run or Predict functions that // handles the memory and other aspects of the chain. Call(ctx context.Context, inputs map[string]any, options ...ChainCallOption) (map[string]any, error) // GetMemory gets the memory of the chain. GetMemory() schema.Memory // GetInputKeys returns the input keys the chain expects. GetInputKeys() []string // GetOutputKeys returns the output keys the chain returns. GetOutputKeys() []string }
Chain is the interface all chains must implement.
type ChainCallOption ¶
type ChainCallOption func(*chainCallOption)
ChainCallOption is a function that can be used to modify the behavior of the Call function.
func WithCallback ¶ added in v0.1.8
func WithCallback(callbackHandler callbacks.Handler) ChainCallOption
WithCallback allows setting a custom Callback Handler.
func WithMaxLength ¶
func WithMaxLength(maxLength int) ChainCallOption
WithMaxLength will add an option to set the maximum length of the generated text for LLM.Call.
func WithMaxTokens ¶
func WithMaxTokens(maxTokens int) ChainCallOption
WithMaxTokens is an option for LLM.Call.
func WithMinLength ¶
func WithMinLength(minLength int) ChainCallOption
WithMinLength will add an option to set the minimum length of the generated text for LLM.Call.
func WithRepetitionPenalty ¶
func WithRepetitionPenalty(repetitionPenalty float64) ChainCallOption
WithRepetitionPenalty will add an option to set the repetition penalty for sampling.
func WithSeed ¶
func WithSeed(seed int) ChainCallOption
WithSeed will add an option to use deterministic sampling for LLM.Call.
func WithStopWords ¶
func WithStopWords(stopWords []string) ChainCallOption
WithStopWords is an option for setting the stop words for LLM.Call.
func WithStreamingFunc ¶
func WithStreamingFunc(streamingFunc func(ctx context.Context, chunk []byte) error) ChainCallOption
WithStreamingFunc is an option for LLM.Call that allows streaming responses.
func WithTemperature ¶
func WithTemperature(temperature float64) ChainCallOption
WithTemperature is an option for LLM.Call.
func WithTopK ¶
func WithTopK(topK int) ChainCallOption
WithTopK will add an option to use top-k sampling for LLM.Call.
func WithTopP ¶
func WithTopP(topP float64) ChainCallOption
WithTopP will add an option to use top-p sampling for LLM.Call.
type ConditionalPromptSelector ¶
type ConditionalPromptSelector struct { DefaultPrompt prompts.PromptTemplate Conditionals []struct { Condition func(llms.Model) bool Prompt prompts.PromptTemplate } }
ConditionalPromptSelector is a formatter selector that selects a prompt depending on conditionals.
func (ConditionalPromptSelector) GetPrompt ¶
func (s ConditionalPromptSelector) GetPrompt(llm llms.Model) prompts.PromptTemplate
type Constitutional ¶
type Constitutional struct {
// contains filtered or unexported fields
}
func NewConstitutional ¶
func NewConstitutional(llm llms.Model, chain LLMChain, constitutionalPrinciples []ConstitutionalPrinciple, options map[string]*prompts.FewShotPrompt, ) *Constitutional
NewConstitutional creates a new Constitutional chain.
func (*Constitutional) Call ¶
func (c *Constitutional) Call(ctx context.Context, inputs map[string]any, options ...ChainCallOption) (map[string]any, error, )
Call handles the inner logic of the Constitutional chain.
func (*Constitutional) GetInputKeys ¶
func (c *Constitutional) GetInputKeys() []string
func (*Constitutional) GetMemory ¶
func (c *Constitutional) GetMemory() schema.Memory
func (*Constitutional) GetOutputKeys ¶
func (c *Constitutional) GetOutputKeys() []string
type ConstitutionalExample ¶
type ConstitutionalExample struct {
// contains filtered or unexported fields
}
type ConstitutionalPrinciple ¶
type ConstitutionalPrinciple struct {
// contains filtered or unexported fields
}
func NewConstitutionalPrinciple ¶
func NewConstitutionalPrinciple(critique, revision string, names ...string) ConstitutionalPrinciple
NewConstitutionalPrinciple creates a new ConstitutionalPrinciple.
type ConversationalRetrievalQA ¶
type ConversationalRetrievalQA struct { // Retriever used to retrieve the relevant documents. Retriever schema.Retriever // Memory that remembers previous conversational back and forths directly. Memory schema.Memory // CombineDocumentsChain The chain used to combine any retrieved documents. CombineDocumentsChain Chain // CondenseQuestionChain The chain the documents and query is given to. // The chain used to generate a new question for the sake of retrieval. // This chain will take in the current question (with variable `question`) // and any chat history (with variable `chat_history`) and will produce // a new standalone question to be used later on. CondenseQuestionChain Chain // OutputKey The output key to return the final answer of this chain in. OutputKey string // RephraseQuestion Whether to pass the new generated question to the CombineDocumentsChain. // If true, will pass the new generated question along. // If false, will only use the new generated question for retrieval and pass the // original question along to the CombineDocumentsChain. RephraseQuestion bool // ReturnGeneratedQuestion Return the generated question as part of the final result. ReturnGeneratedQuestion bool // InputKey The input key to get the query from, by default "query". InputKey string // ReturnSourceDocuments Return the retrieved source documents as part of the final result. ReturnSourceDocuments bool }
ConversationalRetrievalQA chain builds on RetrievalQA to provide a chat history component.
func NewConversationalRetrievalQA ¶
func NewConversationalRetrievalQA( combineDocumentsChain Chain, condenseQuestionChain Chain, retriever schema.Retriever, memory schema.Memory, ) ConversationalRetrievalQA
NewConversationalRetrievalQA creates a new NewConversationalRetrievalQA.
func (ConversationalRetrievalQA) Call ¶
func (c ConversationalRetrievalQA) Call(ctx context.Context, values map[string]any, options ...ChainCallOption) (map[string]any, error)
Call gets question, and relevant documents by question from the retriever and gives them to the combine documents chain.
func (ConversationalRetrievalQA) GetInputKeys ¶
func (c ConversationalRetrievalQA) GetInputKeys() []string
func (ConversationalRetrievalQA) GetMemory ¶
func (c ConversationalRetrievalQA) GetMemory() schema.Memory
func (ConversationalRetrievalQA) GetOutputKeys ¶
func (c ConversationalRetrievalQA) GetOutputKeys() []string
type HTTPRequest ¶
HTTPRequest http requester interface.
type LLMChain ¶
type LLMChain struct { Prompt prompts.FormatPrompter LLM llms.Model Memory schema.Memory CallbacksHandler callbacks.Handler OutputParser schema.OutputParser[any] OutputKey string }
func LoadCondenseQuestionGenerator ¶
LoadCondenseQuestionGenerator chain is used to generate a new question for the sake of retrieval.
func NewLLMChain ¶
func NewLLMChain(llm llms.Model, prompt prompts.FormatPrompter, opts ...ChainCallOption) *LLMChain
NewLLMChain creates a new LLMChain with an LLM and a prompt.
func (LLMChain) Call ¶
func (c LLMChain) Call(ctx context.Context, values map[string]any, options ...ChainCallOption) (map[string]any, error)
Call formats the prompts with the input values, generates using the llm, and parses the output from the llm with the output parser. This function should not be called directly, use rather the Call or Run function if the prompt only requires one input value.
func (LLMChain) GetCallbackHandler ¶
func (LLMChain) GetInputKeys ¶
GetInputKeys returns the expected input keys.
func (LLMChain) GetOutputKeys ¶
GetOutputKeys returns the output keys the chain will return.
type LLMMathChain ¶
type LLMMathChain struct {
LLMChain *LLMChain
}
LLMMathChain is a chain used for evaluating math expressions.
func NewLLMMathChain ¶
func NewLLMMathChain(llm llms.Model) LLMMathChain
func (LLMMathChain) Call ¶
func (c LLMMathChain) Call(ctx context.Context, values map[string]any, options ...ChainCallOption) (map[string]any, error)
Call runs the logic of the LLM Math chain and returns the output.
func (LLMMathChain) GetInputKeys ¶
func (c LLMMathChain) GetInputKeys() []string
func (LLMMathChain) GetMemory ¶
func (c LLMMathChain) GetMemory() schema.Memory
func (LLMMathChain) GetOutputKeys ¶
func (c LLMMathChain) GetOutputKeys() []string
type MapReduceDocuments ¶
type MapReduceDocuments struct { // The chain to apply to each documents individually. LLMChain *LLMChain // The chain to combine the mapped results of the LLMChain. ReduceChain Chain // The memory of the chain. Memory schema.Memory // The variable name of where to put the results from the LLMChain into the collapse chain. // Only needed if the reduce chain has more then one expected input. ReduceDocumentVariableName string // The input variable where the documents should be placed int the LLMChain. Only needed if // the reduce chain has more then one expected input. LLMChainInputVariableName string // MaxNumberOfConcurrent represents the max number of concurrent calls done simultaneously to // the llm chain. MaxNumberOfConcurrent int // The input key where the documents to be combined should be. InputKey string // Whether to add the intermediate steps to the output. ReturnIntermediateSteps bool }
MapReduceDocuments is a chain that combines documents by mapping a chain over them, then combining the results using another chain.
func LoadMapReduceQA ¶
func LoadMapReduceQA(llm llms.Model) MapReduceDocuments
LoadMapReduceQA loads a refine documents chain for question answering. Inputs are "question" and "input_documents".
func LoadMapReduceSummarization ¶
func LoadMapReduceSummarization(llm llms.Model) MapReduceDocuments
LoadMapReduceSummarization loads a map reduce documents chain for summarization of documents.
func NewMapReduceDocuments ¶
func NewMapReduceDocuments(llmChain *LLMChain, reduceChain Chain) MapReduceDocuments
NewMapReduceDocuments creates a new map reduce documents chain with some default values.
func (MapReduceDocuments) Call ¶
func (c MapReduceDocuments) Call(ctx context.Context, values map[string]any, options ...ChainCallOption) (map[string]any, error)
Call handles the inner logic of the MapReduceDocuments documents chain.
func (MapReduceDocuments) GetInputKeys ¶
func (c MapReduceDocuments) GetInputKeys() []string
func (MapReduceDocuments) GetMemory ¶
func (c MapReduceDocuments) GetMemory() schema.Memory
func (MapReduceDocuments) GetOutputKeys ¶
func (c MapReduceDocuments) GetOutputKeys() []string
type MapRerankDocuments ¶
type MapRerankDocuments struct { // Chain used to rerank the documents. LLMChain *LLMChain // Number of workers to concurrently run apply on documents. MaxConcurrentWorkers int // The input variable where the documents should be placed int the LLMChain. LLMChainInputVariableName string // The name of the document variable in the LLMChain. DocumentVariableName string // Key used to access document inputs. InputKey string // Key used to access map results. OutputKey string // Key used for comparison to sort documents. RankKey string // Key used to return the answer. AnswerKey string // When true, the intermediate steps of the map rerank are returned. ReturnIntermediateSteps bool }
func LoadMapRerankQA ¶
func LoadMapRerankQA(llm llms.Model) MapRerankDocuments
LoadMapRerankQA loads a map rerank documents chain for question answering. Inputs are "question" and "input_documents".
func NewMapRerankDocuments ¶
func NewMapRerankDocuments(mapRerankLLMChain *LLMChain) *MapRerankDocuments
NewMapRerankDocuments creates a new map rerank documents chain.
func (MapRerankDocuments) Call ¶
func (c MapRerankDocuments) Call(ctx context.Context, values map[string]any, options ...ChainCallOption) (map[string]any, error)
Call handles the inner logic of the MapRerankDocuments chain.
func (MapRerankDocuments) GetInputKeys ¶
func (c MapRerankDocuments) GetInputKeys() []string
GetInputKeys returns the input keys for the MapRerankDocuments chain.
func (MapRerankDocuments) GetMemory ¶
func (c MapRerankDocuments) GetMemory() schema.Memory
GetMemory returns the memory for the MapRerankDocuments chain.
func (MapRerankDocuments) GetOutputKeys ¶
func (c MapRerankDocuments) GetOutputKeys() []string
GetOutputKeys returns the output keys for the MapRerankDocuments chain.
type PromptSelector ¶
type PromptSelector interface {
GetPrompt(llm llms.Model) prompts.PromptTemplate
}
PromptSelector is the interface for selecting a formatter depending on the LLM given.
type RefineDocuments ¶
type RefineDocuments struct { // Chain used to construct the first text using the first document. LLMChain *LLMChain // Chain used to refine the first text using the additional documents. RefineLLMChain *LLMChain // Prompt to format the documents. Documents are given in the variable // with the name "page_content". All metadata from the documents are // also given to the prompt template. DocumentPrompt prompts.PromptTemplate InputKey string OutputKey string DocumentVariableName string InitialResponseName string }
RefineDocuments is a chain used for combining and processing unstructured text data. The chain iterates over the documents one by one to update a running answer, at each turn using the previous version of the answer and the next document as context.
func LoadRefineQA ¶
func LoadRefineQA(llm llms.Model) RefineDocuments
LoadRefineQA loads a refine documents chain for question answering. Inputs are "question" and "input_documents".
func LoadRefineSummarization ¶
func LoadRefineSummarization(llm llms.Model) RefineDocuments
LoadRefineSummarization loads a refine documents chain for summarization of documents.
func NewRefineDocuments ¶
func NewRefineDocuments(initialLLMChain, refineLLMChain *LLMChain) RefineDocuments
NewRefineDocuments creates a new refine documents chain from the llm chain used to construct the initial text and the llm used to refine the text.
func (RefineDocuments) Call ¶
func (c RefineDocuments) Call(ctx context.Context, values map[string]any, options ...ChainCallOption) (map[string]any, error)
Call handles the inner logic of the refine documents chain.
func (RefineDocuments) GetInputKeys ¶
func (c RefineDocuments) GetInputKeys() []string
func (RefineDocuments) GetMemory ¶
func (c RefineDocuments) GetMemory() schema.Memory
func (RefineDocuments) GetOutputKeys ¶
func (c RefineDocuments) GetOutputKeys() []string
type RetrievalQA ¶
type RetrievalQA struct { // Retriever used to retrieve the relevant documents. Retriever schema.Retriever // The chain the documents and query is given to. CombineDocumentsChain Chain // The input key to get the query from, by default "query". InputKey string // If the chain should return the documents used by the combine // documents chain in the "source_documents" key. ReturnSourceDocuments bool }
RetrievalQA is a chain used for question-answering against a retriever. First the chain gets documents from the retriever, then the documents and the query is used as input to another chain. Typically, that chain combines the documents into a prompt that is sent to an LLM.
func NewRetrievalQA ¶
func NewRetrievalQA(combineDocumentsChain Chain, retriever schema.Retriever) RetrievalQA
NewRetrievalQA creates a new RetrievalQA from a retriever and a chain for combining documents. The chain for combining documents is expected to have the expected input values for the "question" and "input_documents" key.
func NewRetrievalQAFromLLM ¶
func NewRetrievalQAFromLLM(llm llms.Model, retriever schema.Retriever) RetrievalQA
NewRetrievalQAFromLLM loads a question answering combine documents chain from the llm and creates a new retrievalQA chain.
func (RetrievalQA) Call ¶
func (c RetrievalQA) Call(ctx context.Context, values map[string]any, options ...ChainCallOption) (map[string]any, error)
Call gets relevant documents from the retriever and gives them to the combine documents chain.
func (RetrievalQA) GetInputKeys ¶
func (c RetrievalQA) GetInputKeys() []string
func (RetrievalQA) GetMemory ¶
func (c RetrievalQA) GetMemory() schema.Memory
func (RetrievalQA) GetOutputKeys ¶
func (c RetrievalQA) GetOutputKeys() []string
type SQLDatabaseChain ¶
type SQLDatabaseChain struct { LLMChain *LLMChain TopK int Database *sqldatabase.SQLDatabase OutputKey string }
SQLDatabaseChain is a chain used for interacting with SQL Database.
func NewSQLDatabaseChain ¶
func NewSQLDatabaseChain(llm llms.Model, topK int, database *sqldatabase.SQLDatabase) *SQLDatabaseChain
NewSQLDatabaseChain creates a new SQLDatabaseChain. The topK is the max number of results to return.
func (SQLDatabaseChain) Call ¶
func (s SQLDatabaseChain) Call(ctx context.Context, inputs map[string]any, options ...ChainCallOption) (map[string]any, error)
Call calls the chain. Inputs:
"query" : key with the query to run. "table_names_to_use" (optionally): a slice string of the only table names to use(others will be ignored).
Outputs
"result" : with the result of the query.
func (SQLDatabaseChain) GetInputKeys ¶
func (s SQLDatabaseChain) GetInputKeys() []string
func (SQLDatabaseChain) GetMemory ¶
func (s SQLDatabaseChain) GetMemory() schema.Memory
func (SQLDatabaseChain) GetOutputKeys ¶
func (s SQLDatabaseChain) GetOutputKeys() []string
type SequentialChain ¶
type SequentialChain struct {
// contains filtered or unexported fields
}
SequentialChain is a chain that runs multiple chains in sequence, where the output of one chain is the input of the next.
func NewSequentialChain ¶
func NewSequentialChain(chains []Chain, inputKeys []string, outputKeys []string, opts ...SequentialChainOption) (*SequentialChain, error)
func (*SequentialChain) Call ¶
func (c *SequentialChain) Call(ctx context.Context, inputs map[string]any, options ...ChainCallOption) (map[string]any, error)
Call runs the logic of the chains and returns the outputs. This method should not be called directly. Use rather the Call, Run or Predict functions that handles the memory and other aspects of the chain.
func (*SequentialChain) GetInputKeys ¶
func (c *SequentialChain) GetInputKeys() []string
GetInputKeys returns the input keys the chain expects.
func (*SequentialChain) GetMemory ¶
func (c *SequentialChain) GetMemory() schema.Memory
GetMemory gets the memory of the chain.
func (*SequentialChain) GetOutputKeys ¶
func (c *SequentialChain) GetOutputKeys() []string
GetOutputKeys returns the output keys the chain returns.
type SequentialChainOption ¶
type SequentialChainOption func(*SequentialChain)
func WithSeqChainMemory ¶
func WithSeqChainMemory(memory schema.Memory) SequentialChainOption
type SimpleSequentialChain ¶
type SimpleSequentialChain struct {
// contains filtered or unexported fields
}
SimpleSequentialChain is a chain that runs multiple chains in sequence, where the output of one chain is the input of the next. All the chains must have a single input and a single output.
func NewSimpleSequentialChain ¶
func NewSimpleSequentialChain(chains []Chain) (*SimpleSequentialChain, error)
func (*SimpleSequentialChain) Call ¶
func (c *SimpleSequentialChain) Call(ctx context.Context, inputs map[string]any, options ...ChainCallOption) (map[string]any, error)
Call runs the logic of the chains and returns the output. This method should not be called directly. Use the Run function that handles the memory and other aspects of the chain.
func (*SimpleSequentialChain) GetInputKeys ¶
func (c *SimpleSequentialChain) GetInputKeys() []string
GetInputKeys returns the input keys of the first chain.
func (*SimpleSequentialChain) GetMemory ¶
func (c *SimpleSequentialChain) GetMemory() schema.Memory
GetMemory gets the memory of the chain.
func (*SimpleSequentialChain) GetOutputKeys ¶
func (c *SimpleSequentialChain) GetOutputKeys() []string
GetOutputKeys returns the output keys of the last chain.
type StuffDocuments ¶
type StuffDocuments struct { // LLMChain is the LLMChain called after formatting the documents. LLMChain *LLMChain // Input key is the input key the StuffDocuments chain expects the // documents to be in. InputKey string // DocumentVariableName is the variable name used in the llm_chain to put // the documents in. DocumentVariableName string // Separator is the string used to join the documents. Separator string }
StuffDocuments is a chain that combines documents with a separator and uses the stuffed documents in an LLMChain. The input values to the llm chain contains all input values given to this chain, and the stuffed document as a string in the key specified by the "DocumentVariableName" field that is by default set to "context".
func LoadStuffQA ¶
func LoadStuffQA(llm llms.Model) StuffDocuments
LoadStuffQA loads a StuffDocuments chain with default prompts for the llm chain.
func LoadStuffSummarization ¶
func LoadStuffSummarization(llm llms.Model) StuffDocuments
LoadStuffSummarization loads a summarization chain that stuffs all documents given into the prompt.
func NewStuffDocuments ¶
func NewStuffDocuments(llmChain *LLMChain) StuffDocuments
NewStuffDocuments creates a new stuff documents chain with an LLM chain used after formatting the documents.
func (StuffDocuments) Call ¶
func (c StuffDocuments) Call( ctx context.Context, values map[string]any, options ...ChainCallOption, ) (map[string]any, error)
Call handles the inner logic of the StuffDocuments chain.
func (StuffDocuments) GetInputKeys ¶
func (c StuffDocuments) GetInputKeys() []string
GetInputKeys returns the expected input keys, by default "input_documents".
func (StuffDocuments) GetMemory ¶
func (c StuffDocuments) GetMemory() schema.Memory
GetMemory returns a simple memory.
func (StuffDocuments) GetOutputKeys ¶
func (c StuffDocuments) GetOutputKeys() []string
GetOutputKeys returns the output keys the chain will return.
type Transform ¶
type Transform struct { Memory schema.Memory Transform TransformFunc InputKeys []string OutputKeys []string }
Transform is a chain that runs an arbitrary function.
func NewTransform ¶
func NewTransform(f TransformFunc, inputVariables []string, outputVariables []string) Transform
NewTransform creates a new transform chain with the function to use, the expected input and output variables.
func (Transform) Call ¶
func (c Transform) Call(ctx context.Context, inputs map[string]any, options ...ChainCallOption) (map[string]any, error)
Call returns the output of the transform function.
func (Transform) GetInputKeys ¶
GetInputKeys returns the input keys the chain expects.
func (Transform) GetOutputKeys ¶
GetOutputKeys returns the output keys the chain returns.
type TransformFunc ¶
type TransformFunc func(context.Context, map[string]any, ...ChainCallOption) (map[string]any, error)
TransformFunc is the function type that the transform chain uses.
Source Files ¶
- api.go
- chains.go
- constitutional.go
- conversation.go
- conversational_retrieval_qa.go
- doc.go
- errors.go
- llm.go
- llm_math.go
- map_reduce.go
- map_rerank_documents.go
- options.go
- prompt_selector.go
- question_answering.go
- refine_documents.go
- retrieval_qa.go
- sequential.go
- sql_database.go
- stuff_documents.go
- summarization.go
- transform.go