llm

Mistral LLM service implementation using OpenAI-compatible interface.

class pipecat.services.mistral.llm.MistralLLMSettings(model: str | None | _NotGiven = <factory>, extra: dict[str, Any]=<factory>, system_instruction: str | None | _NotGiven = <factory>, temperature: float | None | _NotGiven | NotGiven = <factory>, max_tokens: int | None | _NotGiven | NotGiven = <factory>, top_p: float | None | _NotGiven | NotGiven = <factory>, top_k: int | None | _NotGiven = <factory>, frequency_penalty: float | None | _NotGiven | NotGiven = <factory>, presence_penalty: float | None | _NotGiven | NotGiven = <factory>, seed: int | None | _NotGiven | NotGiven = <factory>, filter_incomplete_user_turns: bool | None | _NotGiven = <factory>, user_turn_completion_config: UserTurnCompletionConfig | None | _NotGiven = <factory>, max_completion_tokens: int | _NotGiven | NotGiven = <factory>)[source]

Bases: OpenAILLMSettings

Settings for MistralLLMService.

class pipecat.services.mistral.llm.MistralLLMService(*, api_key: str, base_url: str = 'https://api.mistral.ai/v1', model: str | None = None, settings: MistralLLMSettings | None = None, **kwargs)[source]

Bases: OpenAILLMService

A service for interacting with Mistral’s API using the OpenAI-compatible interface.

This service extends OpenAILLMService to connect to Mistral’s API endpoint while maintaining full compatibility with OpenAI’s interface and functionality.

supports_developer_role = False

Whether this service’s API supports the “developer” message role.

OpenAI’s native API supports it, but some OpenAI-compatible services (e.g. Cerebras) do not. Subclasses that don’t support it should set this to False, which causes the adapter to convert “developer” messages to “user” messages before sending them to the API.

adapter_class

alias of MistralLLMAdapter

Settings

alias of MistralLLMSettings

__init__(*, api_key: str, base_url: str = 'https://api.mistral.ai/v1', model: str | None = None, settings: MistralLLMSettings | None = None, **kwargs)[source]

Initialize the Mistral LLM service.

Parameters:
  • api_key – The API key for accessing Mistral’s API.

  • base_url – The base URL for Mistral API. Defaults to “https://api.mistral.ai/v1”.

  • model

    The model identifier to use. Defaults to “mistral-small-latest”.

    Deprecated since version 0.0.105: Use settings=MistralLLMService.Settings(model=...) instead.

  • settings – Runtime-updatable settings. When provided alongside deprecated parameters, settings values take precedence.

  • **kwargs – Additional keyword arguments passed to OpenAILLMService.

create_client(api_key=None, base_url=None, **kwargs)[source]

Create OpenAI-compatible client for Mistral API endpoint.

Parameters:
  • api_key – The API key for authentication. If None, uses instance key.

  • base_url – The base URL for the API. If None, uses instance URL.

  • **kwargs – Additional arguments passed to the client constructor.

Returns:

An OpenAI-compatible client configured for Mistral API.

async run_function_calls(function_calls: Sequence[FunctionCallFromLLM])[source]

Execute function calls, filtering out already-completed ones.

Mistral and OpenAI have different function call detection patterns:

OpenAI (Stream-based detection):

  • Detects function calls only from streaming chunks as the LLM generates them

  • Second LLM completion doesn’t re-detect existing tool_calls in message history

  • Function calls execute exactly once

Mistral (Message-based detection):

  • Detects function calls from the complete message history on each completion

  • Second LLM completion with the response re-detects the same tool_calls from previous messages

  • Without filtering, function calls would execute twice

This method prevents duplicate execution by:

  1. Checking message history for existing tool result messages

  2. Filtering out function calls that already have corresponding results

  3. Only executing function calls that haven’t been completed yet

Note: This filtering prevents duplicate function execution, but the on_function_calls_started event may still fire twice due to the detection pattern difference. This is expected behavior.

Parameters:

function_calls – The function calls to potentially execute.

build_chat_completion_params(params_from_context: OpenAILLMInvocationParams) dict[source]

Build parameters for Mistral chat completion request.

Handles Mistral-specific parameter mapping (random_seed in place of seed). Message-shape fixups required by Mistral are applied by MistralLLMAdapter upstream.