clarifai 11.6.2__py3-none-any.whl → 11.6.3__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.6.2"
1
+ __version__ = "11.6.3"
clarifai/cli/model.py CHANGED
@@ -17,10 +17,7 @@ from clarifai.utils.constants import (
17
17
  DEFAULT_LOCAL_DEV_NODEPOOL_ID,
18
18
  )
19
19
  from clarifai.utils.logging import logger
20
- from clarifai.utils.misc import (
21
- clone_github_repo,
22
- format_github_repo_url,
23
- )
20
+ from clarifai.utils.misc import clone_github_repo, format_github_repo_url
24
21
 
25
22
 
26
23
  @cli.group(
@@ -60,7 +57,12 @@ def model():
60
57
  required=False,
61
58
  help='Git branch to clone from the GitHub repository. If not specified, the default branch will be used.',
62
59
  )
63
- def init(model_path, model_type_id, github_pat, github_repo, branch):
60
+ @click.option(
61
+ '--local-ollama-model',
62
+ is_flag=True,
63
+ help='Create an Ollama model template by cloning from GitHub repository.',
64
+ )
65
+ def init(model_path, model_type_id, github_pat, github_repo, branch, local_ollama_model):
64
66
  """Initialize a new model directory structure.
65
67
 
66
68
  Creates the following structure in the specified directory:
@@ -76,6 +78,15 @@ def init(model_path, model_type_id, github_pat, github_repo, branch):
76
78
 
77
79
  MODEL_PATH: Path where to create the model directory structure. If not specified, the current directory is used by default.
78
80
  """
81
+ # Handle the --local-ollama-model flag
82
+ if local_ollama_model:
83
+ if github_repo or branch:
84
+ raise click.ClickException(
85
+ "Cannot specify both --local-ollama-model and --github-repo/--branch"
86
+ )
87
+ github_repo = "https://github.com/Clarifai/runners-examples"
88
+ branch = "ollama"
89
+
79
90
  # Resolve the absolute path
80
91
  model_path = os.path.abspath(model_path)
81
92
 
@@ -407,8 +418,16 @@ def run_locally(model_path, port, mode, keep_env, keep_image, skip_dockerfile=Fa
407
418
  required=False,
408
419
  default=".",
409
420
  )
421
+ @click.option(
422
+ "--pool_size",
423
+ type=int,
424
+ is_flag=True,
425
+ default=1, # default to 1 thread for local dev runner to avoid rapid depletion of compute time.
426
+ show_default=True,
427
+ help="The number of threads to use. On community plan, the compute time allocation is drained at a rate proportional to the number of threads.",
428
+ ) # pylint: disable=range-builtin-not-iterating
410
429
  @click.pass_context
