LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-corelanguage_modelsllmsBaseLLM
    Class●Since v0.1

    BaseLLM

    Base LLM abstract interface.

    It should take in a prompt and return a string.

    Copy
    BaseLLM(
        self,
        *args: Any = (),
        **kwargs: Any = {},
    )

    Bases

    BaseLanguageModel[str]ABC

    Attributes

    attribute
    model_config
    attribute
    OutputType: type[str]

    Get the output type for this Runnable.

    Methods

    method
    invoke
    method
    ainvoke
    method
    batch
    method
    abatch
    method
    stream
    method
    astream
    method
    generate_prompt
    method
    agenerate_prompt
    method
    generate

    Pass a sequence of prompts to a model and return generations.

    This method should make use of batched calls for models that expose a batched API.

    Use this method when you want to:

    1. Take advantage of batched calls,
    2. Need more output from the model than just the top generated value,
    3. Are building chains that are agnostic to the underlying language model type (e.g., pure text completion models vs chat models).
    method
    agenerate

    Asynchronously pass a sequence of prompts to a model and return generations.

    This method should make use of batched calls for models that expose a batched API.

    Use this method when you want to:

    1. Take advantage of batched calls,
    2. Need more output from the model than just the top generated value,
    3. Are building chains that are agnostic to the underlying language model type (e.g., pure text completion models vs chat models).
    method
    dict

    Return a dictionary of the LLM.

    method
    save

    Save the LLM.

    Inherited fromBaseLanguageModel

    Attributes

    Acache: BaseCache | bool | None
    —

    Whether to cache the response.

    Averbose: bool
    —

    Whether to print out response text.

    Acallbacks: Callbacks
    —

    Callbacks to add to the run trace.

    Atags: list[str] | None
    —

    Tags to add to the run trace.

    Ametadata: dict[str, Any] | None
    —

    Metadata to add to the run trace.

    Acustom_get_token_ids: Callable[[str], list[int]] | None
    —

    Optional encoder to use for counting tokens.

    AInputType: TypeAlias
    —

    Get the input type for this Runnable.

    Methods

    Mset_verbose
    —

    If verbose is None, set it.

    Mwith_structured_output
    —

    Not implemented on this class.

    Mget_token_ids
    —

    Return the ordered IDs of the tokens in a text.

    Mget_num_tokens
    —

    Get the number of tokens present in the text.

    Mget_num_tokens_from_messages
    —

    Get the number of tokens in the messages.

    Inherited fromRunnableSerializable

    Attributes

    Aname: str | None
    —

    The name of the Runnable.

    Methods

    Mto_json
    —

    Serialize the Runnable to JSON.

    Mconfigurable_fields
    —

    Configure particular Runnable fields at runtime.

    Mconfigurable_alternatives
    —

    Configure alternatives for Runnable objects that can be set at runtime.

    Inherited fromSerializable

    Attributes

    Alc_secrets: dict[str, str]
    —

    A map of constructor argument names to secret ids.

    Alc_attributes: dict
    —

    List of attribute names that should be included in the serialized kwargs.

    Methods

    Mis_lc_serializable
    —

    Is this class serializable?

    Mget_lc_namespace
    —

    Get the namespace of the LangChain object.

    Mlc_id
    —

    Return a unique identifier for this class for serialization purposes.

    Mto_json
    —

    Serialize the object to JSON.

    Mto_json_not_implemented
    —

    Serialize a "not implemented" object.

    Inherited fromRunnable

    Attributes

    Aname: str | None
    —

    The name of the Runnable. Used for debugging and tracing.

    AInputType: type[Input]
    —

    Input type.

    Ainput_schema: type[BaseModel]
    —

    The type of input this Runnable accepts specified as a Pydantic model.

    Aoutput_schema: type[BaseModel]
    —

    Output schema.

    Aconfig_specs: list[ConfigurableFieldSpec]
    —

    List configurable fields for this Runnable.

    Methods

    Mget_name
    —

    Get the name of the Runnable.

    Mget_input_schema
    —

    Get a Pydantic model that can be used to validate input to the Runnable.

    Mget_input_jsonschema
    —

    Get a JSON schema that represents the input to the Runnable.

    Mget_output_schema
    —

    Get a Pydantic model that can be used to validate output to the Runnable.

    Mget_output_jsonschema
    —

    Get a JSON schema that represents the output of the Runnable.

    Mconfig_schema
    —

    The type of config this Runnable accepts specified as a Pydantic model.

    Mget_config_jsonschema
    —

    Get a JSON schema that represents the config of the Runnable.

    Mget_graph
    —

    Return a graph representation of this Runnable.

    Mget_prompts
    —

    Return a list of prompts used by this Runnable.

    Mpipe
    —

    Pipe Runnable objects.

    Mpick
    —

    Pick keys from the output dict of this Runnable.

    Massign
    —

    Assigns new fields to the dict output of this Runnable.

    Mbatch_as_completed
    —

    Run invoke in parallel on a list of inputs.

    Mabatch_as_completed
    —

    Run ainvoke in parallel on a list of inputs.

    Mastream_log
    —

    Stream all output from a Runnable, as reported to the callback system.

    Mastream_events
    —

    Generate a stream of events.

    Mtransform
    —

    Transform inputs to outputs.

    Matransform
    —

    Transform inputs to outputs.

    Mbind
    —

    Bind arguments to a Runnable, returning a new Runnable.

    Mwith_config
    —

    Bind config to a Runnable, returning a new Runnable.

    Mwith_listeners
    —

    Bind lifecycle listeners to a Runnable, returning a new Runnable.

    Mwith_alisteners
    —

    Bind async lifecycle listeners to a Runnable.

    Mwith_types
    —

    Bind input and output types to a Runnable, returning a new Runnable.

    Mwith_retry
    —

    Create a new Runnable that retries the original Runnable on exceptions.

    Mmap
    —

    Return a new Runnable that maps a list of inputs to a list of outputs.

    Mwith_fallbacks
    —

    Add fallbacks to a Runnable, returning a new Runnable.

    Mas_tool
    —

    Create a BaseTool from a Runnable.

    View source on GitHub