clarifai-protocol 0.0.31rc1__cp313-cp313-musllinux_1_2_x86_64.whl → 0.0.41__cp313-cp313-musllinux_1_2_x86_64.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.31rc1.dist-info → clarifai_protocol-0.0.41.dist-info}/METADATA +65 -1
- clarifai_protocol-0.0.41.dist-info/RECORD +8 -0
- clarifai_protocol.cpython-313-x86_64-linux-musl.so +0 -0
- clarifai_protocol.pyi +19 -11
- clarifai_protocol-0.0.31rc1.dist-info/RECORD +0 -8
- {clarifai_protocol-0.0.31rc1.dist-info → clarifai_protocol-0.0.41.dist-info}/WHEEL +0 -0
- {clarifai_protocol-0.0.31rc1.dist-info → clarifai_protocol-0.0.41.dist-info}/licenses/LICENSE +0 -0
- {clarifai_protocol-0.0.31rc1.dist-info → clarifai_protocol-0.0.41.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: clarifai-protocol
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.41
|
|
4
4
|
Summary: Clarifai Python Runner Protocol
|
|
5
5
|
Author-email: Clarifai <support@clarifai.com>
|
|
6
6
|
License: Apache License
|
|
@@ -230,5 +230,69 @@ Dynamic: license-file
|
|
|
230
230
|
|
|
231
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
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
|
+
|
|
233
297
|
# Release instructions
|
|
234
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-x86_64-linux-musl.so,sha256=_un-QG-gI9mU9AdgKh0xINweOHX2n4LLz7SE64VmWOo,1514200
|
|
2
|
+
clarifai_protocol.pyi,sha256=fymVU4LzsXIN-gaxWcLwMum8Sd0CRog5UJHAv2xTc-E,990
|
|
3
|
+
clarifai_protocol.build/.gitignore,sha256=aEiIwOuxfzdCmLZe4oB1JsBmCUxwG8x-u-HBCV9JT8E,1
|
|
4
|
+
clarifai_protocol-0.0.41.dist-info/METADATA,sha256=x9tSueYZXTDZkW0NgfXiJFxoWQm-BhoNGDNVuxoo_a0,16893
|
|
5
|
+
clarifai_protocol-0.0.41.dist-info/WHEEL,sha256=HQcsgt4_BRQYpTaaip_gA8-a0sREDElUnArgNw0oVvY,107
|
|
6
|
+
clarifai_protocol-0.0.41.dist-info/top_level.txt,sha256=qwWV-wytBq70748luF3R1ouCIWiIm2R551LIVXUtpB8,18
|
|
7
|
+
clarifai_protocol-0.0.41.dist-info/RECORD,,
|
|
8
|
+
clarifai_protocol-0.0.41.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
Binary file
|
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,14 +10,29 @@ __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
|
|
14
29
|
import collections
|
|
15
30
|
import concurrent
|
|
16
31
|
import concurrent.futures
|
|
32
|
+
import contextvars
|
|
17
33
|
import itertools
|
|
18
34
|
import signal
|
|
19
35
|
import sys
|
|
20
|
-
import threading
|
|
21
36
|
import time
|
|
22
37
|
import traceback
|
|
23
38
|
import uuid
|
|
@@ -26,16 +41,9 @@ import concurrent.futures.ThreadPoolExecutor
|
|
|
26
41
|
import queue
|
|
27
42
|
import typing
|
|
28
43
|
import grpc
|
|
29
|
-
import clarifai
|
|
30
|
-
import clarifai.client
|
|
31
44
|
import clarifai.client.base
|
|
32
|
-
import clarifai.utils
|
|
33
|
-
import clarifai.utils.logging
|
|
34
|
-
import clarifai_grpc
|
|
35
|
-
import clarifai_grpc.grpc
|
|
36
|
-
import clarifai_grpc.grpc.api
|
|
37
|
-
import clarifai_grpc.grpc.api.status
|
|
38
45
|
import grpc._cython
|
|
39
46
|
import grpc._server
|
|
40
47
|
import http
|
|
41
|
-
import http.server
|
|
48
|
+
import http.server
|
|
49
|
+
import requests
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
clarifai_protocol.cpython-313-x86_64-linux-musl.so,sha256=gexJgz8BHWlB6fLtQhvh9vq2wzYMKj3q8WVdLF-YsTo,1255992
|
|
2
|
-
clarifai_protocol.pyi,sha256=0U76Jmy9bci3OioLcWj0jNp_SlkWS39rf45zz2BGj_A,775
|
|
3
|
-
clarifai_protocol.build/.gitignore,sha256=aEiIwOuxfzdCmLZe4oB1JsBmCUxwG8x-u-HBCV9JT8E,1
|
|
4
|
-
clarifai_protocol-0.0.31rc1.dist-info/METADATA,sha256=faLSaVYB-MNdYmqUr9-dN26iGtOE-Vpnhcuj9LvhubI,14366
|
|
5
|
-
clarifai_protocol-0.0.31rc1.dist-info/WHEEL,sha256=HQcsgt4_BRQYpTaaip_gA8-a0sREDElUnArgNw0oVvY,107
|
|
6
|
-
clarifai_protocol-0.0.31rc1.dist-info/top_level.txt,sha256=qwWV-wytBq70748luF3R1ouCIWiIm2R551LIVXUtpB8,18
|
|
7
|
-
clarifai_protocol-0.0.31rc1.dist-info/RECORD,,
|
|
8
|
-
clarifai_protocol-0.0.31rc1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
File without changes
|
{clarifai_protocol-0.0.31rc1.dist-info → clarifai_protocol-0.0.41.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|