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 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 AttributeInfo
- type Chain
- type ChainCallOption
- func WithMaxLength(maxLength int) ChainCallOption
- func WithMaxTokens(maxTokens int) ChainCallOption
- func WithMinLength(minLength int) ChainCallOption
- func WithModel(model string) ChainCallOption
- func WithOptions(options chainCallOption) 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 Comparator
- type Comparison
- type ConditionalPromptSelector
- 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 ElasticsearchTranslator
- func (t *ElasticsearchTranslator) FormatFunc(funcType interface{}) string
- func (t *ElasticsearchTranslator) ValidateFunc(funcType interface{})
- func (t *ElasticsearchTranslator) VisitComparison(comparison Comparison) map[string]interface{}
- func (t *ElasticsearchTranslator) VisitOperation(operation Operation) map[string]interface{}
- func (t *ElasticsearchTranslator) VisitStructuredQuery(structuredQuery StructuredQuery) (string, map[string]interface{}, int, *Sort)
- type EmbeddingFunc
- type FilterDirective
- 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 Operation
- type Operator
- type OutputParserException
- type PromptSelector
- type RefineDocuments
- type RetrievalQA
- type SQLDatabaseChain
- type SearchFunc
- type SelfQueryRetriever
- 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 Sort
- type StructuredQuery
- type StructuredQueryOutputParser
- type StuffDocuments
- type Transform
- type TransformFunc
Constants ¶
This section is empty.
Variables ¶
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.
Types ¶
type APIChain ¶
type APIChain struct { RequestChain *LLMChain AnswerChain *LLMChain Request HTTPRequest }
func NewAPIChain ¶
func NewAPIChain(llm llms.LanguageModel, request HTTPRequest) APIChain
NewAPIChain creates a new APIChain object.
It takes a LanguageModel(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 AttributeInfo ¶
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 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 WithOptions ¶
func WithOptions(options chainCallOption) ChainCallOption
WithOptions is an option 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 Comparator ¶
type Comparator string
Comparator 表示比较器的类型。
const ( EQ Comparator = "eq" NE Comparator = "ne" GT Comparator = "gt" GTE Comparator = "gte" LT Comparator = "lt" LTE Comparator = "lte" CONTAIN Comparator = "contain" LIKE Comparator = "like" IN Comparator = "in" NIN Comparator = "nin" )
定义比较器常量
type Comparison ¶
type Comparison struct { Comparator Comparator Attribute string Value interface{} }
func (Comparison) Accept ¶
func (c Comparison) Accept(t *ElasticsearchTranslator) interface{}
type ConditionalPromptSelector ¶
type ConditionalPromptSelector struct { DefaultPrompt prompts.PromptTemplate Conditionals []struct { Condition func(llms.LanguageModel) 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.LanguageModel) prompts.PromptTemplate
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 NewConversationalRetrievalQAFromLLM ¶
func NewConversationalRetrievalQAFromLLM( llm llms.LanguageModel, retriever schema.Retriever, memory schema.Memory, ) ConversationalRetrievalQA
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 ElasticsearchTranslator ¶
type ElasticsearchTranslator struct { AllowedComparators []Comparator AllowedOperators []Operator }
func NewElasticsearchTranslator ¶
func NewElasticsearchTranslator() *ElasticsearchTranslator
func (*ElasticsearchTranslator) FormatFunc ¶
func (t *ElasticsearchTranslator) FormatFunc(funcType interface{}) string
func (*ElasticsearchTranslator) ValidateFunc ¶
func (t *ElasticsearchTranslator) ValidateFunc(funcType interface{})
func (*ElasticsearchTranslator) VisitComparison ¶
func (t *ElasticsearchTranslator) VisitComparison(comparison Comparison) map[string]interface{}
func (*ElasticsearchTranslator) VisitOperation ¶
func (t *ElasticsearchTranslator) VisitOperation(operation Operation) map[string]interface{}
func (*ElasticsearchTranslator) VisitStructuredQuery ¶
func (t *ElasticsearchTranslator) VisitStructuredQuery(structuredQuery StructuredQuery) (string, map[string]interface{}, int, *Sort)
type EmbeddingFunc ¶
type FilterDirective ¶
type FilterDirective interface {
Accept(t *ElasticsearchTranslator) interface{}
}
func AstParse ¶
func AstParse(input string) (FilterDirective, error)
type HTTPRequest ¶
HTTPRequest http requester interface.
type LLMChain ¶
type LLMChain struct { Prompt prompts.FormatPrompter LLM llms.LanguageModel Memory schema.Memory CallbacksHandler callbacks.Handler OutputParser schema.OutputParser[any] OutputKey string }
func LoadCondenseQuestionGenerator ¶
func LoadCondenseQuestionGenerator(llm llms.LanguageModel) *LLMChain
LoadCondenseQuestionGenerator chain is used to generate a new question for the sake of retrieval.
func NewConversation ¶
func NewConversation(llm llms.LanguageModel, memory schema.Memory) LLMChain
func NewLLMChain ¶
func NewLLMChain(llm llms.LanguageModel, prompt prompts.FormatPrompter) *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.LanguageModel) LLMMathChain
func (LLMMathChain) Call ¶
func (c LLMMathChain) 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 (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 // Wether or not 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.LanguageModel) MapReduceDocuments
LoadRefineQA loads a refine documents chain for question answering. Inputs are "question" and "input_documents".
func LoadMapReduceSummarization ¶
func LoadMapReduceSummarization(llm llms.LanguageModel) 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.LanguageModel) 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 Operation ¶
type Operation struct { Operator Operator Arguments []FilterDirective }
func (Operation) Accept ¶
func (o Operation) Accept(t *ElasticsearchTranslator) interface{}
type OutputParserException ¶
type OutputParserException struct {
Message string
}
定义 OutputParserException 结构体
func (OutputParserException) Error ¶
func (e OutputParserException) Error() string
type PromptSelector ¶
type PromptSelector interface {
GetPrompt(llms.LanguageModel) 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.LanguageModel) RefineDocuments
LoadRefineQA loads a refine documents chain for question answering. Inputs are "question" and "input_documents".
func LoadRefineSummarization ¶
func LoadRefineSummarization(llm llms.LanguageModel) 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.LanguageModel, 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.LanguageModel, 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 SelfQueryRetriever ¶
type SelfQueryRetriever struct {
// contains filtered or unexported fields
}
func NewSelfQueryRetriever ¶
func NewSelfQueryRetriever(llm *openai.LLM, metadata []AttributeInfo, contentDescription, vectorField string, embeddingFunc EmbeddingFunc, searchFunc SearchFunc, defaultLimit int) SelfQueryRetriever
func (SelfQueryRetriever) GetRelevantDocuments ¶
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
InputKeys 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
OutputKeys 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
InputKeys 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
OutputKeys returns the output keys of the last chain.
type StructuredQuery ¶
type StructuredQuery struct { Query string Filter FilterDirective Limit int Sort *Sort }
定义 StructuredQuery 结构体(请根据您的数据模型进行修改)
type StructuredQueryOutputParser ¶
type StructuredQueryOutputParser struct { }
定义 StructuredQueryOutputParser 结构体
func NewStructuredQueryOutputParser ¶
func NewStructuredQueryOutputParser() StructuredQueryOutputParser
func (StructuredQueryOutputParser) Parse ¶
func (p StructuredQueryOutputParser) Parse(text string) (StructuredQuery, error)
parse 方法用于解析文本数据并返回 StructuredQuery
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.LanguageModel) StuffDocuments
LoadStuffQA loads a StuffDocuments chain with default prompts for the llm chain.
func LoadStuffSummarization ¶
func LoadStuffSummarization(llm llms.LanguageModel) 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 a 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 ¶
InputKeys returns the input keys the chain expects.
func (Transform) GetOutputKeys ¶
OutputKeys 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
- conversation.go
- conversational_retrieval_qa.go
- doc.go
- elasticsearch_translator.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
- self_query.go
- sequential.go
- sql_database.go
- structured_query_output_parser.go
- stuff_documents.go
- summarization.go
- transform.go