Skip to main content

Mistral AI provider for Metorial

Project description

metorial-mistral

Mistral AI provider integration for Metorial - enables using Metorial tools with Mistral's language models through function calling.

Installation

pip install metorial-mistral
# or
uv add metorial-mistral
# or
poetry add metorial-mistral

Features

  • 🤖 Mistral Integration: Full support for Mistral Large, Codestral, and other Mistral models
  • 🛠️ Function Calling: Native Mistral function calling support
  • 📡 Session Management: Automatic tool lifecycle handling
  • 🔄 Format Conversion: Converts Metorial tools to Mistral function format
  • Strict Mode: Built-in strict parameter validation
  • Async Support: Full async/await support

Usage

Basic Usage

import asyncio
from mistralai.client import MistralClient
from mistralai.models.chat_completion import ChatMessage
from metorial import Metorial
from metorial_mistral import MetorialMistralSession

async def main():
    # Initialize clients
    metorial = Metorial(api_key="your-metorial-api-key")
    mistral = MistralClient(api_key="your-mistral-api-key")
    
    # Create session with your server deployments
    async with metorial.session(["your-server-deployment-id"]) as session:
        # Create Mistral-specific wrapper
        mistral_session = MetorialMistralSession(session.tool_manager)
        
        messages = [
            ChatMessage(role="user", content="What are the latest commits?")
        ]
        
        response = mistral.chat(
            model="mistral-large-latest",
            messages=messages,
            tools=mistral_session.tools
        )
        
        # Handle tool calls
        if response.choices[0].message.tool_calls:
            tool_responses = await mistral_session.call_tools(response.choices[0].message.tool_calls)
            
            # Add assistant message and tool responses
            messages.append(response.choices[0].message)
            messages.extend(tool_responses)
            
            # Continue conversation...

asyncio.run(main())

Using Convenience Functions

from metorial_mistral import build_mistral_tools, call_mistral_tools

async def example_with_functions():
    # Get tools in Mistral format
    tools = build_mistral_tools(tool_manager)
    
    # Call tools from Mistral response
    tool_messages = await call_mistral_tools(tool_manager, tool_calls)

API Reference

MetorialMistralSession

Main session class for Mistral integration.

session = MetorialMistralSession(tool_manager)

Properties:

  • tools: List of tools in Mistral format

Methods:

  • async call_tools(tool_calls): Execute tool calls and return tool messages

build_mistral_tools(tool_mgr)

Build Mistral-compatible tool definitions.

Returns: List of tool definitions in Mistral format

call_mistral_tools(tool_mgr, tool_calls)

Execute tool calls from Mistral response.

Returns: List of tool messages

Tool Format

Tools are converted to Mistral's function calling format:

{
    "type": "function",
    "function": {
        "name": "tool_name",
        "description": "Tool description",
        "parameters": {
            "type": "object",
            "properties": {...},
            "required": [...]
        },
        "strict": True
    }
}

Error Handling

try:
    tool_messages = await mistral_session.call_tools(tool_calls)
except Exception as e:
    print(f"Tool execution failed: {e}")

Tool errors are returned as tool messages with error content.

Dependencies

  • mistralai>=1.0.0
  • metorial-mcp-session>=1.0.0
  • typing-extensions>=4.0.0

License

MIT License - see LICENSE file for details.

Project 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.0rc1.tar.gz (5.8 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.0rc1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file metorial_mistral-1.0.0rc1.tar.gz.

File metadata

  • Download URL: metorial_mistral-1.0.0rc1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for metorial_mistral-1.0.0rc1.tar.gz
Algorithm Hash digest
SHA256 d6d25df2ce6e0e26a3718aeb9b75b7409989191ef5c8081389a8f34f739745b1
MD5 959ac0b482f35dbb6e40ab860d390f57
BLAKE2b-256 7263a7d7c1779ba73b0a7f939237124aa37ffc58ab911288d12bef0527c445a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for metorial_mistral-1.0.0rc1.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.0rc1-py3-none-any.whl.

File metadata

File hashes

Hashes for metorial_mistral-1.0.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 60fe6e0199905535efe44da4d9d26baab1cbc5a51d440542f5d9a50cbacbf0d9
MD5 b352ceb883a945e67f289e34bb36187f
BLAKE2b-256 0987be7a6c681959c823555d9493839fba635dfac56577a3b6b921338ed389d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for metorial_mistral-1.0.0rc1-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.

Supported by

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