Skip to content

mistralai

pixeltable.functions.mistralai

Pixeltable UDFs that wrap various endpoints from the Mistral AI API. In order to use them, you must first pip install mistralai and configure your Mistral AI credentials, as described in the Working with Mistral AI tutorial.

chat_completions

chat_completions(
    messages: JsonT,
    *,
    model: str,
    temperature: Optional[float] = 0.7,
    top_p: Optional[float] = 1.0,
    max_tokens: Optional[int] = None,
    min_tokens: Optional[int] = None,
    stop: Optional[JsonT] = None,
    random_seed: Optional[int] = None,
    response_format: Optional[JsonT] = None,
    safe_prompt: Optional[bool] = False
) -> JsonT

Chat Completion API.

Equivalent to the Mistral AI chat/completions API endpoint. For additional details, see: https://docs.mistral.ai/api/#tag/chat

Requirements:

  • pip install mistralai

Parameters:

For details on the other parameters, see: https://docs.mistral.ai/api/#tag/chat

Returns:

  • JsonT

    A dictionary containing the response and other metadata.

Examples:

Add a computed column that applies the model mistral-latest-small to an existing Pixeltable column tbl.prompt of the table tbl:

>>> messages = [{'role': 'user', 'content': tbl.prompt}]
... tbl['response'] = completions(messages, model='mistral-latest-small')

embeddings

embeddings(input: str, *, model: str) -> ArrayT

Embeddings API.

Equivalent to the Mistral AI embeddings API endpoint. For additional details, see: https://docs.mistral.ai/api/#tag/embeddings

Requirements:

  • pip install mistralai

Parameters:

Returns:

  • ArrayT

    An array representing the application of the given embedding to input.

fim_completions

fim_completions(
    prompt: str,
    *,
    model: str,
    temperature: Optional[float] = 0.7,
    top_p: Optional[float] = 1.0,
    max_tokens: Optional[int] = None,
    min_tokens: Optional[int] = None,
    stop: Optional[JsonT] = None,
    random_seed: Optional[int] = None,
    suffix: Optional[str] = None
) -> JsonT

Fill-in-the-middle Completion API.

Equivalent to the Mistral AI fim/completions API endpoint. For additional details, see: https://docs.mistral.ai/api/#tag/fim

Requirements:

  • pip install mistralai

Parameters:

For details on the other parameters, see: https://docs.mistral.ai/api/#tag/fim

Returns:

  • JsonT

    A dictionary containing the response and other metadata.

Examples:

Add a computed column that applies the model codestral-latest to an existing Pixeltable column tbl.prompt of the table tbl:

>>> tbl['response'] = completions(tbl.prompt, model='codestral-latest')