LangChain es un framework open-source implementado en Python. Es un orquestador de aplicaciones basadas en LLMs que proporciona diferentes abstracciones de alto nivel para construir pipelines sobre LLMs.
La gran ventaja que nos introduce es abstraernos de la manera de consumir los diferentes LLMs para no tener que reinventar el código cada vez que queramos cambiar de modelo.
Ahora mismo LangChain dispone de 6 módulos diferentes
- Model I/O - Handle input/output ops related to the model
- Retrieval - Retrieves relevant texts for the LLM
- Chains (Runnables) - Enables construction of sequences of LLM operations or function calls
- Agents - Allows chains to make decisions on which tools to use based on high-level instructions
- Memory - perstist the state of an application between different runs of a chain
- Callbacks - for running additional code on specific events
Install
poetry add langchain
poetry add langchain-openai
poetry add openai # this is in case we want to use OpenAI's models
ChatModels
We have the following classes to interact with LLMs in the context of LangChain
- SystemMessage - instructions for the AI System (Behaviour)
- HumanMessage - messages coming from an human to interact with the LLM (questions, commands…)
- AIMessage - information coming from the AI itself. This is typically the AI’s response