Class that represents the Ollama language model. It extends the base LLM class and implements the OllamaInput interface.

Hierarchy

  • LLM<OllamaCallOptions>
    • Ollama

Implements

  • OllamaInput

Constructors

Properties

CallOptions: OllamaCallOptions
ParsedCallOptions: Omit<OllamaCallOptions, never>
baseUrl: string = "http://localhost:11434"
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_kwargs: SerializedFields
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.

lc_serializable: boolean = true
model: string = "llama2"
verbose: boolean

Whether to print out response text.

callbacks?: Callbacks
embeddingOnly?: boolean
f16KV?: boolean
format?: StringWithAutocomplete<"json">
frequencyPenalty?: number
logitsAll?: boolean
lowVram?: boolean
mainGpu?: number
metadata?: Record<string, unknown>
mirostat?: number
mirostatEta?: number
mirostatTau?: number
numBatch?: number
numCtx?: number
numGpu?: number
numGqa?: number
numKeep?: number
numThread?: number
penalizeNewline?: boolean
presencePenalty?: number
repeatLastN?: number
repeatPenalty?: number
ropeFrequencyBase?: number
ropeFrequencyScale?: number
stop?: string[]
tags?: string[]
temperature?: number
tfsZ?: number
topK?: number
topP?: number
typicalP?: number
useMLock?: boolean
useMMap?: boolean
vocabOnly?: boolean
lc_runnable: boolean = true

Accessors

  • get lc_aliases(): undefined | {
        [key: string]: string;
    }
  • A map of aliases for constructor args. Keys are the attribute names, e.g. "foo". Values are the alias that will replace the key in serialization. This is used to eg. make argument names match Python.

    Returns undefined | {
        [key: string]: string;
    }

  • get lc_attributes(): undefined | {
        [key: string]: undefined;
    }
  • A map of additional attributes to merge with constructor args. Keys are the attribute names, e.g. "foo". Values are the attribute values, which will be serialized. These attributes need to be accepted by the constructor as arguments.

    Returns undefined | {
        [key: string]: undefined;
    }

  • get lc_secrets(): undefined | {
        [key: string]: string;
    }
  • A map of secrets, which will be omitted from serialization. Keys are paths to the secret in constructor args, e.g. "foo.bar.baz". Values are the secret ids, which will be used when deserializing.

    Returns undefined | {
        [key: string]: string;
    }

