Skip to main content

metorial-mistral

Mistral AI provider integration for Metorial.

Installation

pip install metorial mistralai

Quick Start

import asyncio
from metorial import Metorial, MetorialMistral
from mistralai import AsyncMistral

metorial = Metorial(api_key="your-metorial-api-key")
mistral = AsyncMistral(api_key="your-mistral-api-key")

async def main():
    async def session_handler(session):
        messages = [{"role": "user", "content": "What's the latest news?"}]

        for _ in range(10):
            response = await mistral.chat.complete_async(
                model="mistral-large-latest",
                messages=messages,
                tools=session["tools"]
            )

            choice = response.choices[0]
            tool_calls = choice.message.tool_calls

            if not tool_calls:
                print(choice.message.content)
                break

            tool_responses = await session["callTools"](tool_calls)
            messages.append({"role": "assistant", "tool_calls": tool_calls})
            messages.extend(tool_responses)

        await session["closeSession"]()

    await metorial.with_provider_session(
        MetorialMistral,
        {"serverDeployments": [{"serverDeploymentId": "your-server-deployment-id"}]},
        session_handler
    )

asyncio.run(main())

Streaming

import asyncio
from metorial import Metorial, MetorialMistral
from mistralai import AsyncMistral

metorial = Metorial(api_key="your-metorial-api-key")
mistral = AsyncMistral(api_key="your-mistral-api-key")

async def main():
    async def session_handler(session):
        messages = [{"role": "user", "content": "What's the latest news?"}]

        stream = await mistral.chat.stream_async(
            model="mistral-large-latest",
            messages=messages,
            tools=session["tools"]
        )

        async for chunk in stream:
            if chunk.data.choices[0].delta.content:
                print(chunk.data.choices[0].delta.content, end="", flush=True)

        await session["closeSession"]()

    await metorial.with_provider_session(
        MetorialMistral,
        {
            "serverDeployments": [{"serverDeploymentId": "your-server-deployment-id"}],
            "streaming": True,  # Required for streaming with tool calls
        },
        session_handler
    )

asyncio.run(main())

Supported Models

  • mistral-large-latest: Most capable Mistral model
  • codestral-latest: Code-focused Mistral model

Session Object

async def session_handler(session):
    tools = session["tools"]           # Tool definitions in Mistral format
    call_tools = session["callTools"]  # Execute tools and get responses
    close_session = session["closeSession"]  # Close the session when done

Error Handling

from metorial import MetorialAPIError

try:
    await metorial.with_provider_session(...)
except MetorialAPIError as e:
    print(f"API Error: {e.message} (Status: {e.status})")
except Exception as e:
    print(f"Unexpected error: {e}")

License

MIT License - see LICENSE file for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metorial_mistral-1.0.5.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

metorial_mistral-1.0.5-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file metorial_mistral-1.0.5.tar.gz.

File metadata

  • Download URL: metorial_mistral-1.0.5.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for metorial_mistral-1.0.5.tar.gz
Algorithm Hash digest
SHA256 8f5559eb24060b07cf7b273a4d264b5f58a85d0142edf0b3ae8449595249d4de
MD5 e2da43dd2fd58d03916f2a36bd7efb09
BLAKE2b-256 58d099012c6edc4ca424e789b48fba0afbbc0e5f896192a7e453c376bfd0394d

See more details on using hashes here.

Provenance

The following attestation bundles were made for metorial_mistral-1.0.5.tar.gz:

Publisher: release.yml on metorial/metorial-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file metorial_mistral-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for metorial_mistral-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 15b50c114f20900e64063ae60dd96cb785cd2eb065d1475c805a31598d48a2f3
MD5 ea76b39fe2fd09460003e7e9606d8c2b
BLAKE2b-256 a2d378c4314de82e1888990b4ab77d0b55a2b39dc0c51753adba9d9741dbc180

See more details on using hashes here.

Provenance

The following attestation bundles were made for metorial_mistral-1.0.5-py3-none-any.whl:

Publisher: release.yml on metorial/metorial-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.5 This release

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page