https://python.langchain.com/docs/concepts/chat_models/
- Modern LLMs are typically accessed through a chat model interface that takes a list of messages as input and return a message as output.
- Additional capabilities offer by newest generation chat models are:
-
Tool calling: Many popular chat models offer a nativeĀ tool callingĀ API. This API allows developers to build rich applications that enable LLMs to interact with external services, APIs, and databases. Tool calling can also be used to extract structured information from unstructured data and perform various other tasks.
-
Structured output: A technique to make a chat model respond in a structured format, such as JSON that matches a given schema.
-
Multimodality: The ability to work with data other than text; for example, images, audio, and video.
- https://medium.com/@ihamzakhan89/langchain-showdown-llms-vs-chat-models-ebf044e6827d
- Features:
- Integrations with many chat model providers (e.g., Anthropic, OpenAI, Ollama, Microsoft Azure, Google Vertex, Amazon Bedrock, Hugging Face, Cohere, Groq). Please seeĀ chat model integrationsĀ for an up-to-date list of supported models.
- Use either LangChain'sĀ messagesĀ format or OpenAI format.
- StandardĀ tool calling API: standard interface for binding tools to models, accessing tool call requests made by models, and sending tool results back to the model.
- Standard API forĀ structuring outputsĀ via theĀ
with_structured_outputĀ method.
- Provides support forĀ async programming,Ā efficient batching,Ā a rich streaming API.
- Integration withĀ LangSmithĀ for monitoring and debugging production-grade applications based on LLMs.
- Additional features like standardizedĀ token usage,Ā rate limiting,Ā cachingĀ and more.
- These integrations are one of two types:
- Official models: These are models that are officially supported by LangChain and/or model provider. You can find these models in theĀ
langchain-<provider>Ā packages.
- Community models: There are models that are mostly contributed and supported by the community. You can find these models in theĀ
langchain-communityĀ package.
- LangChain chat models implement theĀ BaseChatModelĀ interface. BecauseĀ
BaseChatModelĀ also implements theĀ Runnable Interface, chat models support aĀ standard streaming interface,Ā async programming, optimizedĀ batching, and more.
- Chat models offer a standard set of parameters that can be used to configure the model. These parameters are typically used to control the behavior of the model, such as the temperature of the output, the maximum number of tokens in the response, and the maximum time to wait for a response.
<aside>
š
Note:
In documentation, we will often use the terms "LLM" and "Chat Model" interchangeably. This is because most modern LLMs are exposed to users via a chat model interface.
However, LangChain also has implementations of older LLMs that do not follow the chat model interface and instead use an interface that takes a string as input and returns a string as output. These models are typically named without the "Chat" prefix (e.g.,Ā Ollama,Ā Anthropic,Ā OpenAI, etc.). These models implement theĀ BaseLLMĀ interface and may be named with the "LLM" suffix (e.g.,Ā OllamaLLM,Ā AnthropicLLM,Ā OpenAILLM, etc.). Generally, users should not use these models.
</aside>
Key methods:
The key methods of a chat model are:
- invoke: The primary method for interacting with a chat model. It takes a list ofĀ messagesĀ as input and returns a list of messages as output.
- stream: A method that allows you to stream the output of a chat model as it is generated.
- batch: A method that allows you to batch multiple requests to a chat model together for more efficient processing.
- bind_tools: A method that allows you to bind a tool to a chat model for use in the model's execution context.
- with_structured_output: A wrapper around theĀ
invokeĀ method for models that natively supportĀ structured output.
Other important methods can be found in theĀ BaseChatModel API Reference.
LangChain supports two message formats to interact with chat models:
- LangChain Message Format: LangChain's own message format, which is used by default and is used internally by LangChain.
- OpenAI's Message Format: OpenAI's message format.
Standard parameters