Methods

  • Internal method that handles batching and configuration for a runnable It takes a function, input values, and optional configuration, and returns a promise that resolves to the output values.

    Type Parameters

    Parameters

    • func: ((inputs, options?, runManagers?, batchOptions?) => Promise<(string | Error)[]>)

      The function to be executed for each input value.

        • (inputs, options?, runManagers?, batchOptions?): Promise<(string | Error)[]>
        • Parameters

          Returns Promise<(string | Error)[]>

    • inputs: T[]
    • Optional options: Partial<OllamaCallOptions & {
          runType?: string;
      }> | Partial<OllamaCallOptions & {
          runType?: string;
      }>[]
    • Optional batchOptions: RunnableBatchOptions

    Returns Promise<(string | Error)[]>

    A promise that resolves to the output values.

  • Default streaming implementation. Subclasses should override this method if they support streaming output.

    Parameters

    Returns AsyncGenerator<string, any, unknown>

  • Default implementation of batch, which calls invoke N times. Subclasses should override this method if they can batch more efficiently.

    Parameters

    • inputs: BaseLanguageModelInput[]

      Array of inputs to each batch call.

    • Optional options: Partial<OllamaCallOptions> | Partial<OllamaCallOptions>[]

      Either a single call options object to apply to each batch call or an array for each call.

    • Optional batchOptions: RunnableBatchOptions & {
          returnExceptions?: false;
      }

    Returns Promise<string[]>

    An array of RunOutputs, or mixed RunOutputs and errors if batchOptions.returnExceptions is set

  • Parameters

    Returns Promise<(string | Error)[]>

  • Parameters

    Returns Promise<(string | Error)[]>

  • Convenience wrapper for generate that takes in a single string prompt and returns a single string output.

    Parameters

    • prompt: string
    • Optional options: string[] | OllamaCallOptions
    • Optional callbacks: Callbacks

    Returns Promise<string>

  • This method takes prompt values, options, and callbacks, and generates a result based on the prompts.

    Parameters

    • promptValues: BasePromptValue[]

      Prompt values for the LLM.

    • Optional options: string[] | OllamaCallOptions

      Options for the LLM call.

    • Optional callbacks: Callbacks

      Callbacks for the LLM call.

    Returns Promise<LLMResult>

    An LLMResult based on the prompts.

  • Get the parameters used to invoke the model

    Parameters

    • Optional options: Omit<OllamaCallOptions, never>

    Returns {
        format: undefined | StringWithAutocomplete<"json">;
        model: string;
        options: {
            embedding_only: undefined | boolean;
            f16_kv: undefined | boolean;
            frequency_penalty: undefined | number;
            logits_all: undefined | boolean;
            low_vram: undefined | boolean;
            main_gpu: undefined | number;
            mirostat: undefined | number;
            mirostat_eta: undefined | number;
            mirostat_tau: undefined | number;
            num_batch: undefined | number;
            num_ctx: undefined | number;
            num_gpu: undefined | number;
            num_gqa: undefined | number;
            num_keep: undefined | number;
            num_thread: undefined | number;
            penalize_newline: undefined | boolean;
            presence_penalty: undefined | number;
            repeat_last_n: undefined | number;
            repeat_penalty: undefined | number;
            rope_frequency_base: undefined | number;
            rope_frequency_scale: undefined | number;
            stop: undefined | string[];
            temperature: undefined | number;
            tfs_z: undefined | number;
            top_k: undefined | number;
            top_p: undefined | number;
            typical_p: undefined | number;
            use_mlock: undefined | boolean;
            use_mmap: undefined | boolean;
            vocab_only: undefined | boolean;
        };
    }

    • format: undefined | StringWithAutocomplete<"json">
    • model: string
    • options: {
          embedding_only: undefined | boolean;
          f16_kv: undefined | boolean;
          frequency_penalty: undefined | number;
          logits_all: undefined | boolean;
          low_vram: undefined | boolean;
          main_gpu: undefined | number;
          mirostat: undefined | number;
          mirostat_eta: undefined | number;
          mirostat_tau: undefined | number;
          num_batch: undefined | number;
          num_ctx: undefined | number;
          num_gpu: undefined | number;
          num_gqa: undefined | number;
          num_keep: undefined | number;
          num_thread: undefined | number;
          penalize_newline: undefined | boolean;
          presence_penalty: undefined | number;
          repeat_last_n: undefined | number;
          repeat_penalty: undefined | number;
          rope_frequency_base: undefined | number;
          rope_frequency_scale: undefined | number;
          stop: undefined | string[];
          temperature: undefined | number;
          tfs_z: undefined | number;
          top_k: undefined | number;
          top_p: undefined | number;
          typical_p: undefined | number;
          use_mlock: undefined | boolean;
          use_mmap: undefined | boolean;
          vocab_only: undefined | boolean;
      }
      • embedding_only: undefined | boolean
      • f16_kv: undefined | boolean
      • frequency_penalty: undefined | number
      • logits_all: undefined | boolean
      • low_vram: undefined | boolean
      • main_gpu: undefined | number
      • mirostat: undefined | number
      • mirostat_eta: undefined | number
      • mirostat_tau: undefined | number
      • num_batch: undefined | number
      • num_ctx: undefined | number
      • num_gpu: undefined | number
      • num_gqa: undefined | number
      • num_keep: undefined | number
      • num_thread: undefined | number
      • penalize_newline: undefined | boolean
      • presence_penalty: undefined | number
      • repeat_last_n: undefined | number
      • repeat_penalty: undefined | number
      • rope_frequency_base: undefined | number
      • rope_frequency_scale: undefined | number
      • stop: undefined | string[]
      • temperature: undefined | number
      • tfs_z: undefined | number
      • top_k: undefined | number
      • top_p: undefined | number
      • typical_p: undefined | number
      • use_mlock: undefined | boolean
      • use_mmap: undefined | boolean
      • vocab_only: undefined | boolean
  • This method takes an input and options, and returns a string. It converts the input to a prompt value and generates a result based on the prompt.

    Parameters

    • input: BaseLanguageModelInput

      Input for the LLM.

    • Optional options: OllamaCallOptions

      Options for the LLM call.

    Returns Promise<string>

    A string result based on the prompt.

  • This method is similar to call, but it's used for making predictions based on the input text.

    Parameters

    • text: string

      Input text for the prediction.

    • Optional options: string[] | OllamaCallOptions

      Options for the LLM call.

    • Optional callbacks: Callbacks

      Callbacks for the LLM call.

    Returns Promise<string>

    A prediction based on the input text.

  • This method takes a list of messages, options, and callbacks, and returns a predicted message.

    Parameters

    • messages: BaseMessage[]

      A list of messages for the prediction.

    • Optional options: string[] | OllamaCallOptions

      Options for the LLM call.

    • Optional callbacks: Callbacks

      Callbacks for the LLM call.

    Returns Promise<BaseMessage>

    A predicted message based on the list of messages.

  • 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<OllamaCallOptions>
    • 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<string, any, unknown>

  • The name of the serializable. Override to provide an alias or to preserve the serialized module name in minified environments.

    Implemented as a static method to support loading logic.

    Returns string

  • Type Parameters

    Parameters

    • func: ((input) => Promise<string>) | ((input, config?, runManager?) => Promise<string>)
    • input: T
    • Optional options: Partial<OllamaCallOptions> & {
          runType?: string;
      }

    Returns Promise<string>

  • Parameters

    • options: Partial<OllamaCallOptions> | Partial<OllamaCallOptions>[]
    • length: number = 0

    Returns Partial<OllamaCallOptions & {
        runType?: string;
    }>[]

  • 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<OllamaCallOptions>

          Returns AsyncGenerator<O, any, unknown>

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

    Returns AsyncGenerator<O, any, unknown>

Generated using TypeDoc