mira-network 0.1.0__py3-none-any.whl → 0.1.2__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-0.1.2.dist-info/METADATA +107 -0
- mira_network-0.1.2.dist-info/RECORD +7 -0
- {mira_network-0.1.0.dist-info → mira_network-0.1.2.dist-info}/WHEEL +1 -2
- mira_network-0.1.2.dist-info/entry_points.txt +4 -0
- mira_sdk/__init__.py +21 -0
- mira_sdk/client.py +180 -0
- mira_sdk/models.py +67 -0
- mira_network/__init__.py +0 -0
- mira_network/client.py +0 -8
- mira_network-0.1.0.dist-info/METADATA +0 -10
- mira_network-0.1.0.dist-info/RECORD +0 -6
- mira_network-0.1.0.dist-info/top_level.txt +0 -1
@@ -0,0 +1,107 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: mira-network
|
3
|
+
Version: 0.1.2
|
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
|
+
Description-Content-Type: text/markdown
|
13
|
+
|
14
|
+
# Mira Network SDK
|
15
|
+
|
16
|
+
A Python SDK for interacting with the Mira Network API. This SDK provides a simple interface to access all Mira API endpoints including model inference, flow management, and credit system.
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
```bash
|
21
|
+
pip install mira-network
|
22
|
+
```
|
23
|
+
|
24
|
+
## Quick Start
|
25
|
+
|
26
|
+
```python
|
27
|
+
import asyncio
|
28
|
+
from mira_sdk import MiraClient, Message, AiRequest
|
29
|
+
|
30
|
+
async def main():
|
31
|
+
# Initialize client
|
32
|
+
client = MiraClient(
|
33
|
+
base_url="https://api.mira.example.com",
|
34
|
+
api_token="your-api-token"
|
35
|
+
)
|
36
|
+
|
37
|
+
# List available models
|
38
|
+
models = await client.list_models()
|
39
|
+
print("Available models:", models)
|
40
|
+
|
41
|
+
# Generate text
|
42
|
+
request = AiRequest(
|
43
|
+
model="mira/llama3.1",
|
44
|
+
messages=[
|
45
|
+
Message(role="system", content="You are a helpful assistant."),
|
46
|
+
Message(role="user", content="Hello!")
|
47
|
+
],
|
48
|
+
model_provider=None
|
49
|
+
)
|
50
|
+
|
51
|
+
response = await client.generate(request)
|
52
|
+
print("Response:", response)
|
53
|
+
|
54
|
+
if __name__ == "__main__":
|
55
|
+
asyncio.run(main())
|
56
|
+
```
|
57
|
+
|
58
|
+
## Features
|
59
|
+
|
60
|
+
- Asynchronous API using `httpx`
|
61
|
+
- Full type hints support
|
62
|
+
- Pydantic models for request/response validation
|
63
|
+
- Support for all Mira API endpoints:
|
64
|
+
- Model inference
|
65
|
+
- Flow management
|
66
|
+
- API token management
|
67
|
+
- Credit system
|
68
|
+
|
69
|
+
## API Reference
|
70
|
+
|
71
|
+
### Models
|
72
|
+
|
73
|
+
- `Message`: Represents a chat message
|
74
|
+
- `ModelProvider`: Configuration for custom model providers
|
75
|
+
- `AiRequest`: Request for model inference
|
76
|
+
- `FlowChatCompletion`: Request for flow-based chat completion
|
77
|
+
- `FlowRequest`: Request for creating/updating flows
|
78
|
+
- `ApiTokenRequest`: Request for creating API tokens
|
79
|
+
- `AddCreditRequest`: Request for adding credits
|
80
|
+
|
81
|
+
### Client Methods
|
82
|
+
|
83
|
+
#### Model Operations
|
84
|
+
- `list_models()`: List available models
|
85
|
+
- `generate(request: AiRequest)`: Generate text using specified model
|
86
|
+
|
87
|
+
#### Flow Operations
|
88
|
+
- `list_flows()`: List all flows
|
89
|
+
- `get_flow(flow_id: str)`: Get flow details
|
90
|
+
- `create_flow(request: FlowRequest)`: Create new flow
|
91
|
+
- `update_flow(flow_id: str, request: FlowRequest)`: Update flow
|
92
|
+
- `delete_flow(flow_id: str)`: Delete flow
|
93
|
+
- `generate_with_flow(flow_id: str, request: FlowChatCompletion)`: Generate using flow
|
94
|
+
|
95
|
+
#### Token Operations
|
96
|
+
- `create_api_token(request: ApiTokenRequest)`: Create API token
|
97
|
+
- `list_api_tokens()`: List API tokens
|
98
|
+
- `delete_api_token(token: str)`: Delete API token
|
99
|
+
|
100
|
+
#### Credit Operations
|
101
|
+
- `get_user_credits()`: Get credit information
|
102
|
+
- `add_credit(request: AddCreditRequest)`: Add credits
|
103
|
+
- `get_credits_history()`: Get credit history
|
104
|
+
|
105
|
+
## License
|
106
|
+
|
107
|
+
MIT License
|
@@ -0,0 +1,7 @@
|
|
1
|
+
mira_network-0.1.2.dist-info/METADATA,sha256=KrCNwQMJqIY3acFF9c00JXWnCnAm0Z_SArKg4dLO8_k,2915
|
2
|
+
mira_network-0.1.2.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
|
3
|
+
mira_network-0.1.2.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
4
|
+
mira_sdk/__init__.py,sha256=KVFj7e20pprJuOWCG9Ky_w2JqKBu8TFPCilPDKRhkyI,364
|
5
|
+
mira_sdk/client.py,sha256=F0E0ATGZXOsozbp91P6MLma5-pgT0rCo0BaEIz-yKDk,5769
|
6
|
+
mira_sdk/models.py,sha256=FQfxjK_Cs7Nt0dB1qYHd7rov3VJSVr6rNAqZqOarU48,1749
|
7
|
+
mira_network-0.1.2.dist-info/RECORD,,
|
mira_sdk/__init__.py
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
from .client import MiraClient
|
2
|
+
from .models import (
|
3
|
+
Message,
|
4
|
+
ModelProvider,
|
5
|
+
AiRequest,
|
6
|
+
FlowChatCompletion,
|
7
|
+
FlowRequest,
|
8
|
+
ApiTokenRequest,
|
9
|
+
AddCreditRequest,
|
10
|
+
)
|
11
|
+
|
12
|
+
__all__ = [
|
13
|
+
"MiraClient",
|
14
|
+
"Message",
|
15
|
+
"ModelProvider",
|
16
|
+
"AiRequest",
|
17
|
+
"FlowChatCompletion",
|
18
|
+
"FlowRequest",
|
19
|
+
"ApiTokenRequest",
|
20
|
+
"AddCreditRequest",
|
21
|
+
]
|
mira_sdk/client.py
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
from typing import Optional, List, Dict, AsyncGenerator, Union
|
2
|
+
import httpx
|
3
|
+
from mira_sdk.models import (
|
4
|
+
Message,
|
5
|
+
ModelProvider,
|
6
|
+
AiRequest,
|
7
|
+
FlowChatCompletion,
|
8
|
+
FlowRequest,
|
9
|
+
ApiTokenRequest,
|
10
|
+
AddCreditRequest,
|
11
|
+
)
|
12
|
+
|
13
|
+
|
14
|
+
class MiraClient:
|
15
|
+
def __init__(self, base_url: str, api_token: Optional[str] = None):
|
16
|
+
"""Initialize Mira client.
|
17
|
+
|
18
|
+
Args:
|
19
|
+
base_url: Base URL of the Mira API
|
20
|
+
api_token: Optional API token for authentication
|
21
|
+
"""
|
22
|
+
self.base_url = base_url
|
23
|
+
self.api_token = api_token
|
24
|
+
self._client = httpx.AsyncClient()
|
25
|
+
|
26
|
+
async def __aenter__(self):
|
27
|
+
return self
|
28
|
+
|
29
|
+
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
30
|
+
await self._client.aclose()
|
31
|
+
|
32
|
+
def _get_headers(self) -> Dict[str, str]:
|
33
|
+
headers = {"Content-Type": "application/json"}
|
34
|
+
if self.api_token:
|
35
|
+
headers["Authorization"] = f"Bearer {self.api_token}"
|
36
|
+
return headers
|
37
|
+
|
38
|
+
async def list_models(self) -> List[str]:
|
39
|
+
"""List available models."""
|
40
|
+
response = await self._client.get(
|
41
|
+
f"{self.base_url}/v1/models",
|
42
|
+
headers=self._get_headers(),
|
43
|
+
)
|
44
|
+
response.raise_for_status()
|
45
|
+
return response.json()
|
46
|
+
|
47
|
+
async def generate(
|
48
|
+
self, request: AiRequest
|
49
|
+
) -> Union[str, AsyncGenerator[str, None]]:
|
50
|
+
"""Generate text using the specified model."""
|
51
|
+
response = await self._client.post(
|
52
|
+
f"{self.base_url}/v1/chat/completions",
|
53
|
+
headers=self._get_headers(),
|
54
|
+
json=request.model_dump(),
|
55
|
+
)
|
56
|
+
|
57
|
+
response.raise_for_status()
|
58
|
+
|
59
|
+
if request.stream:
|
60
|
+
|
61
|
+
async def stream_response():
|
62
|
+
async for chunk in response.aiter_text():
|
63
|
+
yield chunk
|
64
|
+
|
65
|
+
return stream_response()
|
66
|
+
else:
|
67
|
+
return response.json()
|
68
|
+
|
69
|
+
async def generate_with_flow(
|
70
|
+
self, flow_id: str, request: FlowChatCompletion
|
71
|
+
) -> Union[str, AsyncGenerator[str, None]]:
|
72
|
+
"""Generate text using a specific flow."""
|
73
|
+
response = await self._client.post(
|
74
|
+
f"{self.base_url}/v1/flows/{flow_id}/chat/completions",
|
75
|
+
headers=self._get_headers(),
|
76
|
+
json=request.model_dump(),
|
77
|
+
)
|
78
|
+
response.raise_for_status()
|
79
|
+
return response.json()
|
80
|
+
|
81
|
+
async def list_flows(self) -> List[Dict]:
|
82
|
+
"""List all flows."""
|
83
|
+
response = await self._client.get(
|
84
|
+
f"{self.base_url}/flows",
|
85
|
+
headers=self._get_headers(),
|
86
|
+
)
|
87
|
+
response.raise_for_status()
|
88
|
+
return response.json()
|
89
|
+
|
90
|
+
async def get_flow(self, flow_id: str) -> Dict:
|
91
|
+
"""Get details of a specific flow."""
|
92
|
+
response = await self._client.get(
|
93
|
+
f"{self.base_url}/flows/{flow_id}",
|
94
|
+
headers=self._get_headers(),
|
95
|
+
)
|
96
|
+
response.raise_for_status()
|
97
|
+
return response.json()
|
98
|
+
|
99
|
+
async def create_flow(self, request: FlowRequest) -> Dict:
|
100
|
+
"""Create a new flow."""
|
101
|
+
response = await self._client.post(
|
102
|
+
f"{self.base_url}/flows",
|
103
|
+
headers=self._get_headers(),
|
104
|
+
json=request.model_dump(),
|
105
|
+
)
|
106
|
+
response.raise_for_status()
|
107
|
+
return response.json()
|
108
|
+
|
109
|
+
async def update_flow(self, flow_id: str, request: FlowRequest) -> Dict:
|
110
|
+
"""Update an existing flow."""
|
111
|
+
response = await self._client.put(
|
112
|
+
f"{self.base_url}/flows/{flow_id}",
|
113
|
+
headers=self._get_headers(),
|
114
|
+
json=request.model_dump(),
|
115
|
+
)
|
116
|
+
response.raise_for_status()
|
117
|
+
return response.json()
|
118
|
+
|
119
|
+
async def delete_flow(self, flow_id: str) -> None:
|
120
|
+
"""Delete a flow."""
|
121
|
+
response = await self._client.delete(
|
122
|
+
f"{self.base_url}/flows/{flow_id}",
|
123
|
+
headers=self._get_headers(),
|
124
|
+
)
|
125
|
+
response.raise_for_status()
|
126
|
+
|
127
|
+
async def create_api_token(self, request: ApiTokenRequest) -> Dict:
|
128
|
+
"""Create a new API token."""
|
129
|
+
response = await self._client.post(
|
130
|
+
f"{self.base_url}/tokens",
|
131
|
+
headers=self._get_headers(),
|
132
|
+
json=request.model_dump(),
|
133
|
+
)
|
134
|
+
response.raise_for_status()
|
135
|
+
return response.json()
|
136
|
+
|
137
|
+
async def list_api_tokens(self) -> List[Dict]:
|
138
|
+
"""List all API tokens."""
|
139
|
+
response = await self._client.get(
|
140
|
+
f"{self.base_url}/tokens",
|
141
|
+
headers=self._get_headers(),
|
142
|
+
)
|
143
|
+
response.raise_for_status()
|
144
|
+
return response.json()
|
145
|
+
|
146
|
+
async def delete_api_token(self, token: str) -> None:
|
147
|
+
"""Delete an API token."""
|
148
|
+
response = await self._client.delete(
|
149
|
+
f"{self.base_url}/tokens/{token}",
|
150
|
+
headers=self._get_headers(),
|
151
|
+
)
|
152
|
+
response.raise_for_status()
|
153
|
+
|
154
|
+
async def get_user_credits(self) -> Dict:
|
155
|
+
"""Get user credits information."""
|
156
|
+
response = await self._client.get(
|
157
|
+
f"{self.base_url}/credits",
|
158
|
+
headers=self._get_headers(),
|
159
|
+
)
|
160
|
+
response.raise_for_status()
|
161
|
+
return response.json()
|
162
|
+
|
163
|
+
async def add_credit(self, request: AddCreditRequest) -> Dict:
|
164
|
+
"""Add credits to a user account."""
|
165
|
+
response = await self._client.post(
|
166
|
+
f"{self.base_url}/credits",
|
167
|
+
headers=self._get_headers(),
|
168
|
+
json=request.model_dump(),
|
169
|
+
)
|
170
|
+
response.raise_for_status()
|
171
|
+
return response.json()
|
172
|
+
|
173
|
+
async def get_credits_history(self) -> List[Dict]:
|
174
|
+
"""Get user credits history."""
|
175
|
+
response = await self._client.get(
|
176
|
+
f"{self.base_url}/credits/history",
|
177
|
+
headers=self._get_headers(),
|
178
|
+
)
|
179
|
+
response.raise_for_status()
|
180
|
+
return response.json()
|
mira_sdk/models.py
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
from typing import Optional, List, Dict
|
2
|
+
from pydantic import BaseModel, Field, field_validator
|
3
|
+
|
4
|
+
|
5
|
+
class Message(BaseModel):
|
6
|
+
role: str
|
7
|
+
content: str
|
8
|
+
|
9
|
+
@field_validator("role")
|
10
|
+
@classmethod
|
11
|
+
def validate_role(cls, v: str) -> str:
|
12
|
+
valid_roles = ["system", "user", "assistant"]
|
13
|
+
if v not in valid_roles:
|
14
|
+
raise ValueError(f"Invalid role. Must be one of: {valid_roles}")
|
15
|
+
return v
|
16
|
+
|
17
|
+
|
18
|
+
class ModelProvider(BaseModel):
|
19
|
+
base_url: str
|
20
|
+
api_key: str
|
21
|
+
|
22
|
+
|
23
|
+
class AiRequest(BaseModel):
|
24
|
+
model: str = Field("mira/llama3.1", title="Model")
|
25
|
+
model_provider: Optional[ModelProvider] = Field(None, title="Model Provider (optional)")
|
26
|
+
messages: List[Message] = Field([], title="Messages")
|
27
|
+
stream: Optional[bool] = Field(False, title="Stream")
|
28
|
+
|
29
|
+
@field_validator("messages")
|
30
|
+
@classmethod
|
31
|
+
def validate_messages(cls, v: List[Message]) -> List[Message]:
|
32
|
+
if not v:
|
33
|
+
raise ValueError("Messages list cannot be empty")
|
34
|
+
return v
|
35
|
+
|
36
|
+
|
37
|
+
class FlowChatCompletion(BaseModel):
|
38
|
+
variables: Optional[Dict] = Field(None, title="Variables")
|
39
|
+
|
40
|
+
|
41
|
+
class FlowRequest(BaseModel):
|
42
|
+
system_prompt: str
|
43
|
+
name: str
|
44
|
+
|
45
|
+
|
46
|
+
class ApiTokenRequest(BaseModel):
|
47
|
+
description: Optional[str] = None
|
48
|
+
|
49
|
+
|
50
|
+
class AddCreditRequest(BaseModel):
|
51
|
+
user_id: str
|
52
|
+
amount: float
|
53
|
+
description: Optional[str] = None
|
54
|
+
|
55
|
+
@field_validator("amount")
|
56
|
+
@classmethod
|
57
|
+
def validate_amount(cls, v: float) -> float:
|
58
|
+
if v <= 0:
|
59
|
+
raise ValueError("Amount must be greater than 0")
|
60
|
+
return v
|
61
|
+
|
62
|
+
@field_validator("user_id")
|
63
|
+
@classmethod
|
64
|
+
def validate_user_id(cls, v: str) -> str:
|
65
|
+
if not v.strip():
|
66
|
+
raise ValueError("User ID cannot be empty")
|
67
|
+
return v
|
mira_network/__init__.py
DELETED
File without changes
|
mira_network/client.py
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
mira_network/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
mira_network/client.py,sha256=-GSldxzoJrEhLDvF6gd80U6SiEYuUtSnIhJQ6EpeD8w,250
|
3
|
-
mira_network-0.1.0.dist-info/METADATA,sha256=OIrrTjqa2NXGkodyvHrg7YNxFRSs1IOHQzQ2EdZ8mJs,240
|
4
|
-
mira_network-0.1.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
5
|
-
mira_network-0.1.0.dist-info/top_level.txt,sha256=lqyBtm4UdvqoeCYxm2P-ygcfmHhHurxg_Ue7dTChKEo,13
|
6
|
-
mira_network-0.1.0.dist-info/RECORD,,
|
@@ -1 +0,0 @@
|
|
1
|
-
mira_network
|