mira-network 0.1.5__py3-none-any.whl → 0.1.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mira_network/__init__.py +0 -1
- mira_network/client.py +60 -89
- mira_network/models.py +1 -1
- mira_network/sync_client.py +4 -4
- mira_network-0.1.7.dist-info/METADATA +362 -0
- mira_network-0.1.7.dist-info/RECORD +9 -0
- mira_network-0.1.7.dist-info/licenses/LICENSE +21 -0
- mira_network-0.1.5.dist-info/METADATA +0 -186
- mira_network-0.1.5.dist-info/RECORD +0 -8
- {mira_network-0.1.5.dist-info → mira_network-0.1.7.dist-info}/WHEEL +0 -0
- {mira_network-0.1.5.dist-info → mira_network-0.1.7.dist-info}/entry_points.txt +0 -0
mira_network/__init__.py
CHANGED
mira_network/client.py
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
from typing import AsyncIterator, Optional, List, Dict,
|
1
|
+
from typing import AsyncIterator, Optional, List, Dict, Union, Any
|
2
2
|
import httpx
|
3
3
|
from .models import (
|
4
4
|
AiRequest,
|
5
5
|
ApiTokenRequest,
|
6
|
+
Message,
|
6
7
|
)
|
7
8
|
|
8
9
|
|
9
10
|
class MiraClient:
|
10
|
-
|
11
11
|
def __init__(
|
12
12
|
self,
|
13
|
+
api_key: Optional[str] = None,
|
13
14
|
base_url: str = "https://apis.mira.network",
|
14
|
-
api_token: Optional[str] = None,
|
15
15
|
):
|
16
16
|
"""Initialize Mira client.
|
17
17
|
|
18
18
|
Args:
|
19
|
+
api_key: API key for authentication
|
19
20
|
base_url: Base URL of the Mira API
|
20
|
-
api_token: Optional API token for authentication
|
21
21
|
"""
|
22
22
|
self.base_url = base_url
|
23
|
-
self.
|
23
|
+
self.api_key = api_key
|
24
24
|
self._client = httpx.AsyncClient()
|
25
25
|
|
26
26
|
async def __aenter__(self):
|
@@ -31,91 +31,72 @@ class MiraClient:
|
|
31
31
|
|
32
32
|
def _get_headers(self) -> Dict[str, str]:
|
33
33
|
headers = {"Content-Type": "application/json"}
|
34
|
-
if self.
|
35
|
-
headers["Authorization"] = f"Bearer {self.
|
34
|
+
if self.api_key:
|
35
|
+
headers["Authorization"] = f"Bearer {self.api_key}"
|
36
36
|
return headers
|
37
37
|
|
38
|
-
async def
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
async def chat_completions_create(
|
39
|
+
self,
|
40
|
+
model: str,
|
41
|
+
messages: list[Message],
|
42
|
+
stream: bool = False,
|
43
|
+
**kwargs: Any,
|
44
|
+
) -> Union[Dict[str, Any], AsyncIterator[Dict[str, Any]]]:
|
45
|
+
"""Create a chat completion.
|
46
|
+
|
47
|
+
Args:
|
48
|
+
model: The model to use for completion
|
49
|
+
messages: A list of messages in the conversation
|
50
|
+
stream: Whether to stream the response
|
51
|
+
**kwargs: Additional parameters to pass to the API
|
52
|
+
"""
|
53
|
+
request = AiRequest(
|
54
|
+
model=model,
|
55
|
+
messages=messages,
|
56
|
+
stream=stream,
|
57
|
+
**kwargs,
|
43
58
|
)
|
44
|
-
response.raise_for_status()
|
45
|
-
return response.json()
|
46
59
|
|
47
|
-
async def generate(self, request: AiRequest) -> Union[str, AsyncIterator[str]]:
|
48
|
-
"""Generate text using the specified model."""
|
49
60
|
response = await self._client.post(
|
50
61
|
f"{self.base_url}/v1/chat/completions",
|
51
62
|
headers=self._get_headers(),
|
52
63
|
json=request.model_dump(),
|
53
64
|
)
|
54
|
-
|
55
65
|
response.raise_for_status()
|
56
66
|
|
57
|
-
if
|
58
|
-
return
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
# return response.json()
|
91
|
-
|
92
|
-
# async def create_flow(self, request: FlowRequest) -> Dict:
|
93
|
-
# """Create a new flow."""
|
94
|
-
# response = await self._client.post(
|
95
|
-
# f"{self.base_url}/flows",
|
96
|
-
# headers=self._get_headers(),
|
97
|
-
# json=request.model_dump(),
|
98
|
-
# )
|
99
|
-
# response.raise_for_status()
|
100
|
-
# return response.json()
|
101
|
-
|
102
|
-
# async def update_flow(self, flow_id: str, request: FlowRequest) -> Dict:
|
103
|
-
# """Update an existing flow."""
|
104
|
-
# response = await self._client.put(
|
105
|
-
# f"{self.base_url}/flows/{flow_id}",
|
106
|
-
# headers=self._get_headers(),
|
107
|
-
# json=request.model_dump(),
|
108
|
-
# )
|
109
|
-
# response.raise_for_status()
|
110
|
-
# return response.json()
|
111
|
-
|
112
|
-
# async def delete_flow(self, flow_id: str) -> None:
|
113
|
-
# """Delete a flow."""
|
114
|
-
# response = await self._client.delete(
|
115
|
-
# f"{self.base_url}/flows/{flow_id}",
|
116
|
-
# headers=self._get_headers(),
|
117
|
-
# )
|
118
|
-
# response.raise_for_status()
|
67
|
+
if stream:
|
68
|
+
return self._stream_response(response)
|
69
|
+
return response.json()
|
70
|
+
|
71
|
+
async def _stream_response(
|
72
|
+
self, response: httpx.Response
|
73
|
+
) -> AsyncIterator[Dict[str, Any]]:
|
74
|
+
"""Handle streaming response.
|
75
|
+
|
76
|
+
Args:
|
77
|
+
response: The HTTP response object
|
78
|
+
"""
|
79
|
+
async for line in response.aiter_lines():
|
80
|
+
if line.strip():
|
81
|
+
yield self._format_stream_response(line)
|
82
|
+
|
83
|
+
def _format_stream_response(self, line: str) -> Dict[str, Any]:
|
84
|
+
"""Format streaming response to match OpenAI's format.
|
85
|
+
|
86
|
+
Args:
|
87
|
+
line: The response line
|
88
|
+
"""
|
89
|
+
# Add formatting logic here if needed
|
90
|
+
return {"choices": [{"delta": {"content": line}}]}
|
91
|
+
|
92
|
+
async def list_models(self) -> List[str]:
|
93
|
+
"""List available models."""
|
94
|
+
response = await self._client.get(
|
95
|
+
f"{self.base_url}/v1/models",
|
96
|
+
headers=self._get_headers(),
|
97
|
+
)
|
98
|
+
response.raise_for_status()
|
99
|
+
return response.json()
|
119
100
|
|
120
101
|
async def create_api_token(self, request: ApiTokenRequest) -> Dict:
|
121
102
|
"""Create a new API token."""
|
@@ -153,16 +134,6 @@ class MiraClient:
|
|
153
134
|
response.raise_for_status()
|
154
135
|
return response.json()
|
155
136
|
|
156
|
-
# async def add_credit(self, request: AddCreditRequest) -> Dict:
|
157
|
-
# """Add credits to a user account."""
|
158
|
-
# response = await self._client.post(
|
159
|
-
# f"{self.base_url}/credits",
|
160
|
-
# headers=self._get_headers(),
|
161
|
-
# json=request.model_dump(),
|
162
|
-
# )
|
163
|
-
# response.raise_for_status()
|
164
|
-
# return response.json()
|
165
|
-
|
166
137
|
async def get_credits_history(self) -> List[Dict]:
|
167
138
|
"""Get user credits history."""
|
168
139
|
response = await self._client.get(
|
mira_network/models.py
CHANGED
mira_network/sync_client.py
CHANGED
@@ -10,7 +10,7 @@ class MiraSyncClient:
|
|
10
10
|
def __init__(
|
11
11
|
self,
|
12
12
|
base_url: str = "https://apis.mira.network",
|
13
|
-
|
13
|
+
api_key: Optional[str] = None,
|
14
14
|
):
|
15
15
|
"""Initialize Mira synchronous client.
|
16
16
|
|
@@ -19,7 +19,7 @@ class MiraSyncClient:
|
|
19
19
|
api_token: Optional API token for authentication
|
20
20
|
"""
|
21
21
|
self.base_url = base_url
|
22
|
-
self.
|
22
|
+
self.api_key = api_key
|
23
23
|
self._session = requests.Session()
|
24
24
|
|
25
25
|
def __enter__(self):
|
@@ -30,8 +30,8 @@ class MiraSyncClient:
|
|
30
30
|
|
31
31
|
def _get_headers(self) -> Dict[str, str]:
|
32
32
|
headers = {"Content-Type": "application/json"}
|
33
|
-
if self.
|
34
|
-
headers["Authorization"] = f"Bearer {self.
|
33
|
+
if self.api_key:
|
34
|
+
headers["Authorization"] = f"Bearer {self.api_key}"
|
35
35
|
return headers
|
36
36
|
|
37
37
|
def list_models(self) -> List[str]:
|
@@ -0,0 +1,362 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: mira-network
|
3
|
+
Version: 0.1.7
|
4
|
+
Summary: Python SDK for Mira Network API
|
5
|
+
Author-Email: mira-network <sdk@mira.network>
|
6
|
+
License: MIT
|
7
|
+
Requires-Python: <3.14,>=3.9
|
8
|
+
Requires-Dist: httpx>=0.28.1
|
9
|
+
Requires-Dist: pydantic>=2.10.4
|
10
|
+
Requires-Dist: typing-extensions>=4.8.0
|
11
|
+
Requires-Dist: requests>=2.32.3
|
12
|
+
Requires-Dist: pytest-cov>=6.0.0
|
13
|
+
Requires-Dist: pytest>=8.3.4
|
14
|
+
Requires-Dist: pytest-asyncio>=0.25.0
|
15
|
+
Requires-Dist: ruff>=0.9.3
|
16
|
+
Requires-Dist: black>=25.1.0
|
17
|
+
Description-Content-Type: text/markdown
|
18
|
+
|
19
|
+
<div align="center">
|
20
|
+
<img src="https://mira.network/_next/static/media/nav_logo.dfc4db53.svg" alt="Mira Network SDK" width="100"/>
|
21
|
+
<h1>Mira Network Python SDK</h1>
|
22
|
+
<p><strong>Your Universal Gateway to AI Language Models</strong></p>
|
23
|
+
</div>
|
24
|
+
|
25
|
+
<p align="center">
|
26
|
+
<!-- Version and Download stats -->
|
27
|
+
<a href="https://pypi.org/project/mira-network/"><img src="https://img.shields.io/pypi/v/mira-network" alt="PyPI Version"></a>
|
28
|
+
<a href="https://pypi.org/project/mira-network/"><img src="https://img.shields.io/pypi/dm/mira-network" alt="Downloads"></a>
|
29
|
+
|
30
|
+
<!-- Package metadata -->
|
31
|
+
<a href="https://pypi.org/project/mira-network/"><img src="https://img.shields.io/pypi/format/mira-network" alt="Format"></a>
|
32
|
+
<a href="https://pypi.org/project/mira-network/"><img src="https://img.shields.io/pypi/implementation/mira-network" alt="Implementation"></a>
|
33
|
+
|
34
|
+
<!-- License -->
|
35
|
+
<a href="https://pypi.org/project/mira-network/"><img src="https://img.shields.io/pypi/l/mira-network" alt="License"></a>
|
36
|
+
|
37
|
+
<!-- Build Status -->
|
38
|
+
<a href="https://github.com/Aroha-Labs/mira-network/actions/workflows/ci-sdk.yml">
|
39
|
+
<img src="https://github.com/Aroha-Labs/mira-network/actions/workflows/ci-sdk.yml/badge.svg" alt="Build Status">
|
40
|
+
</a>
|
41
|
+
</p>
|
42
|
+
|
43
|
+
<p align="center">
|
44
|
+
<b>Mira Client enables seamless integration with multiple language models while providing advanced routing, load balancing, and flow management capabilities.</b>
|
45
|
+
</p>
|
46
|
+
|
47
|
+
---
|
48
|
+
|
49
|
+
## 🌟 What is Mira Network?
|
50
|
+
|
51
|
+
Mira Network is your unified interface to the world of AI language models. It provides:
|
52
|
+
|
53
|
+
- 🔄 **Smart Model Routing**: Route requests across different models
|
54
|
+
- ⚖️ **Load Balancing**: Distribute workload across nodes
|
55
|
+
- 🌊 **Flow Management**: Handle request patterns efficiently
|
56
|
+
- 🔌 **Universal Integration**: Single API for multiple models
|
57
|
+
- 📊 **Usage Tracking**: Monitor your model usage
|
58
|
+
|
59
|
+
## Why Mira Network SDK?
|
60
|
+
|
61
|
+
| Feature | Mira SDK | Traditional Approach |
|
62
|
+
| ---------------------- | -------------------------- | ----------------------- |
|
63
|
+
| 🔄 Multi-model Support | Single unified API | Separate APIs per model |
|
64
|
+
| ⚖️ Load Balancing | Built-in | Custom implementation |
|
65
|
+
| 🌊 Flow Control | Automatic handling | Manual implementation |
|
66
|
+
| 📊 Usage Tracking | Integrated | Custom tracking needed |
|
67
|
+
| 🛡️ Error Handling | Standardized across models | Model-specific handling |
|
68
|
+
|
69
|
+
## 🎯 Perfect For
|
70
|
+
|
71
|
+
- 🤖 AI Applications
|
72
|
+
- 📝 Text Generation
|
73
|
+
- 🔍 Search Enhancement
|
74
|
+
- 🎮 Interactive Systems
|
75
|
+
|
76
|
+
## 🏃 Quick Start
|
77
|
+
|
78
|
+
```bash
|
79
|
+
pip install mira-network
|
80
|
+
```
|
81
|
+
|
82
|
+
```python
|
83
|
+
from mira_network import MiraClient
|
84
|
+
|
85
|
+
async def get_ai_response(prompt):
|
86
|
+
async with MiraClient() as client:
|
87
|
+
return await client.chat_completions_create(
|
88
|
+
model="your-chosen-model",
|
89
|
+
messages=[{"role": "user", "content": prompt}]
|
90
|
+
)
|
91
|
+
```
|
92
|
+
|
93
|
+
## 🏗️ Architecture
|
94
|
+
|
95
|
+
```mermaid
|
96
|
+
graph LR
|
97
|
+
A[Your App] --> B[Mira SDK]
|
98
|
+
B --> C[Load Balancer]
|
99
|
+
C --> D[Mira Node 1]
|
100
|
+
C --> E[Mira Node 2]
|
101
|
+
C --> F[Mira Node N]
|
102
|
+
```
|
103
|
+
|
104
|
+
## ✨ Key Features
|
105
|
+
|
106
|
+
- 🔌 Simple, intuitive API
|
107
|
+
- 🔄 Async-first design
|
108
|
+
- 🌊 Streaming support
|
109
|
+
- 🔐 Error handling
|
110
|
+
- 🛠️ Customizable nodes
|
111
|
+
- 📊 Usage tracking
|
112
|
+
|
113
|
+
## 📑 Table of Contents
|
114
|
+
|
115
|
+
- [Installation](#installation)
|
116
|
+
- [Quick Start](#-quick-start)
|
117
|
+
- [Basic Usage](#-basic-usage)
|
118
|
+
- [Advanced Usage](#-advanced-usage)
|
119
|
+
- [API Reference](#-reference)
|
120
|
+
- [Support](#-support)
|
121
|
+
- [Contributing](#-contributing)
|
122
|
+
- [License](#-license)
|
123
|
+
|
124
|
+
## 🔧 Installation
|
125
|
+
|
126
|
+
Install the SDK using pip:
|
127
|
+
|
128
|
+
```bash
|
129
|
+
pip install mira-network
|
130
|
+
```
|
131
|
+
|
132
|
+
## 🚀 Quick Start
|
133
|
+
|
134
|
+
Experience the power of Mira Network in just a few lines of code:
|
135
|
+
|
136
|
+
```python
|
137
|
+
from mira_network import MiraClient
|
138
|
+
|
139
|
+
async def main():
|
140
|
+
# Initialize with your API key
|
141
|
+
client = MiraClient(api_key="your-api-key")
|
142
|
+
|
143
|
+
# Get a response from AI
|
144
|
+
response = await client.chat_completions_create(
|
145
|
+
model="your-chosen-model",
|
146
|
+
messages=[
|
147
|
+
{"role": "user", "content": "What is the capital of France?"}
|
148
|
+
]
|
149
|
+
)
|
150
|
+
|
151
|
+
# Print the AI's response
|
152
|
+
print(response["choices"][0]["message"]["content"])
|
153
|
+
|
154
|
+
if __name__ == "__main__":
|
155
|
+
import asyncio
|
156
|
+
asyncio.run(main())
|
157
|
+
```
|
158
|
+
|
159
|
+
## 📝 Basic Usage
|
160
|
+
|
161
|
+
### Having a Conversation
|
162
|
+
|
163
|
+
Engage in natural conversations with AI models. The SDK handles the complexities of managing conversation context and model interactions:
|
164
|
+
|
165
|
+
```python
|
166
|
+
response = await client.chat_completions_create(
|
167
|
+
model="your-chosen-model",
|
168
|
+
messages=[
|
169
|
+
{"role": "system", "content": "You are a helpful assistant"},
|
170
|
+
{"role": "user", "content": "Hi! Can you help me?"},
|
171
|
+
]
|
172
|
+
)
|
173
|
+
```
|
174
|
+
|
175
|
+
### Checking Available Models
|
176
|
+
|
177
|
+
Explore the diverse range of available AI models:
|
178
|
+
|
179
|
+
```python
|
180
|
+
models = await client.list_models()
|
181
|
+
print(models)
|
182
|
+
```
|
183
|
+
|
184
|
+
### Checking Your Credits
|
185
|
+
|
186
|
+
Monitor your usage and available credits:
|
187
|
+
|
188
|
+
```python
|
189
|
+
credits = await client.get_user_credits()
|
190
|
+
print(credits)
|
191
|
+
```
|
192
|
+
|
193
|
+
## 🔧 Advanced Usage
|
194
|
+
|
195
|
+
### Streaming Responses
|
196
|
+
|
197
|
+
Perfect for real-time applications and interactive experiences:
|
198
|
+
|
199
|
+
```python
|
200
|
+
stream = await client.chat_completions_create(
|
201
|
+
model="your-chosen-model",
|
202
|
+
messages=[
|
203
|
+
{"role": "user", "content": "Write a story"}
|
204
|
+
],
|
205
|
+
stream=True
|
206
|
+
)
|
207
|
+
|
208
|
+
async for chunk in stream:
|
209
|
+
print(chunk["choices"][0]["delta"]["content"], end="")
|
210
|
+
```
|
211
|
+
|
212
|
+
### Custom Mira Nodes
|
213
|
+
|
214
|
+
Integrate your preferred Mira nodes seamlessly:
|
215
|
+
|
216
|
+
```python
|
217
|
+
response = await client.chat_completions_create(
|
218
|
+
model="your-model",
|
219
|
+
messages=[{"role": "user", "content": "Hello"}],
|
220
|
+
mira_node={
|
221
|
+
"base_url": "https://custom-node.com",
|
222
|
+
"api_key": "node-api-key"
|
223
|
+
}
|
224
|
+
)
|
225
|
+
```
|
226
|
+
|
227
|
+
### API Token Management
|
228
|
+
|
229
|
+
Secure and flexible token management for your applications:
|
230
|
+
|
231
|
+
```python
|
232
|
+
# Create new token
|
233
|
+
new_token = await client.create_api_token(
|
234
|
+
{"description": "Production API Key"}
|
235
|
+
)
|
236
|
+
|
237
|
+
# List tokens
|
238
|
+
tokens = await client.list_api_tokens()
|
239
|
+
|
240
|
+
# Delete token
|
241
|
+
await client.delete_api_token("token-id")
|
242
|
+
```
|
243
|
+
|
244
|
+
### Using as Context Manager
|
245
|
+
|
246
|
+
Efficient resource management with context managers:
|
247
|
+
|
248
|
+
```python
|
249
|
+
async with MiraClient(api_key="your-api-key") as client:
|
250
|
+
response = await client.chat_completions_create(...)
|
251
|
+
```
|
252
|
+
|
253
|
+
## 📚 Reference
|
254
|
+
|
255
|
+
### Message Structure
|
256
|
+
|
257
|
+
Understanding the core message components:
|
258
|
+
|
259
|
+
```python
|
260
|
+
Message:
|
261
|
+
role: str # "system", "user", or "assistant"
|
262
|
+
content: str # The message content
|
263
|
+
```
|
264
|
+
|
265
|
+
### Error Handling
|
266
|
+
|
267
|
+
Robust error handling for production applications:
|
268
|
+
|
269
|
+
#### Validation Errors
|
270
|
+
|
271
|
+
```python
|
272
|
+
try:
|
273
|
+
response = await client.chat_completions_create(
|
274
|
+
model="your-chosen-model",
|
275
|
+
messages=[
|
276
|
+
{"role": "invalid", "content": "Hello"} # Invalid role
|
277
|
+
]
|
278
|
+
)
|
279
|
+
except ValueError as e:
|
280
|
+
print(f"Validation error: {e}")
|
281
|
+
```
|
282
|
+
|
283
|
+
#### Network Errors
|
284
|
+
|
285
|
+
```python
|
286
|
+
try:
|
287
|
+
response = await client.chat_completions_create(...)
|
288
|
+
except httpx.HTTPError as e:
|
289
|
+
print(f"HTTP error: {e}")
|
290
|
+
```
|
291
|
+
|
292
|
+
### Environment Configuration
|
293
|
+
|
294
|
+
Flexible configuration options for different environments:
|
295
|
+
|
296
|
+
```python
|
297
|
+
import os
|
298
|
+
from mira_network import MiraClient
|
299
|
+
|
300
|
+
client = MiraClient(
|
301
|
+
api_key=os.getenv("MIRA_API_KEY"),
|
302
|
+
base_url=os.getenv("MIRA_API_URL", "https://apis.mira.network")
|
303
|
+
)
|
304
|
+
```
|
305
|
+
|
306
|
+
## 💡 Real-world Examples
|
307
|
+
|
308
|
+
### AI-powered Customer Service
|
309
|
+
|
310
|
+
```python
|
311
|
+
async def handle_customer_query(query: str) -> str:
|
312
|
+
async with MiraClient() as client:
|
313
|
+
response = await client.chat_completions_create(
|
314
|
+
model="your-chosen-model",
|
315
|
+
messages=[
|
316
|
+
{"role": "system", "content": "You are a helpful customer service agent."},
|
317
|
+
{"role": "user", "content": query}
|
318
|
+
],
|
319
|
+
temperature=0.7,
|
320
|
+
max_tokens=150
|
321
|
+
)
|
322
|
+
return response.choices[0].message.content
|
323
|
+
```
|
324
|
+
|
325
|
+
### Content Generation Pipeline
|
326
|
+
|
327
|
+
```python
|
328
|
+
async def generate_blog_post(topic: str) -> dict:
|
329
|
+
async with MiraClient() as client:
|
330
|
+
# Generate outline
|
331
|
+
outline = await client.chat_completions_create(...)
|
332
|
+
|
333
|
+
# Generate content
|
334
|
+
content = await client.chat_completions_create(...)
|
335
|
+
|
336
|
+
# Generate meta description
|
337
|
+
meta = await client.chat_completions_create(...)
|
338
|
+
|
339
|
+
return {"outline": outline, "content": content, "meta": meta}
|
340
|
+
```
|
341
|
+
|
342
|
+
## 🤝 Support
|
343
|
+
|
344
|
+
For feature requests and bug reports, please visit our [Console Feedback](https://console-feedback.arohalabs.tech/).
|
345
|
+
|
346
|
+
## 👥 Contributing
|
347
|
+
|
348
|
+
We welcome contributions! Here's how you can help:
|
349
|
+
|
350
|
+
1. Fork the repository
|
351
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
352
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
353
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
354
|
+
5. Open a Pull Request
|
355
|
+
|
356
|
+
## 📄 License
|
357
|
+
|
358
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
359
|
+
|
360
|
+
---
|
361
|
+
|
362
|
+
<p align="center">Built with ❤️ by the Mira Network team</p>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
mira_network-0.1.7.dist-info/METADATA,sha256=26Wnxl4rxw73IIN5XtBJZ4LuVkr5js5OR333QYXDtfE,9478
|
2
|
+
mira_network-0.1.7.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
|
3
|
+
mira_network-0.1.7.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
4
|
+
mira_network-0.1.7.dist-info/licenses/LICENSE,sha256=bOPoXuA3yH-uo70eTxPrRY4aiy8NkZDVkI8ZVagZIfc,1069
|
5
|
+
mira_network/__init__.py,sha256=h4vgSUv520lY8Ij_k5GclS9elYe1gXKfDnq70Zu-7Og,232
|
6
|
+
mira_network/client.py,sha256=ykbdbjp5rS0ZSbN7w_SEd57_Hvo1yjExX3ojGjaoSx4,4390
|
7
|
+
mira_network/models.py,sha256=VkJjAmVIx3L5U3G0WVcdcEAXnNgud5gjRVfGGsYVtvQ,1799
|
8
|
+
mira_network/sync_client.py,sha256=Q5gzIx92mfFsS90hogtzvjNC51tL6zC4HZzQoK0oJ-Q,3389
|
9
|
+
mira_network-0.1.7.dist-info/RECORD,,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Mira Network
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -1,186 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: mira-network
|
3
|
-
Version: 0.1.5
|
4
|
-
Summary: Python SDK for Mira Network API
|
5
|
-
Author-Email: sarim2000 <sarimbleedblue@gmail.com>
|
6
|
-
License: MIT
|
7
|
-
Requires-Python: ==3.10.*
|
8
|
-
Requires-Dist: httpx>=0.28.1
|
9
|
-
Requires-Dist: pydantic>=2.10.4
|
10
|
-
Requires-Dist: typing-extensions>=4.8.0
|
11
|
-
Requires-Dist: requests>=2.32.3
|
12
|
-
Requires-Dist: pytest-cov>=6.0.0
|
13
|
-
Description-Content-Type: text/markdown
|
14
|
-
|
15
|
-
# Mira Network SDK
|
16
|
-
|
17
|
-
A Python SDK for interacting with the Mira Network API. This SDK provides both synchronous and asynchronous interfaces to access Mira API endpoints for model inference, API token management, and credit system operations.
|
18
|
-
|
19
|
-
## Installation
|
20
|
-
|
21
|
-
```bash
|
22
|
-
pip install mira-network
|
23
|
-
```
|
24
|
-
|
25
|
-
## Quick Start
|
26
|
-
|
27
|
-
### Synchronous Usage
|
28
|
-
|
29
|
-
```python
|
30
|
-
from mira_network.sync_client import MiraSyncClient
|
31
|
-
from mira_network.models import AiRequest, Message
|
32
|
-
|
33
|
-
# Using context manager (recommended)
|
34
|
-
with MiraSyncClient(api_token="your-api-token") as client: # base_url defaults to https://apis.mira.network/
|
35
|
-
# Example 1: Non-streaming response
|
36
|
-
request = AiRequest(
|
37
|
-
messages=[
|
38
|
-
Message(role="system", content="You are a helpful assistant."),
|
39
|
-
Message(role="user", content="Hello!")
|
40
|
-
],
|
41
|
-
stream=False
|
42
|
-
)
|
43
|
-
response = client.generate(request)
|
44
|
-
print(response)
|
45
|
-
|
46
|
-
# Example 2: Streaming response
|
47
|
-
stream_request = AiRequest(
|
48
|
-
messages=[
|
49
|
-
Message(role="system", content="You are a helpful assistant."),
|
50
|
-
Message(role="user", content="Tell me a story!")
|
51
|
-
],
|
52
|
-
stream=True
|
53
|
-
)
|
54
|
-
for chunk in client.generate(stream_request):
|
55
|
-
print(chunk)
|
56
|
-
```
|
57
|
-
|
58
|
-
### Asynchronous Usage
|
59
|
-
|
60
|
-
```python
|
61
|
-
import asyncio
|
62
|
-
from mira_network.client import MiraClient
|
63
|
-
from mira_network.models import AiRequest, Message
|
64
|
-
|
65
|
-
async def main():
|
66
|
-
# Using async context manager (recommended)
|
67
|
-
async with MiraClient(api_token="your-api-token") as client: # base_url defaults to https://apis.mira.network/
|
68
|
-
# Example 1: Non-streaming response
|
69
|
-
request = AiRequest(
|
70
|
-
messages=[
|
71
|
-
Message(role="system", content="You are a helpful assistant."),
|
72
|
-
Message(role="user", content="Hello!")
|
73
|
-
],
|
74
|
-
model="gpt-4o",
|
75
|
-
model_provider=None,
|
76
|
-
stream=False
|
77
|
-
)
|
78
|
-
response = await client.generate(request)
|
79
|
-
print(response)
|
80
|
-
|
81
|
-
# Example 2: Streaming response
|
82
|
-
stream_request = AiRequest(
|
83
|
-
messages=[
|
84
|
-
Message(role="system", content="You are a helpful assistant."),
|
85
|
-
Message(role="user", content="Tell me a story!")
|
86
|
-
],
|
87
|
-
stream=True
|
88
|
-
)
|
89
|
-
async for chunk in await client.generate(stream_request):
|
90
|
-
print(chunk)
|
91
|
-
|
92
|
-
if __name__ == "__main__":
|
93
|
-
asyncio.run(main())
|
94
|
-
```
|
95
|
-
|
96
|
-
## API Reference
|
97
|
-
|
98
|
-
### Client Initialization
|
99
|
-
|
100
|
-
The SDK provides two client classes:
|
101
|
-
- `MiraSyncClient`: Synchronous client using `requests`
|
102
|
-
- `MiraClient`: Asynchronous client using `httpx`
|
103
|
-
|
104
|
-
Both clients support context managers for proper resource cleanup:
|
105
|
-
|
106
|
-
```python
|
107
|
-
# Synchronous
|
108
|
-
with MiraSyncClient(
|
109
|
-
api_token="your-api-token",
|
110
|
-
base_url="https://apis.mira.network/" # Optional, this is the default
|
111
|
-
) as client:
|
112
|
-
# Your sync code here
|
113
|
-
|
114
|
-
# Asynchronous
|
115
|
-
async with MiraClient(
|
116
|
-
api_token="your-api-token",
|
117
|
-
base_url="https://apis.mira.network/" # Optional, this is the default
|
118
|
-
) as client:
|
119
|
-
# Your async code here
|
120
|
-
```
|
121
|
-
|
122
|
-
### Models
|
123
|
-
|
124
|
-
- `Message`: Represents a chat message
|
125
|
-
- `role`: String ("system", "user", or "assistant")
|
126
|
-
- `content`: String content of the message
|
127
|
-
|
128
|
-
- `AiRequest`: Configuration for model inference
|
129
|
-
- `model`: Model identifier (default: "mira/llama3.1")
|
130
|
-
- `messages`: List of Message objects
|
131
|
-
- `stream`: Boolean to enable streaming responses (default: False)
|
132
|
-
- `model_provider`: Optional ModelProvider configuration
|
133
|
-
|
134
|
-
- `ModelProvider`: Custom provider configuration
|
135
|
-
- `base_url`: Provider's base URL
|
136
|
-
- `api_key`: Provider's API key
|
137
|
-
|
138
|
-
- `ApiTokenRequest`: Request for creating API tokens
|
139
|
-
- `description`: Optional description for the token
|
140
|
-
|
141
|
-
### Available Methods
|
142
|
-
|
143
|
-
Both sync and async clients provide the same methods with identical parameters. The only difference is that async methods must be awaited.
|
144
|
-
|
145
|
-
#### Model Operations
|
146
|
-
```python
|
147
|
-
# Sync
|
148
|
-
models = client.list_models()
|
149
|
-
response = client.generate(AiRequest(messages=[...], stream=False))
|
150
|
-
for chunk in client.generate(AiRequest(messages=[...], stream=True)):
|
151
|
-
print(chunk)
|
152
|
-
|
153
|
-
# Async
|
154
|
-
models = await client.list_models()
|
155
|
-
response = await client.generate(AiRequest(messages=[...], stream=False))
|
156
|
-
async for chunk in await client.generate(AiRequest(messages=[...], stream=True)):
|
157
|
-
print(chunk)
|
158
|
-
```
|
159
|
-
|
160
|
-
#### API Token Operations
|
161
|
-
```python
|
162
|
-
# Sync
|
163
|
-
token = client.create_api_token(ApiTokenRequest(description="My Token"))
|
164
|
-
tokens = client.list_api_tokens()
|
165
|
-
client.delete_api_token("token-to-delete")
|
166
|
-
|
167
|
-
# Async
|
168
|
-
token = await client.create_api_token(ApiTokenRequest(description="My Token"))
|
169
|
-
tokens = await client.list_api_tokens()
|
170
|
-
await client.delete_api_token("token-to-delete")
|
171
|
-
```
|
172
|
-
|
173
|
-
#### Credit Operations
|
174
|
-
```python
|
175
|
-
# Sync
|
176
|
-
credits = client.get_user_credits()
|
177
|
-
history = client.get_credits_history()
|
178
|
-
|
179
|
-
# Async
|
180
|
-
credits = await client.get_user_credits()
|
181
|
-
history = await client.get_credits_history()
|
182
|
-
```
|
183
|
-
|
184
|
-
## License
|
185
|
-
|
186
|
-
MIT License
|
@@ -1,8 +0,0 @@
|
|
1
|
-
mira_network-0.1.5.dist-info/METADATA,sha256=Q9jRYiP-Oo6ecT8iBgCIxi4pT-4nbHwuEP-8vgZ2OEc,5353
|
2
|
-
mira_network-0.1.5.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
|
3
|
-
mira_network-0.1.5.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
4
|
-
mira_network/__init__.py,sha256=82x6bhP9_ZhHaBkW-O10F4ADipp1crGQzTaxQ878buA,272
|
5
|
-
mira_network/client.py,sha256=HEqj1G1VfDZxZ3Kh2YPNBeUMlB5Pb56HBSvh80Wde2c,5738
|
6
|
-
mira_network/models.py,sha256=aEJiDHEDFIAQMB-C8ZFY5ruRNGJ-U2Cz9vS5nF7GqVg,1805
|
7
|
-
mira_network/sync_client.py,sha256=vAiQG0SDHO9aROklnPqr0m-AsPIyL8wNfA0L7h5EhPg,3399
|
8
|
-
mira_network-0.1.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|