Skip to main content

Python SDK for Mira Network API

Project description

Mira Network SDK

Mira Network Python SDK

Your Universal Gateway to AI Language Models

PyPI Version Downloads

Format Implementation

License

Build Status

Mira Client enables seamless integration with multiple language models while providing advanced routing, load balancing, and flow management capabilities.


๐ŸŒŸ What is Mira Network?

Mira Network is your unified interface to the world of AI language models. It provides:

  • ๐Ÿ”„ Smart Model Routing: Route requests across different models
  • โš–๏ธ Load Balancing: Distribute workload across nodes
  • ๐ŸŒŠ Flow Management: Handle request patterns efficiently
  • ๐Ÿ”Œ Universal Integration: Single API for multiple models
  • ๐Ÿ“Š Usage Tracking: Monitor your model usage

Why Mira Network SDK?

Feature Mira SDK Traditional Approach
๐Ÿ”„ Multi-model Support Single unified API Separate APIs per model
โš–๏ธ Load Balancing Built-in Custom implementation
๐ŸŒŠ Flow Control Automatic handling Manual implementation
๐Ÿ“Š Usage Tracking Integrated Custom tracking needed
๐Ÿ›ก๏ธ Error Handling Standardized across models Model-specific handling

๐ŸŽฏ Perfect For

  • ๐Ÿค– AI Applications
  • ๐Ÿ“ Text Generation
  • ๐Ÿ” Search Enhancement
  • ๐ŸŽฎ Interactive Systems

๐Ÿƒ Quick Start

pip install mira-network
from mira_network import MiraClient

async def get_ai_response(prompt):
    async with MiraClient() as client:
        return await client.chat_completions_create(
            model="your-chosen-model",
            messages=[{"role": "user", "content": prompt}]
        )

๐Ÿ—๏ธ Architecture

graph LR
    A[Your App] --> B[Mira SDK]
    B --> C[Load Balancer]
    C --> D[Mira Node 1]
    C --> E[Mira Node 2]
    C --> F[Mira Node N]

โœจ Key Features

  • ๐Ÿ”Œ Simple, intuitive API
  • ๐Ÿ”„ Async-first design
  • ๐ŸŒŠ Streaming support
  • ๐Ÿ” Error handling
  • ๐Ÿ› ๏ธ Customizable nodes
  • ๐Ÿ“Š Usage tracking

๐Ÿ“‘ Table of Contents

๐Ÿ”ง Installation

Install the SDK using pip:

pip install mira-network

๐Ÿš€ Quick Start

Experience the power of Mira Network in just a few lines of code:

from mira_network import MiraClient

async def main():
    # Initialize with your API key
    client = MiraClient(api_key="your-api-key")

    # Get a response from AI
    response = await client.chat_completions_create(
        model="your-chosen-model",
        messages=[
            {"role": "user", "content": "What is the capital of France?"}
        ]
    )

    # Print the AI's response
    print(response["choices"][0]["message"]["content"])

if __name__ == "__main__":
    import asyncio
    asyncio.run(main())

๐Ÿ“ Basic Usage

Having a Conversation

Engage in natural conversations with AI models. The SDK handles the complexities of managing conversation context and model interactions:

response = await client.chat_completions_create(
    model="your-chosen-model",
    messages=[
        {"role": "system", "content": "You are a helpful assistant"},
        {"role": "user", "content": "Hi! Can you help me?"},
    ]
)

Checking Available Models

Explore the diverse range of available AI models:

models = await client.list_models()
print(models)

Checking Your Credits

Monitor your usage and available credits:

credits = await client.get_user_credits()
print(credits)

๐Ÿ”ง Advanced Usage

Streaming Responses

Perfect for real-time applications and interactive experiences:

stream = await client.chat_completions_create(
    model="your-chosen-model",
    messages=[
        {"role": "user", "content": "Write a story"}
    ],
    stream=True
)

