Class ChatMistralAI<CallOptions>

Integration with a chat model.

Type Parameters

  • CallOptions extends MistralAICallOptions = MistralAICallOptions

Hierarchy

Implements

Constructors

Properties

ParsedCallOptions: Omit<CallOptions, never>
apiKey: string

The API key to use.

Default

{process.env.MISTRAL_API_KEY}
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.

maxTokens: number

The maximum number of tokens to generate in the completion. The token count of your prompt plus max_tokens cannot exceed the model's context length.

modelName: string = "mistral-small-latest"

The name of the model to use.

Default

{"mistral-small-latest"}
safeMode: boolean = false

⚠️ Deprecated ⚠️

use safePrompt instead

This feature is deprecated and will be removed in the future.

It is not recommended for use.

safePrompt: boolean = false

Whether to inject a safety prompt before all conversations.

Default

{false}
streaming: boolean = false

Whether or not to stream the response.

Default

{false}
temperature: number = 0.7

What sampling temperature to use, between 0.0 and 2.0. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.

Default

{0.7}
topP: number = 1

Nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. Should be between 0 and 1.

Default

{1}
verbose: boolean

Whether to print out response text.

callbacks?: Callbacks
endpoint?: string

Override the default endpoint.

metadata?: Record<string, unknown>
name?: string
randomSeed?: number

The seed to use for random sampling. If set, different calls will generate deterministic results.

tags?: string[]

Accessors

  • get callKeys(): string[]
  • Keys that the language model accepts as call options.

    Returns string[]

