Class BaseLanguageModel<RunOutput, CallOptions>Abstract

Base class for language models.

Type Parameters

Hierarchy

Implements

Constructors

Properties

CallOptions: CallOptions
caller: AsyncCaller

The async caller should be used by subclasses to make any async calls, which will thus benefit from the concurrency and retry logic.

lc_namespace: string[]

A path to the module that contains the class, eg. ["langchain", "llms"] Usually should be the same as the entrypoint the class is exported from.

verbose: boolean

Whether to print out response text.

callbacks?: Callbacks
metadata?: Record<string, unknown>
tags?: string[]
lc_runnable: boolean = true

Accessors

Methods

  • Stream all output from a runnable, as reported to the callback system. This includes all inner runs of LLMs, Retrievers, Tools, etc. Output is streamed as Log objects, which include a list of jsonpatch ops that describe how the state of the run has changed in each step, and the final state of the run. The jsonpatch ops can be applied in order to construct state.

    Parameters

    • input: BaseLanguageModelInput
    • Optional options: Partial<CallOptions>
    • Optional streamOptions: Omit<LogStreamCallbackHandlerInput, "autoClose">

    Returns AsyncGenerator<RunLogPatch, any, unknown>

  • Default implementation of transform, which buffers input and then calls stream. Subclasses should override this method if they can start producing output while input is still being generated.

    Parameters

    Returns AsyncGenerator<RunOutput, any, unknown>

  • Create a unique cache key for a specific call to a specific language model.

    Parameters

    • callOptions: CallOptions

      Call options for the model

    Returns string

    A unique cache key.

  • Helper method to transform an Iterator of Input values into an Iterator of Output values, with callbacks. Use this to implement stream() or transform() in Runnable subclasses.

    Type Parameters

    Parameters

    • inputGenerator: AsyncGenerator<I, any, unknown>
    • transformer: ((generator, runManager?, options?) => AsyncGenerator<O, any, unknown>)
        • (generator, runManager?, options?): AsyncGenerator<O, any, unknown>
        • Parameters

          • generator: AsyncGenerator<I, any, unknown>
          • Optional runManager: CallbackManagerForChainRun
          • Optional options: Partial<CallOptions>

          Returns AsyncGenerator<O, any, unknown>

    • Optional options: CallOptions & {
          runType?: string;
      }

    Returns AsyncGenerator<O, any, unknown>

Generated using TypeDoc