aimarket-streaming 2.0.0__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.
- aimarket_streaming/__init__.py +1 -0
- aimarket_streaming/plugin.py +19 -0
- aimarket_streaming/streaming.py +3 -0
- aimarket_streaming-2.0.0.dist-info/METADATA +89 -0
- aimarket_streaming-2.0.0.dist-info/RECORD +9 -0
- aimarket_streaming-2.0.0.dist-info/WHEEL +5 -0
- aimarket_streaming-2.0.0.dist-info/entry_points.txt +2 -0
- aimarket_streaming-2.0.0.dist-info/licenses/LICENSE +21 -0
- aimarket_streaming-2.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# aimarket-streaming plugin
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""streaming plugin for AIMarket Hub."""
|
|
2
|
+
|
|
3
|
+
from aimarket_hub.plugin import HubPlugin
|
|
4
|
+
from aimarket_streaming.streaming import *
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class StreamingPlugin(HubPlugin):
|
|
8
|
+
name = "aimarket-streaming"
|
|
9
|
+
version = "2.0.0"
|
|
10
|
+
description = "streaming"
|
|
11
|
+
homepage = "https://github.com/alexar76/aimarket-plugins"
|
|
12
|
+
category = "monetization"
|
|
13
|
+
|
|
14
|
+
def register_routes(self, router):
|
|
15
|
+
from fastapi import APIRouter as _AR
|
|
16
|
+
# Plugin-specific routes will be registered here
|
|
17
|
+
pass
|
|
18
|
+
def on_startup(self, db):
|
|
19
|
+
self._biller = None # Lazy init on first stream
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aimarket-streaming
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: SSE/WS streaming + per-chunk billing with micro-receipts
|
|
5
|
+
Author-email: AI-Factory <dev@modelmarket.dev>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/alexar76/aimarket-plugins
|
|
8
|
+
Project-URL: Documentation, https://github.com/alexar76/aimarket-plugins/tree/main/plugins/aimarket-streaming#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/alexar76/aimarket-plugins
|
|
10
|
+
Project-URL: Issues, https://github.com/alexar76/aimarket-plugins/issues
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: aimarket-hub>=2.0.0
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# aimarket-streaming
|
|
26
|
+
|
|
27
|
+
## Documentation
|
|
28
|
+
|
|
29
|
+
| Document | Description |
|
|
30
|
+
|----------|-------------|
|
|
31
|
+
| [User guide](docs/user-guide.md) | Install, configure, verify plugin is loaded |
|
|
32
|
+
| [User cases](docs/user-cases.md) | Personas and cross-plugin workflows |
|
|
33
|
+
| [SDK integration](docs/sdk-integration.md) | Code examples and hook behavior |
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
**SSE/WS streaming + per-chunk billing with micro-receipts.**
|
|
38
|
+
Capability streams tokens. Every N tokens → signed micro-receipt. Consumer can cancel mid-stream — pays only for what was received. Channel balance debited incrementally.
|
|
39
|
+
|
|
40
|
+
## When to Use
|
|
41
|
+
- LLM text generation (tokens streamed → billed per 10 tokens)
|
|
42
|
+
- Long-running AI tasks where consumer wants partial results
|
|
43
|
+
- Budget-sensitive consumers who want to cancel mid-stream
|
|
44
|
+
- Audit: every chunk has a signed receipt for compliance
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
```bash
|
|
48
|
+
pip install aimarket-streaming
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Example
|
|
52
|
+
```python
|
|
53
|
+
from aimarket_hub.signing import Signer
|
|
54
|
+
from aimarket_streaming.streaming import StreamingBiller
|
|
55
|
+
|
|
56
|
+
signer = Signer()
|
|
57
|
+
biller = StreamingBiller(signer)
|
|
58
|
+
|
|
59
|
+
session = biller.open_session(
|
|
60
|
+
capability_id="text.generate@v1", product_id="prod-gpt",
|
|
61
|
+
channel_id="ch_abc123", price_per_token_usd=0.001,
|
|
62
|
+
tokens_per_chunk=10
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
async def token_stream():
|
|
66
|
+
for word in ["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog", ".", "..."]:
|
|
67
|
+
yield word # In production: yield actual LLM tokens
|
|
68
|
+
|
|
69
|
+
import asyncio
|
|
70
|
+
async def main():
|
|
71
|
+
async for chunk in biller.stream_tokens(session, token_stream()):
|
|
72
|
+
print(f"Chunk {chunk['chunk_receipt']['chunk_index']}: "
|
|
73
|
+
f"${chunk['cumulative_price_usd']:.6f} "
|
|
74
|
+
f"({chunk['cumulative_tokens']} tokens)")
|
|
75
|
+
|
|
76
|
+
asyncio.run(main())
|
|
77
|
+
|
|
78
|
+
# Cancel mid-stream — pays only for received
|
|
79
|
+
result = biller.cancel_session(session.session_id)
|
|
80
|
+
print(f"Cancelled. Total paid: ${result['total_price_usd']:.6f}")
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Per-Chunk Billing
|
|
84
|
+
- `price_per_token_usd`: 0.001 (0.1 cent per token)
|
|
85
|
+
- `tokens_per_chunk`: 10 (micro-receipt every 10 tokens)
|
|
86
|
+
- Each chunk receipt is Ed25519-signed — verifiable audit trail
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
MIT · Maintained by AI-Factory
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
aimarket_streaming/__init__.py,sha256=sBwdDDC7HVWETMAj2cQFBD_BY53xZeGHkXNpDBTsRWg,28
|
|
2
|
+
aimarket_streaming/plugin.py,sha256=J06iWY-9EX-7vLfyj1nfnINDDJANQ_KoGpnaZeuS4xQ,581
|
|
3
|
+
aimarket_streaming/streaming.py,sha256=jOo85p1bCLcc0eDZiWsSQICCIOwR67KeNouggaFfRt8,134
|
|
4
|
+
aimarket_streaming-2.0.0.dist-info/licenses/LICENSE,sha256=XMDybCZE66kpDYCsKwJ6_GbxSP7p3r-XIc7u_-KcTYA,1088
|
|
5
|
+
aimarket_streaming-2.0.0.dist-info/METADATA,sha256=OrEjmmkgMr8JB49m7mh8lqkfJBVm2kVxB7F31qLM-i0,3181
|
|
6
|
+
aimarket_streaming-2.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
7
|
+
aimarket_streaming-2.0.0.dist-info/entry_points.txt,sha256=HeUaa5k9h_CZiztfa5LTomLVw2Ip7M5sovLYEcT-kkg,73
|
|
8
|
+
aimarket_streaming-2.0.0.dist-info/top_level.txt,sha256=_LGk6TtwAOI95z3_lB-wfe28xko5Q_VoSU4pUjV4qYA,19
|
|
9
|
+
aimarket_streaming-2.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AI-Factory Project Contributors
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aimarket_streaming
|