Class ChatMistralAI<CallOptions>

Integration with a chat model.

Type Parameters

  • CallOptions extends MistralAICallOptions = MistralAICallOptions

Hierarchy

  • Toolkit<CallOptions>
    • ChatMistralAI

Implements

Constructors

Properties

apiKey: string

The API key to use.

Default

{process.env.MISTRAL_API_KEY}
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}
endpoint?: string

Override the default endpoint.

randomSeed?: number

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

Methods

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

  • Get the parameters used to invoke the model

    Parameters

    • Optional options: unknown

    Returns Omit<MistralAIChatCompletionOptions, "messages">

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

    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>

    A new runnable that calls the LLM with structured output.

Generated using TypeDoc