clarifai-protocol 0.0.13__cp313-cp313-musllinux_1_2_aarch64.whl → 0.0.36__cp313-cp313-musllinux_1_2_aarch64.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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: clarifai-protocol
3
- Version: 0.0.13
3
+ Version: 0.0.36
4
4
  Summary: Clarifai Python Runner Protocol
5
5
  Author-email: Clarifai <support@clarifai.com>
6
6
  License: Apache License
@@ -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.8
222
+ Requires-Python: >=3.9
223
223
  Description-Content-Type: text/markdown
224
224
  License-File: LICENSE
225
- Requires-Dist: clarifai>=10.5.4
226
- Requires-Dist: clarifai-grpc>=10.6.4
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-313-aarch64-linux-musl.so,sha256=9rRL0N18V0L6xSM20lDyMyhfB0M7T8qcuCf3R70yHqE,1391072
2
+ clarifai_protocol.pyi,sha256=FbQbE3bZNiWnfQ4T-Ij4SC5-VKnkUBKkr43-y9Mh65g,974
3
+ clarifai_protocol.build/.gitignore,sha256=aEiIwOuxfzdCmLZe4oB1JsBmCUxwG8x-u-HBCV9JT8E,1
4
+ clarifai_protocol-0.0.36.dist-info/METADATA,sha256=WmyPOT9wyZ3mdJ7M-BRlm7RKkNkIP0Y0WN1aiJOMC0Q,16893
5
+ clarifai_protocol-0.0.36.dist-info/WHEEL,sha256=NTE44UD_Yj2a28uc9ySaBJEPo0qBBhDh2tM3OgGeJyk,108
6
+ clarifai_protocol-0.0.36.dist-info/top_level.txt,sha256=qwWV-wytBq70748luF3R1ouCIWiIm2R551LIVXUtpB8,18
7
+ clarifai_protocol-0.0.36.dist-info/RECORD,,
8
+ clarifai_protocol-0.0.36.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: Nuitka (2.5.6)
2
+ Generator: Nuitka (2.5.8)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp313-cp313-musllinux_1_2_aarch64
5
5
 
clarifai_protocol.pyi CHANGED
@@ -1,7 +1,7 @@
1
1
  # This file was generated by Nuitka
2
2
 
3
3
  # Stubs included by default
4
- from base_runner import BaseRunner
4
+ from base_runner import BaseRunner, get_item_id, register_item_abort_callback, shutdown_abort_executor
5
5
 
6
6
 
7
7
  __name__ = ...
@@ -10,30 +10,38 @@ __name__ = ...
10
10
 
11
11
  # Modules used internally, to allow implicit dependencies to be seen:
12
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
13
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
@@ -1,8 +0,0 @@
1
- clarifai_protocol.pyi,sha256=icCuxcS5FV4vAI_OyikiJhxBWHWwtRZ8_Vnsa5vgdhA,756
2
- clarifai_protocol.cpython-313-aarch64-linux-musl.so,sha256=IgP3LltWRDmbnZAA-UQiqtxzT925KgfCCu1oydOu9hI,1128744
3
- clarifai_protocol.build/.gitignore,sha256=aEiIwOuxfzdCmLZe4oB1JsBmCUxwG8x-u-HBCV9JT8E,1
4
- clarifai_protocol-0.0.13.dist-info/METADATA,sha256=QnqX6kOmkuQljhxo6aDNTQtOik6x5jwAvoQxcfYR2Tw,14191
5
- clarifai_protocol-0.0.13.dist-info/RECORD,,
6
- clarifai_protocol-0.0.13.dist-info/WHEEL,sha256=cy6VAJPKNf17sN4a6PSfQHOTsTSaAxXtfUNSu43D6qo,108
7
- clarifai_protocol-0.0.13.dist-info/top_level.txt,sha256=qwWV-wytBq70748luF3R1ouCIWiIm2R551LIVXUtpB8,18
8
- clarifai_protocol-0.0.13.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357