Skip to main content

Models

Models are a core component of LangChain. LangChain is not a provider of models, but rather provides a standard interface through which you can interact with a variety of language models. LangChain provides support for both text-based Large Language Models (LLMs), Chat Models, and Text Embedding models.

LLMs use a text-based input and output, while Chat Models use a message-based input and output.

Note: Chat model APIs are fairly new, so we are still figuring out the correct abstractions. If you have any feedback, please let us know!

All Models

Advanced

This section is for users who want a deeper technical understanding of how LangChain works. If you are just getting started, you can skip this section.

All LLMs and Chat Models implement the llms.Model interface. This allows us to easily swap out models in chains without changing the rest of the code.

// Model is the interface all language models must implement.
type Model interface {
// GenerateContent asks the model to generate content from a sequence of
// messages. It's the most general interface for multi-modal LLMs that support
// chat-like interactions.
GenerateContent(ctx context.Context, messages []MessageContent, options ...CallOption) (*ContentResponse, error)

// Call is a simplified interface for a text-only Model, generating a single
// string response from a single string prompt.
// Deprecated: Use GenerateContent instead.
Call(ctx context.Context, prompt string, options ...CallOption) (string, error)
}

The llms.Model interface provides both modern multi-modal support via GenerateContent and legacy text-only support via the deprecated Call method.

Note: llms.LLM is a deprecated type alias for llms.Model:

// LLM is an alias for model, for backwards compatibility.
// Deprecated: This alias may be removed in the future; please use Model instead.
type LLM = Model

All language models, whether text-only or chat-based, implement the same llms.Model interface. The interface is designed to handle both simple text prompts and complex multi-modal message sequences.