metorial-mistral


Namemetorial-mistral JSON
Version 1.0.4 PyPI version JSON
download
home_pageNone
SummaryMistral AI provider for Metorial
upload_time2025-10-30 05:03:13
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT
keywords ai llm metorial mistral
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # metorial-mistral

Mistral AI provider integration for Metorial.

## Installation

```bash
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
- šŸ“” **Session Management**: Automatic tool lifecycle handling
- šŸ”„ **Format Conversion**: Converts Metorial tools to Mistral function format
- ⚔ **Async Support**: Full async/await support

## Supported Models

All Mistral AI models that support function calling:

- `mistral-large-latest`: Latest Mistral Large model with enhanced reasoning
- `mistral-large-2411`: Mistral Large November 2024
- `mistral-large-2407`: Mistral Large July 2024
- `mistral-small-latest`: Smaller, faster Mistral model
- `codestral-latest`: Specialized for code generation and analysis

## Usage

### Quick Start (Recommended)

```python
import asyncio
from mistralai.async_client import MistralAsyncClient
from metorial import Metorial

async def main():
  # Initialize clients
  metorial = Metorial(api_key="...your-metorial-api-key...") # async by default
  mistral_client = MistralAsyncClient(
    api_key="...your-mistral-api-key..."
  )
  
  # One-liner chat with automatic session management
  response = await metorial.run(
    "What are the latest commits in the metorial/websocket-explorer repository?",
    "...your-mcp-server-deployment-id...", # can also be list
    mistral_client,
    model="mistral-large-latest",
    max_iterations=25
  )
  
  print("Response:", response)

asyncio.run(main())
```

### Streaming Chat

```python
import asyncio
from mistralai.async_client import MistralAsyncClient
from metorial import Metorial
from metorial.types import StreamEventType

async def streaming_example():
  # Initialize clients
  metorial = Metorial(api_key="...your-metorial-api-key...")
  mistral_client = MistralAsyncClient(
    api_key="...your-mistral-api-key..."
  )
  
  # Streaming chat with real-time responses
  async def stream_action(session):
    messages = [
      {"role": "user", "content": "Explain quantum computing"}
    ]
    
    async for event in metorial.stream(
      mistral_client, session, messages, 
      model="mistral-large-latest",
      max_iterations=25
    ):
      if event.type == StreamEventType.CONTENT:
        print(f"šŸ¤– {event.content}", end="", flush=True)
      elif event.type == StreamEventType.TOOL_CALL:
        print(f"\nšŸ”§ Executing {len(event.tool_calls)} tool(s)...")
      elif event.type == StreamEventType.COMPLETE:
        print(f"\nāœ… Complete!")
  
  await metorial.with_session("...your-server-deployment-id...", stream_action)

asyncio.run(streaming_example())
```

### Advanced Usage with Session Management

```python
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

```python
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.

```python
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:

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

## Error Handling

