MindMap Gallery What is LangChain ——Powerful and easy-to-use large language model programming framework
LangChain is the most popular LLM (Large Language Model) programming framework at the moment. If you want to develop an LLM-based application, it has all the components you need. Just use it directly.
Edited at 2023-10-29 15:48:40El cáncer de pulmón es un tumor maligno que se origina en la mucosa bronquial o las glándulas de los pulmones. Es uno de los tumores malignos con mayor morbilidad y mortalidad y mayor amenaza para la salud y la vida humana.
La diabetes es una enfermedad crónica con hiperglucemia como signo principal. Es causada principalmente por una disminución en la secreción de insulina causada por una disfunción de las células de los islotes pancreáticos, o porque el cuerpo es insensible a la acción de la insulina (es decir, resistencia a la insulina), o ambas cosas. la glucosa en la sangre es ineficaz para ser utilizada y almacenada.
El sistema digestivo es uno de los nueve sistemas principales del cuerpo humano y es el principal responsable de la ingesta, digestión, absorción y excreción de los alimentos. Consta de dos partes principales: el tracto digestivo y las glándulas digestivas.
El cáncer de pulmón es un tumor maligno que se origina en la mucosa bronquial o las glándulas de los pulmones. Es uno de los tumores malignos con mayor morbilidad y mortalidad y mayor amenaza para la salud y la vida humana.
La diabetes es una enfermedad crónica con hiperglucemia como signo principal. Es causada principalmente por una disminución en la secreción de insulina causada por una disfunción de las células de los islotes pancreáticos, o porque el cuerpo es insensible a la acción de la insulina (es decir, resistencia a la insulina), o ambas cosas. la glucosa en la sangre es ineficaz para ser utilizada y almacenada.
El sistema digestivo es uno de los nueve sistemas principales del cuerpo humano y es el principal responsable de la ingesta, digestión, absorción y excreción de los alimentos. Consta de dos partes principales: el tracto digestivo y las glándulas digestivas.
LangChain
What is LangChain?
LangChain is a powerful framework designed to help developers build end-to-end applications using language models. It provides a set of tools, components, and interfaces that simplify the process of creating applications powered by large language models (LLMs) and chat models. LangChain can easily manage interactions with language models, link multiple components together, and integrate additional resources such as APIs and databases.
Core idea
Components and Chains
In LangChain, Components are modular building blocks that can be combined to create powerful applications. A Chain is a series of Components (or other Chains) that are grouped together to accomplish a specific task. For example, a Chain might include a Prompt template, a language model, and an output parser that work together to process user input, generate responses, and process output.
Prompt Templates and Values
The Prompt Template is responsible for creating the PromptValue, which is what is ultimately passed to the language model. Prompt Template helps convert user input and other dynamic information into a format suitable for language models. PromptValues are classes with methods that convert to the exact input type expected by each model type (like text or chat message).
Example Selectors
Example Selectors are useful when you want to dynamically include examples in prompts. They accept user input and return a list of examples to use in prompts, making them more powerful and context-specific.
Output Parsers
Output Parsers are responsible for structuring the language model response into a more useful format. They implement two main methods: one for providing formatting instructions, and another for parsing the language model's response into a structured format. This makes it easier to process the output data in your application.
Indexes and Retrievers
Index is a way of organizing documents to make it easier for language models to interact with them. A retriever is an interface for obtaining relevant documents and combining them with a language model. LangChain provides tools and functionality for working with different types of indexes and retrievers, such as vector databases and text splitters.
Chat Message History
LangChain mainly interacts with the language model through the chat interface. The ChatMessageHistory class is responsible for remembering all previous chat interaction data, which can then be passed back to the model, aggregated, or otherwise combined. This helps maintain context and improves the model's understanding of the conversation.
Agents and Toolkits
Agents are entities that drive decision making in LangChain. They have access to a suite of tools and can decide which tool to call based on user input. Tookits are a set of tools that, when used together, can accomplish a specific task. The agent executor is responsible for running the agent using the appropriate tools.
What is a LangChain Agent?
LangChain Agent is the entity in the framework that drives decision making. It has access to a set of tools and can decide which tool to call based on user input. Agents help build complex applications that require adaptive and context-specific responses. They are particularly useful when there are unknown chains of interactions that depend on user input and other factors.
How to use LangChain?
To use LangChain, developers first import the necessary components and tools, such as LLMs, chat models, agents, chains, and memory functions. These components combine to create an application that understands, processes, and responds to user input. LangChain provides multiple components for specific use cases, such as personal assistants, document Q&A, chatbots, querying tabular data, interacting with APIs, extraction, evaluation, and aggregation.
What’s a LangChain model?
LangChain model is an abstraction that represents the different types of models used in the framework.
LLM (Large Scale Language Model): These models take text strings as input and return text strings as output. They are the backbone of many language model applications.
Chat Model: The Chat Model is powered by a language model but has a more structured API. They take a list of chat messages as input and return chat messages. This makes it easy to manage conversation history and maintain context.
Text Embedding Models: These models take text as input and return a list of floats representing text embeddings. These embeddings can be used for tasks such as document retrieval, clustering, and similarity comparison.
Main features of LangChain
LLMs and Prompts: LangChain makes it easy to manage prompts, optimize them, and create a common interface for all LLMs. Additionally, it includes some handy utilities for working with LLMs.
Chain: These are sequences of calls to LLM or other utilities. LangChain provides a standard interface for the chain, integrates with various tools, and provides an end-to-end chain for popular applications.
Data-augmented generation: LangChain enables the chain to interact with external data sources to collect data for the generation step. For example, it can help summarize long texts or answer questions using specific data sources.
Agents: Agents let the LLM make decisions about actions, take those actions, check the results, and move forward until the work is completed. LangChain provides a standard interface for brokers, a variety of brokers to choose from, and end-to-end broker examples.
Memory: LangChain has a standard memory interface that helps maintain state between chain or proxy calls. It also provides a series of examples of memory implementations and chains or proxies that use memory.
Evaluation: Generative models are difficult to evaluate using traditional metrics. That’s why LangChain provides tips and chains to help developers themselves evaluate their models using LLM.
LangChain usage example
Document-specific Q&A: Answer a question based on given documents, using information from those documents to create the answer.
Chatbots: Build chatbots that can leverage the power of LLM to generate text.
Agents: Develop agents that can decide on actions, take those actions, observe the results, and continue execution until completion.