langchain library
Build powerful LLM-based Dart/Flutter applications.
Classes
- Agent
- An agent is a component that takes an input and a set of tools and decides what to do to get to the desired output.
- AgentAction
- Agent's action to take.
- AgentExecutor
- A chain responsible for executing the actions of an agent using tools. It receives user input and passes it to the agent, which then decides which tool/s to use and what action/s to take.
- AgentFinish
- Agent's return value.
- AgentPlanInput
- Input to the agent's plan method.
- AgentStep
- A action taken by the agent along with the observation of the action.
- AIChatMessage
- Type of message that is spoken by the AI.
- AIChatMessagePromptTemplate
- A chat message prompt template for a AIChatMessage (ChatMessageType.ai).
- AIChatMessageToolCall
- A tool that the model wants to call.
- BaseActionAgent
- Base class for action agents.
- BaseAgentAction
- Base class for agent actions.
-
BaseChain<
MemoryType extends BaseMemory> - Base class for creating structured sequences of calls to components.
- BaseChatMemory
- Base interface for chat memory.
- BaseChatMessageHistory
- Base interface for chat message history.
-
BaseChatModel<
Options extends ChatModelOptions> - Chat models base class. It should take in chat messages and return a chat message.
- BaseChatPromptTemplate
- Base class for chat prompt templates.
- BaseCombineDocumentsChain
- Base interface for chains combining documents, such as StuffDocumentsChain.
- BaseDocumentLoader
- @{template base_document_loader} Interface for loading documents. @{endtemplate}
- BaseDocumentTransformer
- Base interface for transforming documents.
-
BaseLangChain<
RunInput extends Object, CallOptions extends RunnableOptions, RunOutput extends Object> - Base class for LangChain components (language models, chains, tools, etc.).
- BaseLangChainOptions
- Base options class for LangChain components.
-
BaseLanguageModel<
Input extends Object, Options extends LanguageModelOptions, Output extends LanguageModelResult< Object> > - Base class for all language models.
-
BaseLLM<
Options extends LLMOptions> - Large Language Models base class.
- BaseMemory
- Base interface for memory in chains.
- BaseMultiActionAgent
- Base class for multi action agents.
-
BaseOutputParser<
ParserInput extends Object?, CallOptions extends OutputParserOptions, ParserOutput extends Object?> - Class to parse the output of a Runnable invocation.
- BasePromptSelector
- Base class for a prompt template.
- BasePromptTemplate
- Base class for a prompt template.
- BaseSingleActionAgent
- Base class for single action agents.
-
BaseStore<
K, V> - Abstract interface for a key-value store.
- CacheBackedEmbeddings
- Wrapper around an embedder that caches embeddings in a key-value store to avoid recomputing embeddings for the same text.
- ChainOptions
- Options to pass to the chain.
- CharacterTextSplitter
- Implementation of TextSplitter that looks at characters.
- ChatExample
- An example of a conversation between the end-user and the model.
- ChatMessage
- A message that is part of a chat conversation.
- ChatMessageContent
- The content of a message.
- ChatMessageContentImage
- The content of a message that is an image.
- ChatMessageContentMultiModal
- {@template chat_message_content_multi_modal} The content of a message that is multi-modal. {@endtemplate
- ChatMessageContentText
- The content of a message that is text.
- ChatMessageHistory
- A simple in-memory implementation of a chat message history. Stores messages in an in memory list.
- ChatMessagePromptTemplate
- Base class for all message templates in a ChatPromptTemplate.
- ChatModelOptions
- Generation options to pass into the Chat Model.
- ChatPromptTemplate
- A prompt template for chat models.
- ChatPromptValue
- Prompt value whose value is a list of messages.
- ChatResult
- Result returned by the Chat Model.
- ChatToolChoice
- Controls how the model responds to tool calls.
- ChatToolChoiceAuto
- The model can pick between responding to the end-user or calling a tool.
- ChatToolChoiceForced
- The model is forced to to call the specified tool.
- ChatToolChoiceNone
- The model does not call a tool, and responds to the end-user.
- ChatToolChoiceRequired
- The model must call at least one tool, but doesn’t force a particular tool.
- CodeTextSplitter
- CodeTextSplitter allows you to split source code. It supports multiple languages (see CodeLanguage enum). It tries to split along class definitions, function definitions, and control flow statements.
- ConditionalPromptSelector
- Prompt collection that goes through conditionals to select the appropriate prompt template.
- ConversationBufferMemory
- Buffer for storing a conversation in-memory and then retrieving the messages at a later time.
- ConversationBufferWindowMemory
- ConversationBufferWindowMemory is a type of memory that stores a conversation in chatHistory and then retrieves the last k interactions with the model (i.e. the last k input messages and the last k output messages).
- ConversationChain
- Chain that carries on a conversation, loading context from memory and calling an LLM with it.
-
ConversationSummaryMemory<
LLMType extends BaseLanguageModel< Object, LanguageModelOptions, LanguageModelResult< >Object> > - Memory that summarizes a conversation over time. This is useful for longer conversations where keeping the full message history would take up too many tokens.
-
ConversationTokenBufferMemory<
LLMType extends BaseLanguageModel< Object, LanguageModelOptions, LanguageModelResult< >Object> > - Rolling buffer for storing a conversation and then retrieving the messages at a later time.
- CustomChatMessage
- Chat message with custom role.
- CustomChatMessagePromptTemplate
- A template for a CustomChatMessage (ChatMessageType.custom).
- Document
- Interface for interacting with a document.
- Embeddings
- Interface for embedding models.
- EmbeddingsByteStoreEncoder
- Encoder that transforms values to and from bytes.
-
EncoderBackedStore<
K, V, EK, EV> - Wraps a store with key and value encoders/decoders.
- ExceptionTool
- A tool used when the agent throws an OutputParserException.
- FakeChatModel
- Fake Chat Model for testing. You can pass in a list of responses to return in order when called.
- FakeChatModelOptions
- Fake Echo Chat Model Options for testing.
- FakeEchoChatModel
- Fake Chat Model for testing. It just returns the content of the last message of the prompt or streams it char by char.
- FakeEchoChatModelOptions
- Fake Echo Chat Model Options for testing.
- FakeEchoLLM
- Fake LLM for testing. It just returns the prompt or streams it char by char.
- FakeEmbeddings
- Fake embeddings model for testing.
- FakeHandlerLLM
- Fake LLM for testing. It returns the string returned by the handler function.
- FakeLLM
- Fake LLM for testing. You can pass in a list of responses to return in order when called.
- FakeLLMOptions
- Fake LLM options for testing.
- FakeRetriever
- A retriever that returns a fixed list of documents. This class is meant for testing purposes only.
- FakeTool
- Fake tool for testing. It just returns the input string as is.
- HumanChatMessage
- Type of message that is spoken by the human.
- HumanChatMessagePromptTemplate
- A chat message prompt template for a HumanChatMessage (ChatMessageType.human).
-
InMemoryStore<
K, V> - In-memory implementation of the BaseStore using a dictionary.
-
JsonOutputParser<
ParserInput extends Object?> - Output parser that returns the output of the previous Runnable as a JSON Map.
- LanguageModelOptions
- Options to pass into the language model.
-
LanguageModelResult<
O extends Object> - Result returned by the model.
- LanguageModelUsage
- Usage stats for the generation.
-
LLMChain<
LLMType extends BaseLanguageModel< Object, LanguageModelOptions, LanguageModelResult< , LLMOptions extends LanguageModelOptions, MemoryType extends BaseMemory>Object> > -
NOTE: Chains are the legacy way of using LangChain and will eventually be removed. Use LangChain Expression Language (LCEL) instead, a more flexible and powerful way to combine different components.
- LLMOptions
- Options to pass into the LLM.
- LLMResult
- Result returned by the LLM.
- LocalFileStore
- A simple file system implementation of a BaseStore.
- MapReduceDocumentsChain
- Chain that combines documents by mapping them individually and then reducing the results.
- MemoryVector
- Represents an entry of MemoryVectorStore.
- MemoryVectorStore
- Vector store that stores vectors in memory.
- MessagePlaceholder
- Prompt template that assumes the variable is a ChatMessage (ChatMessageType.messagePlaceholder).
- MessagesPlaceholder
- Prompt template that assumes the variable is a list of ChatMessage (ChatMessageType.messagesPlaceholder).
- OutputParserOptions
- Options to pass to an output parser.
- ParsedToolCall
- A parsed tool call from the model.
- PipelinePromptTemplate
- A prompt template for composing multiple prompts together.
- PromptCondition
- Condition for a prompt.
- PromptTemplate
- A prompt template for a language model.
- PromptValue
- Represents the input to an LLM or Chat model.
- RecursiveCharacterTextSplitter
- Implementation of splitting text that looks at characters. Recursively tries to split by different characters to find one that works.
- ReduceDocumentsChain
- Chain that combines documents by recursively reducing them if needed.
- RetrievalQAChain
- Chain for question-answering against the documents retrieved by the retriever.
-
Retriever<
Options extends RetrieverOptions> - Base Index class. All indexes should extend this class.
- RetrieverOptions
- Base class for Retriever options.
- RetryOptions
-
Options to pass into
retryClient
to control the retry behavior. -
Runnable<
RunInput extends Object?, CallOptions extends RunnableOptions, RunOutput extends Object?> - A Runnable is a generic unit of work that can be invoked, batched, streamed, and/or transformed. It is the basic building block of the LangChain Expression Language (LCEL).
- RunnableAgent
- An agent implemented from a Runnable.
-
RunnableBinding<
RunInput extends Object?, CallOptions extends RunnableOptions, RunOutput extends Object?> -
A RunnableBinding allows you to run a Runnable object with
CallOptions
. -
RunnableFunction<
RunInput extends Object, RunOutput extends Object> - A RunnableFunction allows you to run a Dart function as part of a chain.
-
RunnableMap<
RunInput extends Object> - A RunnableMap allows you to run multiple Runnable objects in parallel on the same input returning a map of the results.
-
RunnableMapInput<
RunInput extends Object, RunOutput extends Object> - A RunnableMapInput allows you to map the input to a different value.
-
RunnableMapInputStream<
RunInput extends Object, RunOutput extends Object> - A RunnableMapInputStream allows you to map the input stream to a different stream of values.
- RunnableOptions
- Options to pass into a runnable.
-
RunnablePassthrough<
RunInput extends Object> - A RunnablePassthrough takes the input it receives and passes it through as output.
-
RunnableRetry<
RunInput extends Object?, RunOutput extends Object?> - A Runnable that automatically retries the operation if it fails.
-
RunnableRouter<
RunInput extends Object, RunOutput extends Object> - A RunnableRouter takes the input it receives and routes it to the runnable returned by the router function.
-
RunnableSequence<
RunInput extends Object?, RunOutput extends Object?> - A RunnableSequence allows you to run multiple Runnable objects sequentially, passing the output of the previous Runnable to the next one.
-
RunnableWithFallback<
RunInput extends Object?, RunOutput extends Object?> - A Runnable that can fallback to other Runnables if it fails.
- SequentialChain
- Chain that combines multiple chains where the output of the one chain is the input of the next chain.
-
SimpleChatModel<
Options extends ChatModelOptions> - SimpleChatModel provides a simplified interface for working with chat models, rather than expecting the user to implement the full SimpleChatModel.invoke method.
-
SimpleLLM<
Options extends LLMOptions> - SimpleLLM provides a simplified interface for working with LLMs. Rather than expecting the user to implement the full SimpleLLM.invoke method, the user only needs to implement SimpleLLM.callInternal.
- SimpleMemory
- Simple memory for storing context or other bits of information that shouldn't ever change between prompts.
- SimpleSequentialChain
- SimpleSequentialChain is a simpler form of SequentialChain, where each step has a singular input/output, and the output of one step is the input to the next.
-
StoreEncoder<
K, V, EK, EV> - Encoder/decoder for keys and values.
- StringMessagePromptTemplate
- Base class for all string message templates in a ChatPromptTemplate.
-
StringOutputParser<
ParserInput extends Object?> -
Output parser that returns the output of the previous Runnable as a
String
. - StringPromptValue
- Prompt value whose value is a string.
-
StringTool<
Options extends ToolOptions> - Base class for tools that accept a single string input and returns a string output.
- StuffDocumentsChain
- Chain that combines documents by stuffing into context.
- StuffDocumentsQAChain
- Stuffs documents with a question answering prompt.
- SummarizeChain
- Chain for summarizing documents.
- SystemChatMessage
- Type of message that is a system message.
- SystemChatMessagePromptTemplate
- A chat message prompt template for a SystemChatMessagePromptTemplate (ChatMessageType.human).
- TextSplitter
- Interface for splitting text into chunks.
-
Tool<
Input extends Object, Options extends ToolOptions, Output extends Object> - A LangChain tool.
- ToolChatMessage
- Type of message that is the response of calling a tool.
- ToolOptions
- Generation options to pass into the Tool.
- ToolsAgent
- An agent powered by the tool calling API.
- ToolsAgentOutputParser
- Parser for ToolsAgent.
- ToolsOutputParser
- A parser that returns the list of tool calls returned by the model.
- ToolSpec
- The specification of a LangChain tool without the actual implementation.
- VectorStore
- Interface for vector stores.
- VectorStoreMemory
- Memory backed by a vector store.
- VectorStoreMMRSearch
- Maximal Marginal Relevance (MMR) search .
-
VectorStoreRetriever<
V extends VectorStore> - A retriever that uses a vector store to retrieve documents.
- VectorStoreRetrieverOptions
- Options for VectorStoreRetriever.
- VectorStoreSearchType
- Vector store search type.
- VectorStoreSimilaritySearch
- Similarity search. Eg. using Cosine similarity.
Enums
- AgentEarlyStoppingMethod
- Method to use for early stopping if the agent never returns AgentFinish.
- ChatMessageContentImageDetail
- Specifies the detail level of the image.
- ChatMessageRole
- Role of a chat message
- ChatMessageType
- The type of a chat message prompt template.
- CodeLanguage
- Supported programming languages for CodeTextSplitter.
- FinishReason
- The reason the model stopped generating tokens.
Extensions
-
ChatMessagesX
on List<
ChatMessage> -
Extensions on
List<ChatMessage>
. -
RunnableX
on Runnable<
RunInput, CallOptions, RunOutput> - Extension methods for Runnables.
Functions
-
calculateSimilarity(
List< double> embedding, List<List< embeddings, {double similarityFunction(List<double> >double> a, List<double> b) = cosineSimilarity}) → List<double> - Calculates the similarity between an embedding and a list of embeddings.
-
cosineSimilarity(
List< double> a, List<double> b) → double - Measures the cosine of the angle between two vectors in a vector space. It ranges from -1 to 1, where 1 represents identical vectors, 0 represents orthogonal vectors, and -1 represents vectors that are diametrically opposed.
-
getIndexesMostSimilarEmbeddings(
List< double> embedding, List<List< embeddings, {double similarityFunction(List<double> >double> a, List<double> b) = cosineSimilarity}) → List<int> -
Returns a sorted list of indexes of
embeddings
that are most similar to the providedembedding
(in descending order, most similar first). -
getPromptInputKey(
MemoryInputValues inputValues, Set< String> memoryKeys) → String - This function is used by memory classes to select the input value to use for the memory.
Typedefs
-
ChainValues
= Map<
String, dynamic> - Values to be used in the chain.
-
InputValues
= Map<
String, dynamic> - Input values used to format a prompt. The keys are the names of the variables in the prompt template and the values the actual values to use.
-
MemoryInputValues
= Map<
String, dynamic> - Input values to load from memory.
-
MemoryOutputValues
= Map<
String, dynamic> - Output values to save to memory.
-
MemoryVariables
= Map<
String, dynamic> - Key-value pairs loaded from memory.
-
PartialValues
= Map<
String, dynamic> - Partial input values used to format a prompt. The keys are the names of the variables in the prompt template and the values the actual values to use.
Exceptions / Errors
- LangChainException
- A base class for all exceptions thrown by LangChain.
- OutputParserException
- Exception that output parsers should raise to signify a parsing error.
- PromptException
- Exception thrown when some error occurs while working with a prompt.
- TemplateValidationException
- Exception thrown when a template validation fails.
- ToolException
- An exception that a tool throws when execution error occurs.