Python SDK for Mira Network API
Project description
Mira Network Python SDK
Your Universal Gateway to AI Language Models
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:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mira_network-0.1.7.tar.gz.
File metadata
- Download URL: mira_network-0.1.7.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a8527c461409ccf8c8901e5aa6ddfe988e594a19500f9ead7e1a419fb2d958c
|
|
| MD5 |
c889bc4913b85e962272062f3d9c909a
|
|
| BLAKE2b-256 |
8921ad9aa7e6e19f85938aeabf0d23e58bb16036b001f7f98c80aa508b65d036
|
File details
Details for the file mira_network-0.1.7-py3-none-any.whl.
File metadata
- Download URL: mira_network-0.1.7-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fb423076037029040264a32da6dfbd58e4b8cebe0aa7e97dfe5dd17270880b5
|
|
| MD5 |
7fe5f01c65355653f3490f75ee016660
|
|
| BLAKE2b-256 |
bd5150b215bb7b47ce2f402dd120229333ecbe4bff8a26b7c8bad5fff216c81b
|