```python
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.

## License

MIT License - see [LICENSE](../../LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "metorial-mistral",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "ai, llm, metorial, mistral",
    "author": null,
    "author_email": "Metorial Team <support@metorial.com>",
    "download_url": "https://files.pythonhosted.org/packages/ce/4f/1cd9c810364ab5c49e38502d0043b89a67736e9eee6ce599825a8efc0311/metorial_mistral-1.0.4.tar.gz",
    "platform": null,
    "description": "# metorial-mistral\n\nMistral AI provider integration for Metorial.\n\n## Installation\n\n```bash\npip install metorial-mistral\n# or\nuv add metorial-mistral\n# or\npoetry add metorial-mistral\n```\n\n## Features\n\n- \ud83e\udd16 **Mistral Integration**: Full support for Mistral Large, Codestral, and other Mistral models\n- \ud83d\udce1 **Session Management**: Automatic tool lifecycle handling\n- \ud83d\udd04 **Format Conversion**: Converts Metorial tools to Mistral function format\n- \u26a1 **Async Support**: Full async/await support\n\n## Supported Models\n\nAll Mistral AI models that support function calling:\n\n- `mistral-large-latest`: Latest Mistral Large model with enhanced reasoning\n- `mistral-large-2411`: Mistral Large November 2024\n- `mistral-large-2407`: Mistral Large July 2024\n- `mistral-small-latest`: Smaller, faster Mistral model\n- `codestral-latest`: Specialized for code generation and analysis\n\n## Usage\n\n### Quick Start (Recommended)\n\n```python\nimport asyncio\nfrom mistralai.async_client import MistralAsyncClient\nfrom metorial import Metorial\n\nasync def main():\n  # Initialize clients\n  metorial = Metorial(api_key=\"...your-metorial-api-key...\") # async by default\n  mistral_client = MistralAsyncClient(\n    api_key=\"...your-mistral-api-key...\"\n  )\n  \n  # One-liner chat with automatic session management\n  response = await metorial.run(\n    \"What are the latest commits in the metorial/websocket-explorer repository?\",\n    \"...your-mcp-server-deployment-id...\", # can also be list\n    mistral_client,\n    model=\"mistral-large-latest\",\n    max_iterations=25\n  )\n  \n  print(\"Response:\", response)\n\nasyncio.run(main())\n```\n\n### Streaming Chat\n\n```python\nimport asyncio\nfrom mistralai.async_client import MistralAsyncClient\nfrom metorial import Metorial\nfrom metorial.types import StreamEventType\n\nasync def streaming_example():\n  # Initialize clients\n  metorial = Metorial(api_key=\"...your-metorial-api-key...\")\n  mistral_client = MistralAsyncClient(\n    api_key=\"...your-mistral-api-key...\"\n  )\n  \n  # Streaming chat with real-time responses\n  async def stream_action(session):\n    messages = [\n      {\"role\": \"user\", \"content\": \"Explain quantum computing\"}\n    ]\n    \n    async for event in metorial.stream(\n      mistral_client, session, messages, \n      model=\"mistral-large-latest\",\n      max_iterations=25\n    ):\n      if event.type == StreamEventType.CONTENT:\n        print(f\"\ud83e\udd16 {event.content}\", end=\"\", flush=True)\n      elif event.type == StreamEventType.TOOL_CALL:\n        print(f\"\\n\ud83d\udd27 Executing {len(event.tool_calls)} tool(s)...\")\n      elif event.type == StreamEventType.COMPLETE:\n        print(f\"\\n\u2705 Complete!\")\n  \n  await metorial.with_session(\"...your-server-deployment-id...\", stream_action)\n\nasyncio.run(streaming_example())\n```\n\n### Advanced Usage with Session Management\n\n```python\nimport asyncio\nfrom mistralai.client import MistralClient\nfrom mistralai.models.chat_completion import ChatMessage\nfrom metorial import Metorial\nfrom metorial_mistral import MetorialMistralSession\n\nasync def main():\n  # Initialize clients\n  metorial = Metorial(api_key=\"...your-metorial-api-key...\")\n  mistral = MistralClient(api_key=\"...your-mistral-api-key...\")\n  \n  # Create session with your server deployments\n  async with metorial.session([\"...your-server-deployment-id...\"]) as session:\n    # Create Mistral-specific wrapper\n    mistral_session = MetorialMistralSession(session.tool_manager)\n    \n    messages = [\n      ChatMessage(role=\"user\", content=\"What are the latest commits?\")\n    ]\n    \n    response = mistral.chat(\n      model=\"mistral-large-latest\",\n      messages=messages,\n      tools=mistral_session.tools\n    )\n    \n    # Handle tool calls\n    if response.choices[0].message.tool_calls:\n      tool_responses = await mistral_session.call_tools(response.choices[0].message.tool_calls)\n      \n      # Add assistant message and tool responses\n      messages.append(response.choices[0].message)\n      messages.extend(tool_responses)\n      \n      # Continue conversation...\n\nasyncio.run(main())\n```\n\n### Using Convenience Functions\n\n```python\nfrom metorial_mistral import build_mistral_tools, call_mistral_tools\n\nasync def example_with_functions():\n  # Get tools in Mistral format\n  tools = build_mistral_tools(tool_manager)\n  \n  # Call tools from Mistral response\n  tool_messages = await call_mistral_tools(tool_manager, tool_calls)\n```\n\n## API Reference\n\n### `MetorialMistralSession`\n\nMain session class for Mistral integration.\n\n```python\nsession = MetorialMistralSession(tool_manager)\n```\n\n**Properties:**\n- `tools`: List of tools in Mistral format\n\n**Methods:**\n- `async call_tools(tool_calls)`: Execute tool calls and return tool messages\n\n### `build_mistral_tools(tool_mgr)`\n\nBuild Mistral-compatible tool definitions.\n\n**Returns:** List of tool definitions in Mistral format\n\n### `call_mistral_tools(tool_mgr, tool_calls)`\n\nExecute tool calls from Mistral response.\n\n**Returns:** List of tool messages\n\n## Tool Format\n\nTools are converted to Mistral's function calling format:\n\n```python\n{\n  \"type\": \"function\",\n  \"function\": {\n    \"name\": \"tool_name\",\n    \"description\": \"Tool description\",\n    \"parameters\": {\n      \"type\": \"object\",\n      \"properties\": {...},\n      \"required\": [...]\n    },\n    \"strict\": True\n  }\n}\n```\n\n## Error Handling\n\n```python\ntry:\n    tool_messages = await mistral_session.call_tools(tool_calls)\nexcept Exception as e:\n    print(f\"Tool execution failed: {e}\")\n```\n\nTool errors are returned as tool messages with error content.\n\n## License\n\nMIT License - see [LICENSE](../../LICENSE) file for details.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Mistral AI provider for Metorial",
    "version": "1.0.4",
    "project_urls": {
        "Documentation": "https://metorial.com/docs",
        "Homepage": "https://metorial.com",
        "Repository": "https://github.com/metorial/metorial-python"
    },
    "split_keywords": [
        "ai",
        " llm",
        " metorial",
        " mistral"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "07ea3defbfe1c75af089bf75dd6c8b9dd4dfd268e4d846a8ce3baa05b4560ac3",
                "md5": "74cb579fc84dce36b7aec20a314ee2c8",
                "sha256": "91a3688a6bd5858ea5297843698028536777d67bc7f17cc4794b3ac2362d8270"
            },
            "downloads": -1,
            "filename": "metorial_mistral-1.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "74cb579fc84dce36b7aec20a314ee2c8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 5541,
            "upload_time": "2025-10-30T05:03:11",
            "upload_time_iso_8601": "2025-10-30T05:03:11.838820Z",
            "url": "https://files.pythonhosted.org/packages/07/ea/3defbfe1c75af089bf75dd6c8b9dd4dfd268e4d846a8ce3baa05b4560ac3/metorial_mistral-1.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ce4f1cd9c810364ab5c49e38502d0043b89a67736e9eee6ce599825a8efc0311",
                "md5": "1b28560da021f872ed1e93b168c9563b",
                "sha256": "02c9a3ee8f57d39e7e0966232e910b4ab362a5f2c60269cd788a7f2f11d49dab"
            },
            "downloads": -1,
            "filename": "metorial_mistral-1.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "1b28560da021f872ed1e93b168c9563b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 6553,
            "upload_time": "2025-10-30T05:03:13",
            "upload_time_iso_8601": "2025-10-30T05:03:13.409171Z",
            "url": "https://files.pythonhosted.org/packages/ce/4f/1cd9c810364ab5c49e38502d0043b89a67736e9eee6ce599825a8efc0311/metorial_mistral-1.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-30 05:03:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "metorial",
    "github_project": "metorial-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "metorial-mistral"
}
        
Elapsed time: 5.02963s