clarifai 11.7.4__py3-none-any.whl → 11.7.5rc1__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 +1 -1
- clarifai/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/__pycache__/errors.cpython-311.pyc +0 -0
- clarifai/__pycache__/errors.cpython-39.pyc +0 -0
- clarifai/__pycache__/versions.cpython-311.pyc +0 -0
- clarifai/__pycache__/versions.cpython-39.pyc +0 -0
- clarifai/cli/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/cli/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/base.cpython-39.pyc +0 -0
- clarifai/cli/__pycache__/compute_cluster.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/compute_cluster.cpython-39.pyc +0 -0
- clarifai/cli/__pycache__/deployment.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/deployment.cpython-39.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-39.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-39.pyc +0 -0
- clarifai/cli/__pycache__/pipeline.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/pipeline_step.cpython-311.pyc +0 -0
- clarifai/cli/base.py +2 -2
- clarifai/cli/model.py +264 -144
- clarifai/cli/model_templates.py +243 -0
- clarifai/cli/pipeline.py +31 -11
- clarifai/cli/pipeline_step_templates.py +64 -0
- clarifai/cli/templates/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/cli/templates/__pycache__/pipeline_templates.cpython-311.pyc +0 -0
- clarifai/cli/templates/pipeline_templates.py +34 -28
- clarifai/client/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-39.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-39.pyc +0 -0
- clarifai/client/__pycache__/compute_cluster.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-39.pyc +0 -0
- clarifai/client/__pycache__/deployment.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/deployment.cpython-39.pyc +0 -0
- clarifai/client/__pycache__/input.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/input.cpython-39.pyc +0 -0
- clarifai/client/__pycache__/lister.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/lister.cpython-39.pyc +0 -0
- clarifai/client/__pycache__/model.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/model.cpython-39.pyc +0 -0
- clarifai/client/__pycache__/model_client.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/model_client.cpython-39.pyc +0 -0
- clarifai/client/__pycache__/module.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/nodepool.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/pipeline.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/pipeline_step.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/runner.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/search.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/user.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/workflow.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/client/auth/__pycache__/helper.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/helper.cpython-39.pyc +0 -0
- clarifai/client/auth/__pycache__/register.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/register.cpython-39.pyc +0 -0
- clarifai/client/auth/__pycache__/stub.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/stub.cpython-39.pyc +0 -0
- clarifai/client/pipeline.py +20 -4
- clarifai/client/user.py +172 -0
- clarifai/constants/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/base.cpython-39.pyc +0 -0
- clarifai/constants/__pycache__/dataset.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/dataset.cpython-39.pyc +0 -0
- clarifai/constants/__pycache__/input.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/input.cpython-39.pyc +0 -0
- clarifai/constants/__pycache__/model.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/model.cpython-39.pyc +0 -0
- clarifai/constants/__pycache__/rag.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/search.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/workflow.cpython-311.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/export/__pycache__/inputs_annotations.cpython-311.pyc +0 -0
- clarifai/datasets/export/__pycache__/inputs_annotations.cpython-39.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/upload/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/base.cpython-39.pyc +0 -0
- clarifai/datasets/upload/__pycache__/features.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/features.cpython-39.pyc +0 -0
- clarifai/datasets/upload/__pycache__/image.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/image.cpython-39.pyc +0 -0
- clarifai/datasets/upload/__pycache__/multimodal.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/multimodal.cpython-39.pyc +0 -0
- clarifai/datasets/upload/__pycache__/text.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/text.cpython-39.pyc +0 -0
- clarifai/datasets/upload/__pycache__/utils.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/utils.cpython-39.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/coco_detection.cpython-311.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/imagenet_classification.cpython-311.pyc +0 -0
- clarifai/models/model_serving/README.md +158 -0
- clarifai/models/model_serving/__init__.py +14 -0
- clarifai/models/model_serving/cli/__init__.py +12 -0
- clarifai/models/model_serving/cli/_utils.py +53 -0
- clarifai/models/model_serving/cli/base.py +14 -0
- clarifai/models/model_serving/cli/build.py +79 -0
- clarifai/models/model_serving/cli/clarifai_clis.py +33 -0
- clarifai/models/model_serving/cli/create.py +171 -0
- clarifai/models/model_serving/cli/example_cli.py +34 -0
- clarifai/models/model_serving/cli/login.py +26 -0
- clarifai/models/model_serving/cli/upload.py +179 -0
- clarifai/models/model_serving/constants.py +21 -0
- clarifai/models/model_serving/docs/cli.md +161 -0
- clarifai/models/model_serving/docs/concepts.md +229 -0
- clarifai/models/model_serving/docs/dependencies.md +11 -0
- clarifai/models/model_serving/docs/inference_parameters.md +139 -0
- clarifai/models/model_serving/docs/model_types.md +19 -0
- clarifai/models/model_serving/model_config/__init__.py +16 -0
- clarifai/models/model_serving/model_config/base.py +369 -0
- clarifai/models/model_serving/model_config/config.py +312 -0
- clarifai/models/model_serving/model_config/inference_parameter.py +129 -0
- clarifai/models/model_serving/model_config/model_types_config/multimodal-embedder.yaml +25 -0
- clarifai/models/model_serving/model_config/model_types_config/text-classifier.yaml +19 -0
- clarifai/models/model_serving/model_config/model_types_config/text-embedder.yaml +20 -0
- clarifai/models/model_serving/model_config/model_types_config/text-to-image.yaml +19 -0
- clarifai/models/model_serving/model_config/model_types_config/text-to-text.yaml +19 -0
- clarifai/models/model_serving/model_config/model_types_config/visual-classifier.yaml +22 -0
- clarifai/models/model_serving/model_config/model_types_config/visual-detector.yaml +32 -0
- clarifai/models/model_serving/model_config/model_types_config/visual-embedder.yaml +19 -0
- clarifai/models/model_serving/model_config/model_types_config/visual-segmenter.yaml +19 -0
- clarifai/models/model_serving/model_config/output.py +133 -0
- clarifai/models/model_serving/model_config/triton/__init__.py +14 -0
- clarifai/models/model_serving/model_config/triton/serializer.py +136 -0
- clarifai/models/model_serving/model_config/triton/triton_config.py +182 -0
- clarifai/models/model_serving/model_config/triton/wrappers.py +281 -0
- clarifai/models/model_serving/repo_build/__init__.py +14 -0
- clarifai/models/model_serving/repo_build/build.py +198 -0
- clarifai/models/model_serving/repo_build/static_files/_requirements.txt +2 -0
- clarifai/models/model_serving/repo_build/static_files/base_test.py +169 -0
- clarifai/models/model_serving/repo_build/static_files/inference.py +26 -0
- clarifai/models/model_serving/repo_build/static_files/sample_clarifai_config.yaml +25 -0
- clarifai/models/model_serving/repo_build/static_files/test.py +40 -0
- clarifai/models/model_serving/repo_build/static_files/triton/model.py +75 -0
- clarifai/models/model_serving/utils.py +23 -0
- clarifai/rag/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-311.pyc +0 -0
- clarifai/rag/__pycache__/utils.cpython-311.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/models/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/models/__pycache__/dummy_openai_model.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/mcp_class.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_builder.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_builder.cpython-39.pyc +0 -0
- clarifai/runners/models/__pycache__/model_class.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_runner.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_servicer.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/openai_class.cpython-311.pyc +0 -0
- clarifai/runners/models/base_typed_model.py +238 -0
- clarifai/runners/models/model_builder.py +274 -10
- clarifai/runners/models/model_runner.py +93 -76
- clarifai/runners/models/model_upload.py +607 -0
- clarifai/runners/pipeline_steps/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/pipeline_steps/__pycache__/pipeline_step_builder.cpython-311.pyc +0 -0
- clarifai/runners/pipeline_steps/pipeline_step_builder.py +10 -1
- clarifai/runners/pipelines/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/pipelines/__pycache__/pipeline_builder.cpython-311.pyc +0 -0
- clarifai/runners/server.py +1 -1
- clarifai/runners/utils/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/code_script.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/code_script.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/const.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/loader.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/method_signatures.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/model_utils.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/openai_convertor.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/pipeline_validation.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/serializers.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-311.pyc +0 -0
- clarifai/runners/utils/data_handler.py +231 -0
- clarifai/runners/utils/data_types/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/utils/data_types/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/utils/data_types/__pycache__/data_types.cpython-311.pyc +0 -0
- clarifai/runners/utils/data_types/__pycache__/data_types.cpython-39.pyc +0 -0
- clarifai/runners/utils/data_types.py +471 -0
- clarifai/runners/utils/loader.py +24 -4
- clarifai/runners/utils/temp.py +59 -0
- clarifai/schema/__pycache__/search.cpython-311.pyc +0 -0
- clarifai/urls/__pycache__/helper.cpython-311.pyc +0 -0
- clarifai/urls/__pycache__/helper.cpython-39.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/utils/__pycache__/cli.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/cli.cpython-39.pyc +0 -0
- clarifai/utils/__pycache__/config.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/config.cpython-39.pyc +0 -0
- clarifai/utils/__pycache__/constants.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/constants.cpython-39.pyc +0 -0
- clarifai/utils/__pycache__/logging.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/logging.cpython-39.pyc +0 -0
- clarifai/utils/__pycache__/misc.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/misc.cpython-39.pyc +0 -0
- clarifai/utils/__pycache__/model_train.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/protobuf.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/protobuf.cpython-39.pyc +0 -0
- clarifai/utils/__pycache__/secrets.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/helpers.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/main.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/testset_annotation_parser.cpython-311.pyc +0 -0
- clarifai/utils/misc.py +20 -0
- clarifai/utils/secrets.py +96 -1
- clarifai/workflows/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/workflows/__pycache__/export.cpython-311.pyc +0 -0
- clarifai/workflows/__pycache__/utils.cpython-311.pyc +0 -0
- clarifai/workflows/__pycache__/validate.cpython-311.pyc +0 -0
- {clarifai-11.7.4.dist-info → clarifai-11.7.5rc1.dist-info}/METADATA +1 -1
- clarifai-11.7.5rc1.dist-info/RECORD +339 -0
- {clarifai-11.7.4.dist-info → clarifai-11.7.5rc1.dist-info}/WHEEL +1 -1
- clarifai-11.7.4.dist-info/RECORD +0 -129
- {clarifai-11.7.4.dist-info → clarifai-11.7.5rc1.dist-info}/entry_points.txt +0 -0
- {clarifai-11.7.4.dist-info → clarifai-11.7.5rc1.dist-info}/licenses/LICENSE +0 -0
- {clarifai-11.7.4.dist-info → clarifai-11.7.5rc1.dist-info}/top_level.txt +0 -0
clarifai/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "11.7.
|
1
|
+
__version__ = "11.7.5rc1"
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
clarifai/cli/base.py
CHANGED
@@ -304,8 +304,8 @@ def view(ctx, output_format):
|
|
304
304
|
def run(ctx, script, context=None):
|
305
305
|
"""Execute a script with the current context's environment"""
|
306
306
|
context = ctx.obj.current if not context else context
|
307
|
-
cmd = f'CLARIFAI_USER_ID={context.user_id} CLARIFAI_API_BASE={context.
|
308
|
-
cmd += ' '.join([f'{k}={v}' for k, v in context.
|
307
|
+
cmd = f'CLARIFAI_USER_ID={context.user_id} CLARIFAI_API_BASE={context.api_base} CLARIFAI_PAT={context.pat} '
|
308
|
+
cmd += ' '.join([f'{k}={v}' for k, v in context.to_serializable_dict().items()])
|
309
309
|
cmd += f' {script}'
|
310
310
|
os.system(cmd)
|
311
311
|
|
clarifai/cli/model.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import json
|
1
2
|
import os
|
2
3
|
import shutil
|
3
4
|
import tempfile
|
@@ -25,7 +26,12 @@ from clarifai.utils.constants import (
|
|
25
26
|
DEFAULT_OLLAMA_MODEL_REPO_BRANCH,
|
26
27
|
)
|
27
28
|
from clarifai.utils.logging import logger
|
28
|
-
from clarifai.utils.misc import
|
29
|
+
from clarifai.utils.misc import (
|
30
|
+
GitHubDownloader,
|
31
|
+
clone_github_repo,
|
32
|
+
format_github_repo_url,
|
33
|
+
get_list_of_files_to_download,
|
34
|
+
)
|
29
35
|
|
30
36
|
|
31
37
|
@cli.group(
|
@@ -150,16 +156,27 @@ def init(
|
|
150
156
|
branch = DEFAULT_OLLAMA_MODEL_REPO_BRANCH
|
151
157
|
|
152
158
|
if github_url:
|
159
|
+
downloader = GitHubDownloader(
|
160
|
+
max_retries=3,
|
161
|
+
github_token=github_pat,
|
162
|
+
)
|
163
|
+
if toolkit:
|
164
|
+
owner, repo, _, folder_path = downloader.parse_github_url(url=github_url)
|
165
|
+
else:
|
166
|
+
owner, repo, branch, folder_path = downloader.parse_github_url(url=github_url)
|
167
|
+
logger.info(
|
168
|
+
f"Parsed GitHub repository: owner={owner}, repo={repo}, branch={branch}, folder_path={folder_path}"
|
169
|
+
)
|
170
|
+
files_to_download = get_list_of_files_to_download(
|
171
|
+
downloader, owner, repo, folder_path, branch, []
|
172
|
+
)
|
173
|
+
for i, file in enumerate(files_to_download):
|
174
|
+
files_to_download[i] = f"{i + 1}. {file}"
|
175
|
+
files_to_download = '\n'.join(files_to_download)
|
176
|
+
logger.info(f"Files to be downloaded are:\n{files_to_download}")
|
177
|
+
input("Press Enter to continue...")
|
153
178
|
if not toolkit:
|
154
|
-
owner, repo, branch, folder_path = GitHubDownloader().parse_github_url(url=github_url)
|
155
|
-
logger.info(
|
156
|
-
f"Parsed GitHub repository: owner={owner}, repo={repo}, branch={branch}, folder_path={folder_path}"
|
157
|
-
)
|
158
179
|
if folder_path != "":
|
159
|
-
downloader = GitHubDownloader(
|
160
|
-
max_retries=3,
|
161
|
-
github_token=github_pat,
|
162
|
-
)
|
163
180
|
try:
|
164
181
|
downloader.download_github_folder(
|
165
182
|
url=github_url,
|
@@ -168,6 +185,10 @@ def init(
|
|
168
185
|
)
|
169
186
|
logger.info(f"Successfully downloaded folder contents to {model_path}")
|
170
187
|
logger.info("Model initialization complete with GitHub folder download")
|
188
|
+
logger.info("Next steps:")
|
189
|
+
logger.info("1. Review the model configuration")
|
190
|
+
logger.info("2. Install any required dependencies manually")
|
191
|
+
logger.info("3. Test the model locally using 'clarifai model local-test'")
|
171
192
|
return
|
172
193
|
|
173
194
|
except Exception as e:
|
@@ -235,6 +256,9 @@ def init(
|
|
235
256
|
|
236
257
|
# Fall back to template-based initialization if no GitHub repo or if GitHub repo failed
|
237
258
|
if not github_url:
|
259
|
+
logger.info("Initializing model with default templates...")
|
260
|
+
input("Press Enter to continue...")
|
261
|
+
|
238
262
|
from clarifai.cli.templates.model_templates import (
|
239
263
|
get_config_template,
|
240
264
|
get_model_template,
|
@@ -569,9 +593,7 @@ def local_runner(ctx, model_path, pool_size, verbose):
|
|
569
593
|
"""
|
570
594
|
from clarifai.client.user import User
|
571
595
|
from clarifai.runners.models.model_builder import ModelBuilder
|
572
|
-
from clarifai.runners.server import
|
573
|
-
|
574
|
-
builder = ModelBuilder(model_path, download_validation_only=True)
|
596
|
+
from clarifai.runners.server import ModelServer
|
575
597
|
|
576
598
|
validate_context(ctx)
|
577
599
|
builder = ModelBuilder(model_path, download_validation_only=True)
|
@@ -727,24 +749,39 @@ def local_runner(ctx, model_path, pool_size, verbose):
|
|
727
749
|
|
728
750
|
# Now we need to create a version for the model if no version exists. Only need one version that
|
729
751
|
# mentions it's a local runner.
|
730
|
-
model_versions =
|
752
|
+
model_versions = list(model.list_versions())
|
731
753
|
method_signatures = builder.get_method_signatures(mocking=False)
|
754
|
+
|
755
|
+
create_new_version = False
|
732
756
|
if len(model_versions) == 0:
|
733
757
|
logger.warning("No model versions found. Creating a new version for local runner.")
|
758
|
+
create_new_version = True
|
759
|
+
else:
|
760
|
+
# Try to patch the latest version, and fallback to creating a new one if that fails.
|
761
|
+
latest_version = model_versions[0]
|
762
|
+
logger.warning(f"Attempting to patch latest version: {latest_version.model_version.id}")
|
763
|
+
|
764
|
+
try:
|
765
|
+
patched_model = model.patch_version(
|
766
|
+
version_id=latest_version.model_version.id,
|
767
|
+
pretrained_model_config={"local_dev": True},
|
768
|
+
method_signatures=method_signatures,
|
769
|
+
)
|
770
|
+
patched_model.load_info()
|
771
|
+
version = patched_model.model_version
|
772
|
+
logger.info(f"Successfully patched version {version.id}")
|
773
|
+
ctx.obj.current.CLARIFAI_MODEL_VERSION_ID = version.id
|
774
|
+
ctx.obj.to_yaml() # save to yaml file.
|
775
|
+
except Exception as e:
|
776
|
+
logger.warning(f"Failed to patch model version: {e}. Creating a new version instead.")
|
777
|
+
create_new_version = True
|
778
|
+
|
779
|
+
if create_new_version:
|
734
780
|
version = model.create_version(
|
735
781
|
pretrained_model_config={"local_dev": True}, method_signatures=method_signatures
|
736
782
|
).model_version
|
737
783
|
ctx.obj.current.CLARIFAI_MODEL_VERSION_ID = version.id
|
738
784
|
ctx.obj.to_yaml()
|
739
|
-
else:
|
740
|
-
model.patch_version(
|
741
|
-
version_id=model_versions[0].model_version.id,
|
742
|
-
pretrained_model_config={"local_dev": True},
|
743
|
-
method_signatures=method_signatures,
|
744
|
-
)
|
745
|
-
version = model_versions[0].model_version
|
746
|
-
ctx.obj.current.CLARIFAI_MODEL_VERSION_ID = version.id
|
747
|
-
ctx.obj.to_yaml() # save to yaml file.
|
748
785
|
|
749
786
|
logger.info(f"Current model version {version.id}")
|
750
787
|
|
@@ -895,8 +932,8 @@ def local_runner(ctx, model_path, pool_size, verbose):
|
|
895
932
|
logger.info("✅ Starting local runner...")
|
896
933
|
|
897
934
|
# This reads the config.yaml from the model_path so we alter it above first.
|
898
|
-
|
899
|
-
|
935
|
+
server = ModelServer(model_path)
|
936
|
+
server.serve(
|
900
937
|
pool_size=pool_size,
|
901
938
|
num_threads=pool_size,
|
902
939
|
user_id=user_id,
|
@@ -909,6 +946,114 @@ def local_runner(ctx, model_path, pool_size, verbose):
|
|
909
946
|
)
|
910
947
|
|
911
948
|
|
949
|
+
def _parse_json_param(param_value, param_name):
|
950
|
+
"""Parse JSON parameter with error handling.
|
951
|
+
|
952
|
+
Args:
|
953
|
+
param_value: The JSON string to parse
|
954
|
+
param_name: Name of the parameter for error messages
|
955
|
+
|
956
|
+
Returns:
|
957
|
+
dict: Parsed JSON dictionary
|
958
|
+
|
959
|
+
Raises:
|
960
|
+
ValueError: If JSON parsing fails
|
961
|
+
"""
|
962
|
+
if not param_value or param_value == '{}':
|
963
|
+
return {}
|
964
|
+
try:
|
965
|
+
return json.loads(param_value)
|
966
|
+
except json.JSONDecodeError as e:
|
967
|
+
logger.error(f"ValueError: Invalid JSON in --{param_name} parameter: {e}")
|
968
|
+
raise click.Abort()
|
969
|
+
|
970
|
+
|
971
|
+
def _process_multimodal_inputs(inputs_dict):
|
972
|
+
"""Process inputs to convert URLs and file paths to appropriate data types.
|
973
|
+
|
974
|
+
Args:
|
975
|
+
inputs_dict: Dictionary of input parameters
|
976
|
+
|
977
|
+
Returns:
|
978
|
+
dict: Processed inputs with Image/Video/Audio objects where appropriate
|
979
|
+
"""
|
980
|
+
from clarifai.runners.utils.data_types import Audio, Image, Video
|
981
|
+
|
982
|
+
for key, value in list(inputs_dict.items()):
|
983
|
+
if not isinstance(value, str):
|
984
|
+
continue
|
985
|
+
|
986
|
+
if value.startswith(("http://", "https://")):
|
987
|
+
# Convert URL strings to appropriate data types
|
988
|
+
if "image" in key.lower():
|
989
|
+
inputs_dict[key] = Image(url=value)
|
990
|
+
elif "video" in key.lower():
|
991
|
+
inputs_dict[key] = Video(url=value)
|
992
|
+
elif "audio" in key.lower():
|
993
|
+
inputs_dict[key] = Audio(url=value)
|
994
|
+
elif os.path.isfile(value):
|
995
|
+
# Convert file paths to appropriate data types
|
996
|
+
try:
|
997
|
+
with open(value, "rb") as f:
|
998
|
+
file_bytes = f.read()
|
999
|
+
if "image" in key.lower():
|
1000
|
+
inputs_dict[key] = Image(bytes=file_bytes)
|
1001
|
+
elif "video" in key.lower():
|
1002
|
+
inputs_dict[key] = Video(bytes=file_bytes)
|
1003
|
+
elif "audio" in key.lower():
|
1004
|
+
inputs_dict[key] = Audio(bytes=file_bytes)
|
1005
|
+
except IOError as e:
|
1006
|
+
logger.error(f"ValueError: Failed to read file {value}: {e}")
|
1007
|
+
raise click.Abort()
|
1008
|
+
|
1009
|
+
return inputs_dict
|
1010
|
+
|
1011
|
+
|
1012
|
+
def _validate_model_params(model_id, user_id, app_id, model_url):
|
1013
|
+
"""Validate model identification parameters.
|
1014
|
+
|
1015
|
+
Args:
|
1016
|
+
model_id: Model ID
|
1017
|
+
user_id: User ID
|
1018
|
+
app_id: App ID
|
1019
|
+
model_url: Model URL
|
1020
|
+
|
1021
|
+
Raises:
|
1022
|
+
ValueError: If validation fails
|
1023
|
+
"""
|
1024
|
+
# Check if we have either (model_id, user_id, app_id) or model_url
|
1025
|
+
has_triple = all([model_id, user_id, app_id])
|
1026
|
+
has_url = bool(model_url)
|
1027
|
+
|
1028
|
+
if not (has_triple or has_url):
|
1029
|
+
logger.error(
|
1030
|
+
"ValueError: Either --model_id & --user_id & --app_id or --model_url must be provided."
|
1031
|
+
)
|
1032
|
+
raise click.Abort()
|
1033
|
+
|
1034
|
+
|
1035
|
+
def _validate_compute_params(compute_cluster_id, nodepool_id, deployment_id):
|
1036
|
+
"""Validate compute cluster parameters.
|
1037
|
+
|
1038
|
+
Args:
|
1039
|
+
compute_cluster_id: Compute cluster ID
|
1040
|
+
nodepool_id: Nodepool ID
|
1041
|
+
deployment_id: Deployment ID
|
1042
|
+
|
1043
|
+
Raises:
|
1044
|
+
ValueError: If validation fails
|
1045
|
+
"""
|
1046
|
+
if any([compute_cluster_id, nodepool_id, deployment_id]):
|
1047
|
+
has_cluster_nodepool = bool(compute_cluster_id) and bool(nodepool_id)
|
1048
|
+
has_deployment = bool(deployment_id)
|
1049
|
+
|
1050
|
+
if not (has_cluster_nodepool or has_deployment):
|
1051
|
+
logger.error(
|
1052
|
+
"ValueError: Either --compute_cluster_id & --nodepool_id or --deployment_id must be provided."
|
1053
|
+
)
|
1054
|
+
raise click.Abort()
|
1055
|
+
|
1056
|
+
|
912
1057
|
@model.command(help="Perform a prediction using the model.")
|
913
1058
|
@click.option(
|
914
1059
|
'--config',
|
@@ -920,10 +1065,6 @@ def local_runner(ctx, model_path, pool_size, verbose):
|
|
920
1065
|
@click.option('--user_id', required=False, help='User ID of the model used to predict.')
|
921
1066
|
@click.option('--app_id', required=False, help='App ID of the model used to predict.')
|
922
1067
|
@click.option('--model_url', required=False, help='Model URL of the model used to predict.')
|
923
|
-
@click.option('--file_path', required=False, help='File path of file for the model to predict')
|
924
|
-
@click.option('--url', required=False, help='URL to the file for the model to predict')
|
925
|
-
@click.option('--bytes', required=False, help='Bytes to the file for the model to predict')
|
926
|
-
@click.option('--input_type', required=False, help='Type of input')
|
927
1068
|
@click.option(
|
928
1069
|
'-cc_id',
|
929
1070
|
'--compute_cluster_id',
|
@@ -935,9 +1076,17 @@ def local_runner(ctx, model_path, pool_size, verbose):
|
|
935
1076
|
'-dpl_id', '--deployment_id', required=False, help='Deployment ID to use for the model'
|
936
1077
|
)
|
937
1078
|
@click.option(
|
938
|
-
'
|
1079
|
+
'-dpl_usr_id',
|
1080
|
+
'--deployment_user_id',
|
1081
|
+
required=False,
|
1082
|
+
help='User ID to use for runner selector (organization or user). If not provided, defaults to PAT owner user_id.',
|
1083
|
+
)
|
1084
|
+
@click.option(
|
1085
|
+
'--inputs',
|
1086
|
+
required=False,
|
1087
|
+
help='JSON string of input parameters for pythonic models (e.g., \'{"prompt": "Hello", "max_tokens": 100}\')',
|
939
1088
|
)
|
940
|
-
@click.option('--
|
1089
|
+
@click.option('--method', required=False, default='predict', help='Method to call on the model.')
|
941
1090
|
@click.pass_context
|
942
1091
|
def predict(
|
943
1092
|
ctx,
|
@@ -946,133 +1095,104 @@ def predict(
|
|
946
1095
|
user_id,
|
947
1096
|
app_id,
|
948
1097
|
model_url,
|
949
|
-
file_path,
|
950
|
-
url,
|
951
|
-
bytes,
|
952
|
-
input_type,
|
953
1098
|
compute_cluster_id,
|
954
1099
|
nodepool_id,
|
955
1100
|
deployment_id,
|
956
|
-
|
957
|
-
|
1101
|
+
deployment_user_id,
|
1102
|
+
inputs,
|
1103
|
+
method,
|
958
1104
|
):
|
959
|
-
"""Predict using
|
960
|
-
import json
|
1105
|
+
"""Predict using a Clarifai model.
|
961
1106
|
|
1107
|
+
\b
|
1108
|
+
Model Identification:
|
1109
|
+
Use either --model_url OR the combination of --model_id, --user_id, and --app_id
|
1110
|
+
|
1111
|
+
\b
|
1112
|
+
Input Methods:
|
1113
|
+
--inputs: JSON string with parameters (e.g., '{"prompt": "Hello", "max_tokens": 100}')
|
1114
|
+
--method: Method to call on the model (default is 'predict')
|
1115
|
+
|
1116
|
+
\b
|
1117
|
+
Compute Options:
|
1118
|
+
Use either --deployment_id OR both --compute_cluster_id and --nodepool_id
|
1119
|
+
|
1120
|
+
\b
|
1121
|
+
Examples:
|
1122
|
+
Text model:
|
1123
|
+
clarifai model predict --model_url <url> --inputs '{"prompt": "Hello world"}'
|
1124
|
+
|
1125
|
+
With compute cluster:
|
1126
|
+
clarifai model predict --model_id <id> --user_id <uid> --app_id <aid> \\
|
1127
|
+
--compute_cluster_id <cc_id> --nodepool_id <np_id> \\
|
1128
|
+
--inputs '{"prompt": "Hello"}'
|
1129
|
+
"""
|
962
1130
|
from clarifai.client.model import Model
|
1131
|
+
from clarifai.urls.helper import ClarifaiUrlHelper
|
963
1132
|
from clarifai.utils.cli import from_yaml, validate_context
|
964
1133
|
|
965
1134
|
validate_context(ctx)
|
1135
|
+
|
1136
|
+
# Load configuration from file if provided
|
966
1137
|
if config:
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
('model_url', model_url),
|
989
|
-
('file_path', file_path),
|
990
|
-
('url', url),
|
991
|
-
('bytes', bytes),
|
992
|
-
('input_type', input_type),
|
993
|
-
('compute_cluster_id', compute_cluster_id),
|
994
|
-
('nodepool_id', nodepool_id),
|
995
|
-
('deployment_id', deployment_id),
|
996
|
-
('inference_params', inference_params),
|
997
|
-
('output_config', output_config),
|
998
|
-
]
|
999
|
-
)
|
1000
|
-
if (
|
1001
|
-
sum(
|
1002
|
-
[
|
1003
|
-
opt[1]
|
1004
|
-
for opt in [(model_id, 1), (user_id, 1), (app_id, 1), (model_url, 3)]
|
1005
|
-
if opt[0]
|
1006
|
-
]
|
1007
|
-
)
|
1008
|
-
!= 3
|
1009
|
-
):
|
1010
|
-
raise ValueError(
|
1011
|
-
"Either --model_id & --user_id & --app_id or --model_url must be provided."
|
1012
|
-
)
|
1013
|
-
if compute_cluster_id or nodepool_id or deployment_id:
|
1014
|
-
if (
|
1015
|
-
sum(
|
1016
|
-
[
|
1017
|
-
opt[1]
|
1018
|
-
for opt in [(compute_cluster_id, 0.5), (nodepool_id, 0.5), (deployment_id, 1)]
|
1019
|
-
if opt[0]
|
1020
|
-
]
|
1021
|
-
)
|
1022
|
-
!= 1
|
1023
|
-
):
|
1024
|
-
raise ValueError(
|
1025
|
-
"Either --compute_cluster_id & --nodepool_id or --deployment_id must be provided."
|
1026
|
-
)
|
1027
|
-
if model_url:
|
1028
|
-
model = Model(
|
1029
|
-
url=model_url,
|
1030
|
-
pat=ctx.obj['pat'],
|
1031
|
-
base_url=ctx.obj['base_url'],
|
1032
|
-
compute_cluster_id=compute_cluster_id,
|
1033
|
-
nodepool_id=nodepool_id,
|
1034
|
-
deployment_id=deployment_id,
|
1138
|
+
config_data = from_yaml(config)
|
1139
|
+
# Override None values with config data
|
1140
|
+
model_id = model_id or config_data.get('model_id')
|
1141
|
+
user_id = user_id or config_data.get('user_id')
|
1142
|
+
app_id = app_id or config_data.get('app_id')
|
1143
|
+
model_url = model_url or config_data.get('model_url')
|
1144
|
+
compute_cluster_id = compute_cluster_id or config_data.get('compute_cluster_id')
|
1145
|
+
nodepool_id = nodepool_id or config_data.get('nodepool_id')
|
1146
|
+
deployment_id = deployment_id or config_data.get('deployment_id')
|
1147
|
+
deployment_user_id = deployment_user_id or config_data.get('deployment_user_id')
|
1148
|
+
inputs = inputs or config_data.get('inputs')
|
1149
|
+
method = method or config_data.get('method', 'predict')
|
1150
|
+
|
1151
|
+
# Validate parameters
|
1152
|
+
_validate_model_params(model_id, user_id, app_id, model_url)
|
1153
|
+
_validate_compute_params(compute_cluster_id, nodepool_id, deployment_id)
|
1154
|
+
|
1155
|
+
# Generate model URL if not provided
|
1156
|
+
if not model_url:
|
1157
|
+
model_url = ClarifaiUrlHelper.clarifai_url(
|
1158
|
+
user_id=user_id, app_id=app_id, resource_type="models", resource_id=model_id
|
1035
1159
|
)
|
1160
|
+
logger.debug(f"Using model at URL: {model_url}")
|
1161
|
+
|
1162
|
+
# Create model instance
|
1163
|
+
model = Model(
|
1164
|
+
url=model_url,
|
1165
|
+
pat=ctx.obj.current.pat,
|
1166
|
+
base_url=ctx.obj.current.api_base,
|
1167
|
+
compute_cluster_id=compute_cluster_id,
|
1168
|
+
nodepool_id=nodepool_id,
|
1169
|
+
deployment_id=deployment_id,
|
1170
|
+
deployment_user_id=deployment_user_id,
|
1171
|
+
)
|
1172
|
+
|
1173
|
+
model_methods = model.client.available_methods()
|
1174
|
+
stream_method = (
|
1175
|
+
model.client.method_signature(method).split()[-1][:-1].lower().startswith('iter')
|
1176
|
+
)
|
1177
|
+
|
1178
|
+
# Determine prediction method and execute
|
1179
|
+
if inputs and (method in model_methods):
|
1180
|
+
# Pythonic model prediction with JSON inputs
|
1181
|
+
inputs_dict = _parse_json_param(inputs, "inputs")
|
1182
|
+
inputs_dict = _process_multimodal_inputs(inputs_dict)
|
1183
|
+
model_prediction = getattr(model, method)(**inputs_dict)
|
1036
1184
|
else:
|
1037
|
-
|
1038
|
-
|
1039
|
-
user_id=user_id,
|
1040
|
-
app_id=app_id,
|
1041
|
-
pat=ctx.obj['pat'],
|
1042
|
-
base_url=ctx.obj['base_url'],
|
1043
|
-
compute_cluster_id=compute_cluster_id,
|
1044
|
-
nodepool_id=nodepool_id,
|
1045
|
-
deployment_id=deployment_id,
|
1185
|
+
logger.error(
|
1186
|
+
f"ValueError: The model does not support the '{method}' method. Please check the model's capabilities."
|
1046
1187
|
)
|
1188
|
+
raise click.Abort()
|
1047
1189
|
|
1048
|
-
if
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
model_prediction = model.predict_by_filepath(
|
1055
|
-
filepath=file_path,
|
1056
|
-
input_type=input_type,
|
1057
|
-
inference_params=inference_params,
|
1058
|
-
output_config=output_config,
|
1059
|
-
)
|
1060
|
-
elif url:
|
1061
|
-
model_prediction = model.predict_by_url(
|
1062
|
-
url=url,
|
1063
|
-
input_type=input_type,
|
1064
|
-
inference_params=inference_params,
|
1065
|
-
output_config=output_config,
|
1066
|
-
)
|
1067
|
-
elif bytes:
|
1068
|
-
bytes = str.encode(bytes)
|
1069
|
-
model_prediction = model.predict_by_bytes(
|
1070
|
-
input_bytes=bytes,
|
1071
|
-
input_type=input_type,
|
1072
|
-
inference_params=inference_params,
|
1073
|
-
output_config=output_config,
|
1074
|
-
) ## TO DO: Add support for input_id
|
1075
|
-
click.echo(model_prediction)
|
1190
|
+
if stream_method:
|
1191
|
+
for chunk in model_prediction:
|
1192
|
+
click.echo(chunk, nl=False)
|
1193
|
+
click.echo() # Ensure a newline after the stream ends
|
1194
|
+
else:
|
1195
|
+
click.echo(model_prediction)
|
1076
1196
|
|
1077
1197
|
|
1078
1198
|
@model.command(name="list")
|
@@ -1098,7 +1218,7 @@ def list_model(ctx, user_id, app_id):
|
|
1098
1218
|
from clarifai.client import User
|
1099
1219
|
|
1100
1220
|
try:
|
1101
|
-
pat = ctx.obj.
|
1221
|
+
pat = ctx.obj.current.pat
|
1102
1222
|
except Exception as e:
|
1103
1223
|
pat = None
|
1104
1224
|
|