Getting Started: Chat Models
LangChain provides a standard interface for using chat models. Chat models are a variation on language models. While chat models use language models under the hood, the interface they expose is a bit different. Rather than expose a "text in, text out" API, they expose an interface where "chat messages" are the inputs and outputs.
Chat Messages
A ChatMessage is what we refer to as the modular unit of information for a chat model.
At the moment, this consists of a "text" field, which refers to the content of the chat message.
There are currently four different classes of ChatMessage supported by LangChain:
HumanChatMessage: A chat message that is sent as if from a Human's point of view.AIChatMessage: A chat message that is sent from the point of view of the AI system to which the Human is corresponding.SystemChatMessage: A chat message that gives the AI system some information about the conversation. This is usually sent at the beginning of a conversation.ChatMessage: A generic chat message, with not only a"text"field but also an arbitrary"role"field.
These classes model conversation history. When calling a model with GenerateContent,
messages are passed as llms.MessageContent, which carries a role plus one or more
ContentParts — so a single message can mix text, images, and other modalities on
providers that support it (build them with llms.TextParts, llms.TextPart,
llms.ImageURLPart, and related helpers).
Dig deeper
📄️ Integrations
In LangChainGo every provider implements the same llms.Model interface, so a "chat