411
- def local_dev(ctx, model_path):
430
+ def local_dev(ctx, model_path, pool_size):
412
431
  """Run the model as a local dev runner to help debug your model connected to the API or to
413
432
  leverage local compute resources manually. This relies on many variables being present in the env
414
433
  of the currently selected context. If they are not present then default values will be used to
@@ -731,6 +750,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
731
750
  # This reads the config.yaml from the model_path so we alter it above first.
732
751
  serve(
733
752
  model_path,
753
+ pool_size=pool_size,
754
+ num_threads=pool_size,
734
755
  user_id=user_id,
735
756
  compute_cluster_id=compute_cluster_id,
736
757
  nodepool_id=nodepool_id,
@@ -7,7 +7,7 @@ def get_model_class_template() -> str:
7
7
  """Return the template for a basic ModelClass-based model."""
8
8
  return '''from typing import Iterator, List
9
9
  from clarifai.runners.models.model_class import ModelClass
10
- from clarifai.runners.util.data_utils import Param
10
+ from clarifai.runners.utils.data_utils import Param
11
11
 
12
12
  class MyModel(ModelClass):
13
13
  """A custom model implementation using ModelClass."""
@@ -31,7 +31,7 @@ class MyModel(ModelClass):
31
31
  """This is the method that will be called when the runner is run. It takes in an input and returns an output."""
32
32
  # TODO: please fill in
33
33
  # Implement your prediction logic here
34
- pass # Replace with your actual logic
34
+ return "This is a placeholder response. Please implement your model logic."
35
35
 
36
36
  @ModelClass.method
37
37
  def generate(
@@ -45,7 +45,7 @@ class MyModel(ModelClass):
45
45
  """Example yielding a streamed response."""
46
46
  # TODO: please fill in
47
47
  # Implement your generation logic here
48
- pass # Replace with your actual logic
48
+ yield "This is a placeholder response. Please implement your model logic."
49
49
  '''
50
50
 
51
51
 
@@ -104,7 +104,7 @@ def get_openai_model_class_template() -> str:
104
104
  return '''from typing import List
105
105
  from openai import OpenAI
106
106
  from clarifai.runners.models.openai_class import OpenAIModelClass
107
- from clarifai.runners.util.data_utils import Param
107
+ from clarifai.runners.utils.data_utils import Param
108
108
  from clarifai.runners.utils.openai_convertor import build_openai_messages
109
109
 
110
110
  class MyModel(OpenAIModelClass):
@@ -8,6 +8,7 @@ from string import Template
8
8
  import yaml
9
9
  from clarifai_grpc.grpc.api import resources_pb2, service_pb2
10
10
  from clarifai_grpc.grpc.api.status import status_code_pb2
11
+ from google.protobuf import json_format
11
12
 
12
13
  from clarifai.client.base import BaseClient
13
14
  from clarifai.utils.logging import logger
@@ -106,16 +107,16 @@ class PipelineStepBuilder:
106
107
 
107
108
  def _get_pipeline_step_compute_info(self):
108
109
  """Get pipeline step compute info from config."""
110
+ assert "pipeline_step_compute_info" in self.config, (
111
+ "pipeline_step_compute_info not found in the config file"
112
+ )
109
113
  compute_config = self.config.get("pipeline_step_compute_info", {})
110
114
 
111
- compute_info = resources_pb2.ComputeInfo()
115
+ # Ensure cpu_limit is a string if it exists and is an int
116
+ if 'cpu_limit' in compute_config and isinstance(compute_config['cpu_limit'], int):
117
+ compute_config['cpu_limit'] = str(compute_config['cpu_limit'])
112
118
 
113
- if "cpu_limit" in compute_config:
114
- compute_info.cpu_limit = compute_config["cpu_limit"]
115
- if "cpu_memory" in compute_config:
116
- compute_info.cpu_memory = compute_config["cpu_memory"]
117
- if "num_accelerators" in compute_config:
118
- compute_info.num_accelerators = compute_config["num_accelerators"]
119
+ compute_info = json_format.ParseDict(compute_config, resources_pb2.ComputeInfo())
119
120
 
120
121
  return compute_info
121
122
 
@@ -200,8 +201,11 @@ COPY --link=true requirements.txt config.yaml /home/nonroot/main/
200
201
  PYTHON_VERSION=python_version
201
202
  )
202
203
 
203
- # Write Dockerfile
204
+ # Write Dockerfile if it doesn't exist
204
205
  dockerfile_path = os.path.join(self.folder, 'Dockerfile')
206
+ if os.path.exists(dockerfile_path):
207
+ logger.info(f"Dockerfile already exists at {dockerfile_path}, skipping creation.")
208
+ return
205
209
  with open(dockerfile_path, 'w') as dockerfile:
206
210
  dockerfile.write(dockerfile_content)
207
211
 
@@ -81,6 +81,7 @@ def serve(
81
81
  model_path,
82
82
  port=8000,
83
83
  pool_size=32,
84
+ num_threads=0,
84
85
  max_queue_size=10,
85
86
  max_msg_length=1024 * 1024 * 1024,
86
87
  enable_tls=False,
@@ -98,7 +99,8 @@ def serve(
98
99
 
99
100
  # `num_threads` can be set in config.yaml or via the environment variable CLARIFAI_NUM_THREADS="<integer>".
100
101
  # Note: The value in config.yaml takes precedence over the environment variable.
101
- num_threads = builder.config.get("num_threads")
102
+ if num_threads == 0:
103
+ num_threads = builder.config.get("num_threads")
102
104
  # Setup the grpc server for local development.
103
105
  if grpc:
104
106
  # initialize the servicer with the runner so that it gets the predict(), generate(), stream() classes.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clarifai
3
- Version: 11.6.2
3
+ Version: 11.6.3
4
4
  Home-page: https://github.com/Clarifai/clarifai-python
5
5
  Author: Clarifai
6
6
  Author-email: support@clarifai.com
@@ -19,7 +19,7 @@ Classifier: Operating System :: OS Independent
19
19
  Requires-Python: >=3.8
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
- Requires-Dist: clarifai-grpc>=11.6.0
22
+ Requires-Dist: clarifai-grpc>=11.6.1
23
23
  Requires-Dist: clarifai-protocol>=0.0.25
24
24
  Requires-Dist: numpy>=1.22.0
25
25
  Requires-Dist: tqdm>=4.65.0
@@ -1,4 +1,4 @@
1
- clarifai/__init__.py,sha256=oRlzSjuWA3FSB8u8EiFTs_Z5cSwME4q7lVIMCuT6tEU,23
1
+ clarifai/__init__.py,sha256=KA1lts4rsvHFFgJa89RTeY-d2XENw6-Iw3kZ1H6GvjQ,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
@@ -8,12 +8,12 @@ clarifai/cli/__main__.py,sha256=7nPbLW7Jr2shkgMPvnxpn4xYGMvIcnqluJ69t9w4H_k,74
8
8
  clarifai/cli/base.py,sha256=SNJL5TEcB2rD6pX1v_nrMCH9F7IJ_TD6XXI95cJCi3I,8330
9
9
  clarifai/cli/compute_cluster.py,sha256=8Xss0Obrp6l1XuxJe0luOqU_pf8vXGDRi6jyIe8qR6k,2282
10
10
  clarifai/cli/deployment.py,sha256=9C4I6_kyMxRkWl6h681wc79-3mAtDHtTUaxRv05OZMs,4262
11
- clarifai/cli/model.py,sha256=Kigk6lFy179Puvlgb26Gllra32Sy_WaIayR0ImJ8ZJE,35639
11
+ clarifai/cli/model.py,sha256=EhpujegtnR6j5QtBrea37e_7aMOZBzIWT3CFv0iKFJs,36587
12
12
  clarifai/cli/nodepool.py,sha256=H6OIdUW_EiyDUwZogzEDoYmVwEjLMsgoDlPyE7gjIuU,4245
13
13
  clarifai/cli/pipeline.py,sha256=smWPCK9kLCqnjTCb3w8BAeiAcowY20Bdxfk-OCzCi0I,10601
14
14
  clarifai/cli/pipeline_step.py,sha256=Unrq63w5rjwyhHHmRhV-enztO1HuVTnimAXltNCotQs,3814
15
15
  clarifai/cli/templates/__init__.py,sha256=HbMlZuYOMyVJde73ijNAevmSRUpIttGlHdwyO4W-JOs,44
16
- clarifai/cli/templates/model_templates.py,sha256=_ZonIBnY9KKSJY31KZbUys_uN_k_Txu7Dip12KWfmSU,9633
16
+ clarifai/cli/templates/model_templates.py,sha256=q1dKF5jHhX_1g4qtiYcEbJdWQaxCv2BSEAXI4AR2JOo,9709
17
17
  clarifai/cli/templates/pipeline_step_templates.py,sha256=HU1BoU7wG71MviQAvyecxT_qo70XhTtPGYtoIQ-U-l0,1663
18
18
  clarifai/cli/templates/pipeline_templates.py,sha256=mfHrEoRxICIv00zxfgIct2IpxcMmZ6zjHG8WLF1TPcI,4409
19
19
  clarifai/client/__init__.py,sha256=KXvZFE9TCJf1k_GNUHCZ4icsUlKr1lz0cnBR91LuY8M,765
@@ -71,7 +71,7 @@ clarifai/rag/__init__.py,sha256=wu3PzAzo7uqgrEzuaC9lY_3gj1HFiR3GU3elZIKTT5g,40
71
71
  clarifai/rag/rag.py,sha256=EG3GoFrHFCmA70Tz49_0Jo1-3WIaHSgWGHecPeErcdc,14170
72
72
  clarifai/rag/utils.py,sha256=_gVZdABuMnraCKViLruV75x0F3IpgFXN6amYSGE5_xc,4462
73
73
  clarifai/runners/__init__.py,sha256=wXLaSljH7qLeJCrZdKEnlQh2tNqTQAIZKWOu2rZ6wGs,279
74
- clarifai/runners/server.py,sha256=YNK2ZjVsAzpULJ6cBAJotrL3xSJ_Gx3VodbBY_Fa7kQ,4732
74
+ clarifai/runners/server.py,sha256=ic1qI-ZhlePCpJDP94hWIf8X-_D1fiEp2CdtaMvFFMk,4780
75
75
  clarifai/runners/dockerfile_template/Dockerfile.template,sha256=DUH7F0-uLOV0LTjnPde-9chSzscAAxBAwjTxi9b_l9g,2425
76
76
  clarifai/runners/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
77
77
  clarifai/runners/models/dummy_openai_model.py,sha256=pcmAVbqTTGG4J3BLVjKfvM_SQ-GET_XexIUdLcr9Zvo,8373
@@ -85,7 +85,7 @@ clarifai/runners/models/openai_class.py,sha256=OVYe4dWJPhskyZn53X9yJorzKZA7mjRCq
85
85
  clarifai/runners/models/visual_classifier_class.py,sha256=1ZoLfCT2crrgRbejjTMAIwpTRgQMiH9N9yflOVpFxSg,2721
86
86
  clarifai/runners/models/visual_detector_class.py,sha256=ky4oFAkGCKPpGPdgaOso-n6D3HcmnbKee_8hBsNiV8U,2883
87
87
  clarifai/runners/pipeline_steps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
88
- clarifai/runners/pipeline_steps/pipeline_step_builder.py,sha256=E6Ce3b0RolYLMJHaUrKukphD7ndNZafZ8gIsaONiYUk,21047
88
+ clarifai/runners/pipeline_steps/pipeline_step_builder.py,sha256=X2xWg4QM4kX3cr8JkG1RmAiVE8-XH8XbomjmXa16zmY,21333
89
89
  clarifai/runners/pipelines/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
90
90
  clarifai/runners/pipelines/pipeline_builder.py,sha256=z_bCwjwQPFa_1AYkorhh5r6t6r5hC5K2D8Z1LTEzIpg,12801
91
91
  clarifai/runners/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -119,9 +119,9 @@ clarifai/workflows/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
119
119
  clarifai/workflows/export.py,sha256=HvUYG9N_-UZoRR0-_tdGbZ950_AeBqawSppgUxQebR0,1913
120
120
  clarifai/workflows/utils.py,sha256=ESL3INcouNcLKCh-nMpfXX-YbtCzX7tz7hT57_RGQ3M,2079
121
121
  clarifai/workflows/validate.py,sha256=UhmukyHkfxiMFrPPeBdUTiCOHQT5-shqivlBYEyKTlU,2931
122
- clarifai-11.6.2.dist-info/licenses/LICENSE,sha256=mUqF_d12-qE2n41g7C5_sq-BMLOcj6CNN-jevr15YHU,555
123
- clarifai-11.6.2.dist-info/METADATA,sha256=kTK4jHcDxTNvtoqcZVZ3Th80hByozBNF1H4nENvSLiU,22737
124
- clarifai-11.6.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
125
- clarifai-11.6.2.dist-info/entry_points.txt,sha256=X9FZ4Z-i_r2Ud1RpZ9sNIFYuu_-9fogzCMCRUD9hyX0,51
126
- clarifai-11.6.2.dist-info/top_level.txt,sha256=wUMdCQGjkxaynZ6nZ9FAnvBUCgp5RJUVFSy2j-KYo0s,9
127
- clarifai-11.6.2.dist-info/RECORD,,
122
+ clarifai-11.6.3.dist-info/licenses/LICENSE,sha256=mUqF_d12-qE2n41g7C5_sq-BMLOcj6CNN-jevr15YHU,555
123
+ clarifai-11.6.3.dist-info/METADATA,sha256=0sSfIat8_W12dE83Koh0f6BAVxn5F1OG7OFB-FhjAuc,22737
124
+ clarifai-11.6.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
125
+ clarifai-11.6.3.dist-info/entry_points.txt,sha256=X9FZ4Z-i_r2Ud1RpZ9sNIFYuu_-9fogzCMCRUD9hyX0,51
126
+ clarifai-11.6.3.dist-info/top_level.txt,sha256=wUMdCQGjkxaynZ6nZ9FAnvBUCgp5RJUVFSy2j-KYo0s,9
127
+ clarifai-11.6.3.dist-info/RECORD,,