async for chunk in stream:
    print(chunk["choices"][0]["delta"]["content"], end="")

Custom Mira Nodes

Integrate your preferred Mira nodes seamlessly:

response = await client.chat_completions_create(
    model="your-model",
    messages=[{"role": "user", "content": "Hello"}],
    mira_node={
        "base_url": "https://custom-node.com",
        "api_key": "node-api-key"
    }
)

API Token Management

Secure and flexible token management for your applications:

# Create new token
new_token = await client.create_api_token(
    {"description": "Production API Key"}
)

# List tokens
tokens = await client.list_api_tokens()

# Delete token
await client.delete_api_token("token-id")

Using as Context Manager

Efficient resource management with context managers:

async with MiraClient(api_key="your-api-key") as client:
    response = await client.chat_completions_create(...)

๐Ÿ“š Reference

Message Structure

Understanding the core message components:

Message:
    role: str       # "system", "user", or "assistant"
    content: str    # The message content

Error Handling

Robust error handling for production applications:

Validation Errors

try:
    response = await client.chat_completions_create(
        model="your-chosen-model",
        messages=[
            {"role": "invalid", "content": "Hello"}  # Invalid role
        ]
    )
except ValueError as e:
    print(f"Validation error: {e}")

Network Errors

try:
    response = await client.chat_completions_create(...)
except httpx.HTTPError as e:
    print(f"HTTP error: {e}")

Environment Configuration

Flexible configuration options for different environments:

import os
from mira_network import MiraClient

client = MiraClient(
    api_key=os.getenv("MIRA_API_KEY"),
    base_url=os.getenv("MIRA_API_URL", "https://apis.mira.network")
)

๐Ÿ’ก Real-world Examples

AI-powered Customer Service

async def handle_customer_query(query: str) -> str:
    async with MiraClient() as client:
        response = await client.chat_completions_create(
            model="your-chosen-model",
            messages=[
                {"role": "system", "content": "You are a helpful customer service agent."},
                {"role": "user", "content": query}
            ],
            temperature=0.7,
            max_tokens=150
        )
        return response.choices[0].message.content

Content Generation Pipeline

async def generate_blog_post(topic: str) -> dict:
    async with MiraClient() as client:
        # Generate outline
        outline = await client.chat_completions_create(...)

        # Generate content
        content = await client.chat_completions_create(...)

        # Generate meta description
        meta = await client.chat_completions_create(...)

        return {"outline": outline, "content": content, "meta": meta}

๐Ÿค Support

For feature requests and bug reports, please visit our Console Feedback.

๐Ÿ‘ฅ Contributing

We welcome contributions! Here's how you can help:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with โค๏ธ by the Mira Network team

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

mira_network-0.1.8.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

mira_network-0.1.8-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file mira_network-0.1.8.tar.gz.

File metadata

  • Download URL: mira_network-0.1.8.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.21.0 CPython/3.10.15 Darwin/24.3.0

File hashes

Hashes for mira_network-0.1.8.tar.gz
Algorithm Hash digest
SHA256 4f25157705971237c0d404dc69e2d8966a0a40cbf5d13766a47a73c33f5802f2
MD5 6a83507dd1eb200b7ba49e2ae4941454
BLAKE2b-256 1f4ff40fc468cc696cab49a611de9550734c6d6d15d94dae5e43f3b47b092e56

See more details on using hashes here.

File details

Details for the file mira_network-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: mira_network-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.21.0 CPython/3.10.15 Darwin/24.3.0

File hashes

Hashes for mira_network-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 b2cb133370f3ac9864983a41cf8ecc8ba5e733275b4110d7a69549ebb670c02f
MD5 ff18c7a3fe470cc116adcc0e8049ac14
BLAKE2b-256 ad7075779c61f5bcd037e18da2785692b2308bb9c1f3ec257cc68ea89252e103

See more details on using hashes here.

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