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.

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

Methods

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

  • 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