clarifai-protocol 0.0.7__cp312-cp312-macosx_11_0_universal2.whl → 0.0.40__cp312-cp312-macosx_11_0_universal2.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.
- {clarifai_protocol-0.0.7.dist-info → clarifai_protocol-0.0.40.dist-info}/METADATA +75 -7
- clarifai_protocol-0.0.40.dist-info/RECORD +8 -0
- {clarifai_protocol-0.0.7.dist-info → clarifai_protocol-0.0.40.dist-info}/WHEEL +1 -1
- clarifai_protocol.build/.gitignore +1 -0
- clarifai_protocol.cpython-312-darwin.so +0 -0
- clarifai_protocol.pyi +29 -25
- clarifai_protocol-0.0.7.dist-info/RECORD +0 -7
- {clarifai_protocol-0.0.7.dist-info → clarifai_protocol-0.0.40.dist-info/licenses}/LICENSE +0 -0
- {clarifai_protocol-0.0.7.dist-info → clarifai_protocol-0.0.40.dist-info}/top_level.txt +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: clarifai-protocol
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.40
|
|
4
4
|
Summary: Clarifai Python Runner Protocol
|
|
5
5
|
Author-email: Clarifai <support@clarifai.com>
|
|
6
|
-
License:
|
|
6
|
+
License: Apache License
|
|
7
7
|
Version 2.0, January 2004
|
|
8
8
|
http://www.apache.org/licenses/
|
|
9
9
|
|
|
@@ -211,20 +211,88 @@ Keywords: clarifai,runners,python
|
|
|
211
211
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
212
212
|
Classifier: Programming Language :: Python :: 3
|
|
213
213
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
214
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
215
214
|
Classifier: Programming Language :: Python :: 3.9
|
|
216
215
|
Classifier: Programming Language :: Python :: 3.10
|
|
217
216
|
Classifier: Programming Language :: Python :: 3.11
|
|
218
217
|
Classifier: Programming Language :: Python :: 3.12
|
|
218
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
219
219
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
220
220
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
221
221
|
Classifier: Operating System :: OS Independent
|
|
222
|
-
Requires-Python: >=3.
|
|
222
|
+
Requires-Python: >=3.9
|
|
223
223
|
Description-Content-Type: text/markdown
|
|
224
224
|
License-File: LICENSE
|
|
225
|
-
Requires-Dist: clarifai>=
|
|
226
|
-
Requires-Dist: clarifai-grpc>=
|
|
225
|
+
Requires-Dist: clarifai>=11.7.2
|
|
226
|
+
Requires-Dist: clarifai-grpc>=11.7.8
|
|
227
|
+
Dynamic: license-file
|
|
227
228
|
|
|
228
229
|
# Clarifai Protocol
|
|
229
230
|
|
|
230
231
|
This is a proprietary protocol used by our runners to communicate with our API. This should be installed as part of our python SDK.
|
|
232
|
+
|
|
233
|
+
## Request Cancellation Support
|
|
234
|
+
|
|
235
|
+
The protocol now supports request cancellation, allowing models to abort in-flight requests to external inference servers when a user cancels their request.
|
|
236
|
+
|
|
237
|
+
### Features
|
|
238
|
+
|
|
239
|
+
- **Request ID Access**: Models can access the current request ID via `get_request_id()`
|
|
240
|
+
- **Abort Callbacks**: Models can register a callback that will be invoked when requests are cancelled or when connections are aborted
|
|
241
|
+
- **Thread Safety**: All operations are thread-safe and work correctly with concurrent requests
|
|
242
|
+
- **Background Execution**: Abort callbacks run in background threads to avoid blocking the protocol
|
|
243
|
+
|
|
244
|
+
### Usage
|
|
245
|
+
|
|
246
|
+
```python
|
|
247
|
+
from clarifai_protocol import get_request_id, register_abort_callback
|
|
248
|
+
import requests
|
|
249
|
+
|
|
250
|
+
class MyModel:
|
|
251
|
+
def __init__(self):
|
|
252
|
+
super().__init__()
|
|
253
|
+
self.sglang_url = "http://localhost:30000"
|
|
254
|
+
# Register abort callback during initialization
|
|
255
|
+
register_abort_callback(self._abort_sglang)
|
|
256
|
+
|
|
257
|
+
def _abort_sglang(self, req_id: str) -> None:
|
|
258
|
+
"""Abort handler called when requests are cancelled."""
|
|
259
|
+
try:
|
|
260
|
+
requests.post(
|
|
261
|
+
f"{self.sglang_url}/abort_request",
|
|
262
|
+
json={"rid": req_id},
|
|
263
|
+
timeout=2.0
|
|
264
|
+
)
|
|
265
|
+
except Exception:
|
|
266
|
+
pass # Handle exceptions gracefully
|
|
267
|
+
|
|
268
|
+
def generate(self, prompt: str):
|
|
269
|
+
"""Generate text using external inference server."""
|
|
270
|
+
# Get the request ID to pass to the external server
|
|
271
|
+
req_id = get_request_id()
|
|
272
|
+
|
|
273
|
+
# Use req_id when calling external services
|
|
274
|
+
for token in self._call_sglang(prompt, req_id):
|
|
275
|
+
yield token
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### API Reference
|
|
279
|
+
|
|
280
|
+
#### `get_request_id() -> Optional[str]`
|
|
281
|
+
|
|
282
|
+
Returns the current request ID, or `None` if called outside of a request context.
|
|
283
|
+
|
|
284
|
+
Use this as an identifier when calling external inference servers so that cancellation can properly abort the request.
|
|
285
|
+
|
|
286
|
+
#### `register_abort_callback(callback: Callable[[str], None]) -> None`
|
|
287
|
+
|
|
288
|
+
Register a function to be called when a request is cancelled or the connection is aborted.
|
|
289
|
+
|
|
290
|
+
- Should be called once during model initialization
|
|
291
|
+
- The callback receives the cancelled request's ID as a parameter
|
|
292
|
+
- The callback runs in a background thread
|
|
293
|
+
- **The callback should be idempotent** (safe to call multiple times with the same req_id)
|
|
294
|
+
- Exceptions in the callback are logged but don't crash the protocol
|
|
295
|
+
- Triggered when: explicit cancellation (`RUNNER_ITEM_CANCELLED`) or connection abort (stream done/cancelled)
|
|
296
|
+
|
|
297
|
+
# Release instructions
|
|
298
|
+
Bump the version in the file VERSION, merge it, pull master, git tag to the same version, push the tag to github to release.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
clarifai_protocol.cpython-312-darwin.so,sha256=QFWsLTrCvJ9eBOY81UlWauIkGVHM6ADojhCfGAjL_fQ,944376
|
|
2
|
+
clarifai_protocol.pyi,sha256=fymVU4LzsXIN-gaxWcLwMum8Sd0CRog5UJHAv2xTc-E,990
|
|
3
|
+
clarifai_protocol-0.0.40.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
4
|
+
clarifai_protocol.build/.gitignore,sha256=aEiIwOuxfzdCmLZe4oB1JsBmCUxwG8x-u-HBCV9JT8E,1
|
|
5
|
+
clarifai_protocol-0.0.40.dist-info/METADATA,sha256=nVsu_ubyKv_N_qknzHVdp8qeB7Mka5-4lCs_FAmaGME,16893
|
|
6
|
+
clarifai_protocol-0.0.40.dist-info/WHEEL,sha256=K2_moIlF6mA5-I1JEl7qWu8KIFR2Ytdqxl2ezOqILQE,109
|
|
7
|
+
clarifai_protocol-0.0.40.dist-info/top_level.txt,sha256=qwWV-wytBq70748luF3R1ouCIWiIm2R551LIVXUtpB8,18
|
|
8
|
+
clarifai_protocol-0.0.40.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*
|
|
Binary file
|
clarifai_protocol.pyi
CHANGED
|
@@ -1,45 +1,49 @@
|
|
|
1
|
-
# This file was generated by Nuitka
|
|
2
|
-
# created shared library.
|
|
1
|
+
# This file was generated by Nuitka
|
|
3
2
|
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
# standalone mode usage of the created library will need it.
|
|
3
|
+
# Stubs included by default
|
|
4
|
+
from base_runner import BaseRunner, get_item_id, register_item_abort_callback, shutdown_abort_executor
|
|
7
5
|
|
|
8
|
-
# In the future, this will also contain type information for values
|
|
9
|
-
# in the module, so IDEs will use this. Therefore please include it
|
|
10
|
-
# when you make software releases of the extension module that it
|
|
11
|
-
# describes.
|
|
12
6
|
|
|
7
|
+
__name__ = ...
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# Modules used internally, to allow implicit dependencies to be seen:
|
|
13
12
|
import os
|
|
13
|
+
import importlib
|
|
14
|
+
import importlib.util
|
|
15
|
+
import subprocess
|
|
16
|
+
import threading
|
|
17
|
+
import datetime
|
|
18
|
+
import clarifai
|
|
19
|
+
import clarifai.client
|
|
20
|
+
import clarifai.client.input
|
|
21
|
+
import clarifai.utils
|
|
22
|
+
import clarifai.utils.logging
|
|
23
|
+
import clarifai_grpc
|
|
24
|
+
import clarifai_grpc.grpc
|
|
25
|
+
import clarifai_grpc.grpc.api
|
|
26
|
+
import clarifai_grpc.grpc.api.status
|
|
27
|
+
import av
|
|
28
|
+
import atexit
|
|
29
|
+
import collections
|
|
30
|
+
import concurrent
|
|
31
|
+
import concurrent.futures
|
|
32
|
+
import contextvars
|
|
14
33
|
import itertools
|
|
15
34
|
import signal
|
|
16
35
|
import sys
|
|
17
|
-
import threading
|
|
18
36
|
import time
|
|
19
37
|
import traceback
|
|
20
38
|
import uuid
|
|
21
39
|
import abc
|
|
22
|
-
import concurrent
|
|
23
|
-
import concurrent.futures
|
|
24
40
|
import concurrent.futures.ThreadPoolExecutor
|
|
25
41
|
import queue
|
|
26
42
|
import typing
|
|
27
43
|
import grpc
|
|
28
|
-
import clarifai
|
|
29
|
-
import clarifai.client
|
|
30
44
|
import clarifai.client.base
|
|
31
|
-
import clarifai.utils
|
|
32
|
-
import clarifai.utils.logging
|
|
33
|
-
import clarifai_grpc
|
|
34
|
-
import clarifai_grpc.grpc
|
|
35
|
-
import clarifai_grpc.grpc.api
|
|
36
|
-
import clarifai_grpc.grpc.api.status
|
|
37
45
|
import grpc._cython
|
|
38
46
|
import grpc._server
|
|
39
47
|
import http
|
|
40
48
|
import http.server
|
|
41
|
-
|
|
42
|
-
# This is not Python source even if it looks so. Make it clear for
|
|
43
|
-
# now. This was decided by PEP 484 designers.
|
|
44
|
-
__name__ = ...
|
|
45
|
-
|
|
49
|
+
import requests
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
clarifai_protocol.cpython-312-darwin.so,sha256=TpC8MfpXYFZsEWrlMG_rb-Bi60V6wGygqYL5ghV41nc,617928
|
|
2
|
-
clarifai_protocol.pyi,sha256=HQ96MJ60MdL3XB-HNINSO_rVFGn50CkJzC7tuQz6FuU,1193
|
|
3
|
-
clarifai_protocol-0.0.7.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
4
|
-
clarifai_protocol-0.0.7.dist-info/METADATA,sha256=E1Uq5Ern_q9FCvGuB9icOadt_wO7LhUkPtsCAhJxQ6k,14157
|
|
5
|
-
clarifai_protocol-0.0.7.dist-info/WHEEL,sha256=C7A5CO1UkzeoTkUVlV1TGCNBYZghQ_seCGYtnvYr1Uk,110
|
|
6
|
-
clarifai_protocol-0.0.7.dist-info/top_level.txt,sha256=qwWV-wytBq70748luF3R1ouCIWiIm2R551LIVXUtpB8,18
|
|
7
|
-
clarifai_protocol-0.0.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|