clarifai 11.5.5__py3-none-any.whl → 11.5.6__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.
clarifai/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "11.5.5"
1
+ __version__ = "11.5.6"
@@ -550,6 +550,11 @@ class ModelBuilder:
550
550
  "inference_compute_info not found in the config file"
551
551
  )
552
552
  inference_compute_info = self.config.get('inference_compute_info')
553
+ # Ensure cpu_limit is a string if it exists and is an int
554
+ if 'cpu_limit' in inference_compute_info and isinstance(
555
+ inference_compute_info['cpu_limit'], int
556
+ ):
557
+ inference_compute_info['cpu_limit'] = str(inference_compute_info['cpu_limit'])
553
558
  return json_format.ParseDict(inference_compute_info, resources_pb2.ComputeInfo())
554
559
 
555
560
  def check_model_exists(self):
@@ -1,6 +1,7 @@
1
1
  import inspect
2
2
  import itertools
3
3
  import os
4
+ import threading
4
5
  import traceback
5
6
  from abc import ABC
6
7
  from collections import abc
@@ -59,15 +60,22 @@ class ModelClass(ABC):
59
60
  yield item.x + ' ' + str(item.y)
60
61
  '''
61
62
 
63
+ def __init__(self):
64
+ super().__init__()
65
+ self._thread_local = threading.local()
66
+
62
67
  @staticmethod
63
68
  def method(func):
64
69
  setattr(func, _METHOD_INFO_ATTR, _MethodInfo(func))
65
70
  return func
66
71
 
67
72
  def set_output_context(self, prompt_tokens=None, completion_tokens=None):
68
- """This is used to set the prompt and completion tokens in the Output proto"""
69
- self._prompt_tokens = prompt_tokens
70
- self._completion_tokens = completion_tokens
73
+ """Set the prompt and completion tokens for the Output proto.
74
+ In batch mode, call this once per output, in order, before returning each output.
75
+ """
76
+ if not hasattr(self._thread_local, 'token_contexts'):
77
+ self._thread_local.token_contexts = []
78
+ self._thread_local.token_contexts.append((prompt_tokens, completion_tokens))
71
79
 
72
80
  def load_model(self):
73
81
  """Load the model."""
@@ -213,6 +221,7 @@ class ModelClass(ABC):
213
221
  self, request: service_pb2.PostModelOutputsRequest
214
222
  ) -> Iterator[service_pb2.MultiOutputResponse]:
215
223
  try:
224
+ assert len(request.inputs) == 1, "Generate requires exactly one input"
216
225
  method_name = 'generate'
217
226
  if len(request.inputs) > 0 and '_method_name' in request.inputs[0].data.metadata:
218
227
  method_name = request.inputs[0].data.metadata['_method_name']
@@ -385,12 +394,18 @@ class ModelClass(ABC):
385
394
  data = DataConverter.convert_output_data_to_old_format(proto.data)
386
395
  proto.data.CopyFrom(data)
387
396
  proto.status.code = status_code_pb2.SUCCESS
388
- if hasattr(self, "_prompt_tokens") and self._prompt_tokens is not None:
389
- proto.prompt_tokens = self._prompt_tokens
390
- if hasattr(self, "_completion_tokens") and self._completion_tokens is not None:
391
- proto.completion_tokens = self._completion_tokens
392
- self._prompt_tokens = None
393
- self._completion_tokens = None
397
+ # Per-output token context support
398
+ token_contexts = getattr(self._thread_local, 'token_contexts', None)
399
+ prompt_tokens = completion_tokens = None
400
+ if token_contexts and len(token_contexts) > 0:
401
+ prompt_tokens, completion_tokens = token_contexts.pop(0)
402
+ # If this was the last, clean up
403
+ if len(token_contexts) == 0:
404
+ del self._thread_local.token_contexts
405
+ if prompt_tokens is not None:
406
+ proto.prompt_tokens = prompt_tokens
407
+ if completion_tokens is not None:
408
+ proto.completion_tokens = completion_tokens
394
409
  return proto
395
410
 
396
411
  @classmethod
@@ -34,6 +34,7 @@ class OpenAIModelClass(ModelClass):
34
34
  model = None
35
35
 
36
36
  def __init__(self) -> None:
37
+ super().__init__()
37
38
  if self.client is None:
38
39
  raise NotImplementedError("Subclasses must set the 'client' class attribute")
39
40
  if self.model is None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clarifai
3
- Version: 11.5.5
3
+ Version: 11.5.6
4
4
  Home-page: https://github.com/Clarifai/clarifai-python
5
5
  Author: Clarifai
6
6
  Author-email: support@clarifai.com
@@ -1,4 +1,4 @@
1
- clarifai/__init__.py,sha256=OF6Ppf-NDN6b_03eNnRsnEEmYm8mHwco3nReiqZIKq8,23
1
+ clarifai/__init__.py,sha256=BxuXNC41hShXWv3SgslBYu8ufM3yw21Lbp4jemirGjY,23
2
2
  clarifai/cli.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  clarifai/errors.py,sha256=GXa6D4v_L404J83jnRNFPH7s-1V9lk7w6Ws99f1g-AY,2772
4
4
  clarifai/versions.py,sha256=ecSuEB_nOL2XSoYHDw2n23XUbm_KPOGjudMXmQrGdS8,224
@@ -75,12 +75,12 @@ clarifai/runners/dockerfile_template/Dockerfile.template,sha256=DUH7F0-uLOV0LTjn
75
75
  clarifai/runners/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
76
76
  clarifai/runners/models/dummy_openai_model.py,sha256=pcmAVbqTTGG4J3BLVjKfvM_SQ-GET_XexIUdLcr9Zvo,8373
77
77
  clarifai/runners/models/mcp_class.py,sha256=RdKn7rW4vYol0VRDZiLTSMfkqjLhO1ijXAQ0Rq0Jfnw,6647
78
- clarifai/runners/models/model_builder.py,sha256=QgGYruFVUS-xfva-wdGaZT0zpLbbc3dkYqOoYSM_jyU,63409
79
- clarifai/runners/models/model_class.py,sha256=2yAXPsRFIjmyo8n9XUu-YaMOxyRpeVg_MJo4IAo0kRU,19365
78
+ clarifai/runners/models/model_builder.py,sha256=lzXf1H4oQ4l672xHoXSaT4bi0z0vTj3YnziT7RRRLIg,63695
79
+ clarifai/runners/models/model_class.py,sha256=Ndh437BNMkpFBo6B108GuKL8sGYaGnSplZ6FxOgd_v8,20010
80
80
  clarifai/runners/models/model_run_locally.py,sha256=6-6WjEKc0ba3gAv4wOLdMs2XOzS3b-2bZHJS0wdVqJY,20088
81
81
  clarifai/runners/models/model_runner.py,sha256=tZTX1XKMlniJEmd1WMjcwGfej5NCWqv23HZ4xrG8YV8,9153
82
82
  clarifai/runners/models/model_servicer.py,sha256=415RqiXCPH-1WgFHrtZMDH1nb8gaQDpVlrQ_tvtbjOg,4523
83
- clarifai/runners/models/openai_class.py,sha256=aXlk5W6LWkh-A4eZYi74DeLW0i_86_9DYYGxpJHXI0w,6688
83
+ clarifai/runners/models/openai_class.py,sha256=OVYe4dWJPhskyZn53X9yJorzKZA7mjRCqYbu1rzRTFU,6715
84
84
  clarifai/runners/models/visual_classifier_class.py,sha256=1ZoLfCT2crrgRbejjTMAIwpTRgQMiH9N9yflOVpFxSg,2721
85
85
  clarifai/runners/models/visual_detector_class.py,sha256=ky4oFAkGCKPpGPdgaOso-n6D3HcmnbKee_8hBsNiV8U,2883
86
86
  clarifai/runners/pipeline_steps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -118,9 +118,9 @@ clarifai/workflows/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
118
118
  clarifai/workflows/export.py,sha256=HvUYG9N_-UZoRR0-_tdGbZ950_AeBqawSppgUxQebR0,1913
119
119
  clarifai/workflows/utils.py,sha256=ESL3INcouNcLKCh-nMpfXX-YbtCzX7tz7hT57_RGQ3M,2079
120
120
  clarifai/workflows/validate.py,sha256=UhmukyHkfxiMFrPPeBdUTiCOHQT5-shqivlBYEyKTlU,2931
121
- clarifai-11.5.5.dist-info/licenses/LICENSE,sha256=mUqF_d12-qE2n41g7C5_sq-BMLOcj6CNN-jevr15YHU,555
122
- clarifai-11.5.5.dist-info/METADATA,sha256=SkHXmknF4MRdxN2h9_8tqq-ZZid1avN-WisUenwU6ak,22737
123
- clarifai-11.5.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
124
- clarifai-11.5.5.dist-info/entry_points.txt,sha256=X9FZ4Z-i_r2Ud1RpZ9sNIFYuu_-9fogzCMCRUD9hyX0,51
125
- clarifai-11.5.5.dist-info/top_level.txt,sha256=wUMdCQGjkxaynZ6nZ9FAnvBUCgp5RJUVFSy2j-KYo0s,9
126
- clarifai-11.5.5.dist-info/RECORD,,
121
+ clarifai-11.5.6.dist-info/licenses/LICENSE,sha256=mUqF_d12-qE2n41g7C5_sq-BMLOcj6CNN-jevr15YHU,555
122
+ clarifai-11.5.6.dist-info/METADATA,sha256=dE9Pb314d6-aAeFuNetMEyt6GsbveEuJdqnjTbeln7E,22737
123
+ clarifai-11.5.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
124
+ clarifai-11.5.6.dist-info/entry_points.txt,sha256=X9FZ4Z-i_r2Ud1RpZ9sNIFYuu_-9fogzCMCRUD9hyX0,51
125
+ clarifai-11.5.6.dist-info/top_level.txt,sha256=wUMdCQGjkxaynZ6nZ9FAnvBUCgp5RJUVFSy2j-KYo0s,9
126
+ clarifai-11.5.6.dist-info/RECORD,,