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.9.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.9-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mira_network-0.1.9.tar.gz
Algorithm Hash digest
SHA256 30f06ae4619cffbc80b332bd25f598fb90e24ec4f52a75e0a0f2b28e56f68ba6
MD5 852ba67ba8c51a1d5fd89bf7711eeff3
BLAKE2b-256 efdbc1361a91afba95a268e53d888964ddc564b624e69c11b209d098d2d18d3a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mira_network-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.3 CPython/3.11.11 Darwin/24.3.0

File hashes

Hashes for mira_network-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 48c93259b17901a0f014cdc9fb643cb1f16cac58a24f5985e9c1b68b6384d35d
MD5 1bf9bc487f866c33f354c748ea6d9d5b
BLAKE2b-256 6ca7870229034c1f664d07ac95e72e982ff7a4bc020752ba598ca427e24bb665

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