Methods

  • Assigns new fields to the dict output of this runnable. Returns a new runnable.

    Parameters

    • mapping: RunnableMapLike<Record<string, unknown>, Record<string, unknown>>

    Returns Runnable<any, any, RunnableConfig>

  • 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<CallOptions> | Partial<CallOptions>[]

      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<BaseMessageChunk[]>

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

  • Parameters

    Returns Promise<(Error | BaseMessageChunk)[]>

  • Parameters

    Returns Promise<(Error | BaseMessageChunk)[]>

  • Parameters

    • messages: BaseMessageLike[]

      An array of BaseMessage instances.

    • Optional options: string[] | CallOptions

      The call options or an array of stop sequences.

    • Optional callbacks: Callbacks

      The callbacks for the language model.

    Returns Promise<BaseMessage>

    A Promise that resolves to a BaseMessage.

    Deprecated

    Use .invoke() instead. Will be removed in 0.2.0.

    Makes a single call to the chat model.

  • Parameters

    • promptValue: BasePromptValueInterface

      The value of the prompt.

    • Optional options: string[] | CallOptions

      The call options or an array of stop sequences.

    • Optional callbacks: Callbacks

      The callbacks for the language model.

    Returns Promise<BaseMessage>

    A Promise that resolves to a BaseMessage.

    Deprecated

    Use .invoke() instead. Will be removed in 0.2.0.

    Makes a single call to the chat model with a prompt value.

  • Calls the MistralAI API with retry logic in case of failures.

    Parameters

    • input: MistralAIChatCompletionOptions

      The input to send to the MistralAI API.

    • streaming: true

    Returns Promise<AsyncGenerator<ChatCompletionResponseChunk, any, unknown>>

    The response from the MistralAI API.

  • Parameters

    • input: MistralAIChatCompletionOptions
    • streaming: false

    Returns Promise<ChatCompletionResponse>

  • Generates chat based on the input messages.

    Parameters

    • messages: BaseMessageLike[][]

      An array of arrays of BaseMessage instances.

    • Optional options: string[] | CallOptions

      The call options or an array of stop sequences.

    • Optional callbacks: Callbacks

      The callbacks for the language model.

    Returns Promise<LLMResult>

    A Promise that resolves to an LLMResult.

  • Generates a prompt based on the input prompt values.

    Parameters

    • promptValues: BasePromptValueInterface[]

      An array of BasePromptValue instances.

    • Optional options: string[] | CallOptions

      The call options or an array of stop sequences.

    • Optional callbacks: Callbacks

      The callbacks for the language model.

    Returns Promise<LLMResult>

    A Promise that resolves to an LLMResult.

  • Parameters

    • Optional suffix: string

    Returns string

  • Parameters

    Returns Promise<number>

  • Invokes the chat model with a single input.

    Parameters

    • input: BaseLanguageModelInput

      The input for the language model.

    • Optional options: CallOptions

      The call options.

    Returns Promise<BaseMessageChunk>

    A Promise that resolves to a BaseMessageChunk.

  • Parameters

    • text: string

      The text input.

    • Optional options: string[] | CallOptions

      The call options or an array of stop sequences.

    • Optional callbacks: Callbacks

      The callbacks for the language model.

    Returns Promise<string>

    A Promise that resolves to a string.

    Deprecated

    Use .invoke() instead. Will be removed in 0.2.0.

    Predicts the next message based on a text input.

  • Parameters

    • messages: BaseMessage[]

      An array of BaseMessage instances.

    • Optional options: string[] | CallOptions

      The call options or an array of stop sequences.

    • Optional callbacks: Callbacks

      The callbacks for the language model.

    Returns Promise<BaseMessage>

    A Promise that resolves to a BaseMessage.

    Deprecated

    Use .invoke() instead. Will be removed in 0.2.0.

    Predicts the next message based on the input messages.

  • Stream output in chunks.

    Parameters

    Returns Promise<IterableReadableStream<BaseMessageChunk>>

    A readable stream that is also an iterable.

  • Generate a stream of events emitted by the internal steps of the runnable.

    Use to create an iterator over StreamEvents that provide real-time information about the progress of the runnable, including StreamEvents from intermediate results.

    A StreamEvent is a dictionary with the following schema:

    • event: string - Event names are of the format: on_[runnable_type]_(start|stream|end).
    • name: string - The name of the runnable that generated the event.
    • run_id: string - Randomly generated ID associated with the given execution of the runnable that emitted the event. A child runnable that gets invoked as part of the execution of a parent runnable is assigned its own unique ID.
    • tags: string[] - The tags of the runnable that generated the event.
    • metadata: Record<string, any> - The metadata of the runnable that generated the event.
    • data: Record<string, any>

    Below is a table that illustrates some events that might be emitted by various chains. Metadata fields have been omitted from the table for brevity. Chain definitions have been included after the table.

    event name chunk input output
    on_llm_start [model name] {'input': 'hello'}
    on_llm_stream [model name] 'Hello' OR AIMessageChunk("hello")
    on_llm_end [model name] 'Hello human!'
    on_chain_start format_docs
    on_chain_stream format_docs "hello world!, goodbye world!"
    on_chain_end format_docs [Document(...)] "hello world!, goodbye world!"
    on_tool_start some_tool {"x": 1, "y": "2"}
    on_tool_stream some_tool {"x": 1, "y": "2"}
    on_tool_end some_tool {"x": 1, "y": "2"}
    on_retriever_start [retriever name] {"query": "hello"}
    on_retriever_chunk [retriever name] {documents: [...]}
    on_retriever_end [retriever name] {"query": "hello"} {documents: [...]}
    on_prompt_start [template_name] {"question": "hello"}
    on_prompt_end [template_name] {"question": "hello"} ChatPromptValue(messages: [SystemMessage, ...])

    Parameters

    • input: BaseLanguageModelInput
    • options: Partial<CallOptions> & {
          version: "v1";
      }
    • Optional streamOptions: Omit<LogStreamCallbackHandlerInput, "autoClose">

    Returns AsyncGenerator<StreamEvent, any, unknown>

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

  • Bind lifecycle listeners to a Runnable, returning a new Runnable. The Run object contains information about the run, including its id, type, input, output, error, startTime, endTime, and any tags or metadata added to the run.

    Parameters

    • params: {
          onEnd?: ((run, config?) => void | Promise<void>);
          onError?: ((run, config?) => void | Promise<void>);
          onStart?: ((run, config?) => void | Promise<void>);
      }

      The object containing the callback functions.

      • Optional onEnd?: ((run, config?) => void | Promise<void>)
          • (run, config?): void | Promise<void>
          • Called after the runnable finishes running, with the Run object.

            Parameters

            Returns void | Promise<void>

      • Optional onError?: ((run, config?) => void | Promise<void>)
          • (run, config?): void | Promise<void>
          • Called if the runnable throws an error, with the Run object.

            Parameters

            Returns void | Promise<void>

      • Optional onStart?: ((run, config?) => void | Promise<void>)
          • (run, config?): void | Promise<void>
          • Called before the runnable starts running, with the Run object.

            Parameters

            Returns void | Promise<void>

    Returns Runnable<BaseLanguageModelInput, BaseMessageChunk, CallOptions>

  • Model wrapper that returns outputs formatted to match the given schema.

    Type Parameters

    • RunInput = BaseLanguageModelInput

      The input type for the Runnable, expected to be the same input for the LLM.

    • RunOutput extends ZodObject<any, any, any, any, {}> = ZodObject<any, any, any, any, {}>

      The output type for the Runnable, expected to be a Zod schema object for structured output validation.

    Parameters

    • __namedParameters: {
          includeRaw: true;
          name: string;
          schema: Record<string, any> | ZodEffects<RunOutput, output<RunOutput>, input<RunOutput>>;
          method?: "functionCalling" | "jsonMode";
      }
      • includeRaw: true
      • name: string
      • schema: Record<string, any> | ZodEffects<RunOutput, output<RunOutput>, input<RunOutput>>
      • Optional method?: "functionCalling" | "jsonMode"

    Returns Runnable<RunInput, {
        parsed: RunOutput;
        raw: BaseMessage;
    }, RunnableConfig>

    A new runnable that calls the LLM with structured output.

  • Model wrapper that returns outputs formatted to match the given schema.

    Type Parameters

    • RunInput = BaseLanguageModelInput

      The input type for the Runnable, expected to be the same input for the LLM.

    • RunOutput extends ZodObject<any, any, any, any, {}> = ZodObject<any, any, any, any, {}>

      The output type for the Runnable, expected to be a Zod schema object for structured output validation.

    Parameters

    • __namedParameters: {
          name: string;
          schema: Record<string, any> | ZodEffects<RunOutput, output<RunOutput>, input<RunOutput>>;
          includeRaw?: false;
          method?: "functionCalling" | "jsonMode";
      }
      • name: string
      • schema: Record<string, any> | ZodEffects<RunOutput, output<RunOutput>, input<RunOutput>>
      • Optional includeRaw?: false
      • Optional method?: "functionCalling" | "jsonMode"

    Returns Runnable<RunInput, RunOutput, RunnableConfig>

    A new runnable that calls the LLM with structured output.

Generated using TypeDoc