clarifai 11.6.4rc1__py3-none-any.whl → 11.6.5__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.
Files changed (199) hide show
  1. clarifai/__init__.py +1 -1
  2. clarifai/cli/README.md +39 -0
  3. clarifai/cli/base.py +107 -118
  4. clarifai/cli/model.py +62 -79
  5. clarifai/client/app.py +1 -1
  6. clarifai/client/auth/helper.py +7 -2
  7. clarifai/client/base.py +35 -8
  8. clarifai/client/compute_cluster.py +1 -1
  9. clarifai/client/model.py +3 -1
  10. clarifai/client/nodepool.py +4 -2
  11. clarifai/client/user.py +4 -2
  12. clarifai/runners/models/model_runner.py +55 -0
  13. clarifai/runners/server.py +1 -0
  14. clarifai/runners/utils/code_script.py +52 -46
  15. clarifai/runners/utils/url_fetcher.py +51 -12
  16. clarifai/utils/cli.py +127 -0
  17. clarifai/utils/constants.py +5 -0
  18. clarifai/utils/misc.py +49 -1
  19. {clarifai-11.6.4rc1.dist-info → clarifai-11.6.5.dist-info}/METADATA +2 -2
  20. clarifai-11.6.5.dist-info/RECORD +127 -0
  21. {clarifai-11.6.4rc1.dist-info → clarifai-11.6.5.dist-info}/WHEEL +1 -1
  22. clarifai/__pycache__/__init__.cpython-311.pyc +0 -0
  23. clarifai/__pycache__/__init__.cpython-39.pyc +0 -0
  24. clarifai/__pycache__/errors.cpython-311.pyc +0 -0
  25. clarifai/__pycache__/errors.cpython-39.pyc +0 -0
  26. clarifai/__pycache__/versions.cpython-311.pyc +0 -0
  27. clarifai/__pycache__/versions.cpython-39.pyc +0 -0
  28. clarifai/cli/__pycache__/__init__.cpython-39.pyc +0 -0
  29. clarifai/cli/__pycache__/base.cpython-39.pyc +0 -0
  30. clarifai/cli/__pycache__/compute_cluster.cpython-39.pyc +0 -0
  31. clarifai/cli/__pycache__/deployment.cpython-39.pyc +0 -0
  32. clarifai/cli/__pycache__/model.cpython-39.pyc +0 -0
  33. clarifai/cli/__pycache__/nodepool.cpython-39.pyc +0 -0
  34. clarifai/cli/model_templates.py +0 -243
  35. clarifai/cli/pipeline_step_templates.py +0 -64
  36. clarifai/client/__pycache__/__init__.cpython-311.pyc +0 -0
  37. clarifai/client/__pycache__/__init__.cpython-39.pyc +0 -0
  38. clarifai/client/__pycache__/app.cpython-311.pyc +0 -0
  39. clarifai/client/__pycache__/app.cpython-39.pyc +0 -0
  40. clarifai/client/__pycache__/base.cpython-311.pyc +0 -0
  41. clarifai/client/__pycache__/base.cpython-39.pyc +0 -0
  42. clarifai/client/__pycache__/compute_cluster.cpython-311.pyc +0 -0
  43. clarifai/client/__pycache__/dataset.cpython-311.pyc +0 -0
  44. clarifai/client/__pycache__/dataset.cpython-39.pyc +0 -0
  45. clarifai/client/__pycache__/deployment.cpython-311.pyc +0 -0
  46. clarifai/client/__pycache__/deployment.cpython-39.pyc +0 -0
  47. clarifai/client/__pycache__/input.cpython-311.pyc +0 -0
  48. clarifai/client/__pycache__/input.cpython-39.pyc +0 -0
  49. clarifai/client/__pycache__/lister.cpython-311.pyc +0 -0
  50. clarifai/client/__pycache__/lister.cpython-39.pyc +0 -0
  51. clarifai/client/__pycache__/model.cpython-311.pyc +0 -0
  52. clarifai/client/__pycache__/model.cpython-39.pyc +0 -0
  53. clarifai/client/__pycache__/model_client.cpython-311.pyc +0 -0
  54. clarifai/client/__pycache__/model_client.cpython-39.pyc +0 -0
  55. clarifai/client/__pycache__/module.cpython-311.pyc +0 -0
  56. clarifai/client/__pycache__/nodepool.cpython-311.pyc +0 -0
  57. clarifai/client/__pycache__/runner.cpython-311.pyc +0 -0
  58. clarifai/client/__pycache__/search.cpython-311.pyc +0 -0
  59. clarifai/client/__pycache__/user.cpython-311.pyc +0 -0
  60. clarifai/client/__pycache__/workflow.cpython-311.pyc +0 -0
  61. clarifai/client/auth/__pycache__/__init__.cpython-311.pyc +0 -0
  62. clarifai/client/auth/__pycache__/__init__.cpython-39.pyc +0 -0
  63. clarifai/client/auth/__pycache__/helper.cpython-311.pyc +0 -0
  64. clarifai/client/auth/__pycache__/helper.cpython-39.pyc +0 -0
  65. clarifai/client/auth/__pycache__/register.cpython-311.pyc +0 -0
  66. clarifai/client/auth/__pycache__/register.cpython-39.pyc +0 -0
  67. clarifai/client/auth/__pycache__/stub.cpython-311.pyc +0 -0
  68. clarifai/client/auth/__pycache__/stub.cpython-39.pyc +0 -0
  69. clarifai/constants/__pycache__/base.cpython-311.pyc +0 -0
  70. clarifai/constants/__pycache__/base.cpython-39.pyc +0 -0
  71. clarifai/constants/__pycache__/dataset.cpython-311.pyc +0 -0
  72. clarifai/constants/__pycache__/dataset.cpython-39.pyc +0 -0
  73. clarifai/constants/__pycache__/input.cpython-311.pyc +0 -0
  74. clarifai/constants/__pycache__/input.cpython-39.pyc +0 -0
  75. clarifai/constants/__pycache__/model.cpython-311.pyc +0 -0
  76. clarifai/constants/__pycache__/model.cpython-39.pyc +0 -0
  77. clarifai/constants/__pycache__/search.cpython-311.pyc +0 -0
  78. clarifai/constants/__pycache__/workflow.cpython-311.pyc +0 -0
  79. clarifai/datasets/__pycache__/__init__.cpython-311.pyc +0 -0
  80. clarifai/datasets/__pycache__/__init__.cpython-39.pyc +0 -0
  81. clarifai/datasets/export/__pycache__/__init__.cpython-311.pyc +0 -0
  82. clarifai/datasets/export/__pycache__/__init__.cpython-39.pyc +0 -0
  83. clarifai/datasets/export/__pycache__/inputs_annotations.cpython-311.pyc +0 -0
  84. clarifai/datasets/export/__pycache__/inputs_annotations.cpython-39.pyc +0 -0
  85. clarifai/datasets/upload/__pycache__/__init__.cpython-311.pyc +0 -0
  86. clarifai/datasets/upload/__pycache__/__init__.cpython-39.pyc +0 -0
  87. clarifai/datasets/upload/__pycache__/base.cpython-311.pyc +0 -0
  88. clarifai/datasets/upload/__pycache__/base.cpython-39.pyc +0 -0
  89. clarifai/datasets/upload/__pycache__/features.cpython-311.pyc +0 -0
  90. clarifai/datasets/upload/__pycache__/features.cpython-39.pyc +0 -0
  91. clarifai/datasets/upload/__pycache__/image.cpython-311.pyc +0 -0
  92. clarifai/datasets/upload/__pycache__/image.cpython-39.pyc +0 -0
  93. clarifai/datasets/upload/__pycache__/multimodal.cpython-311.pyc +0 -0
  94. clarifai/datasets/upload/__pycache__/multimodal.cpython-39.pyc +0 -0
  95. clarifai/datasets/upload/__pycache__/text.cpython-311.pyc +0 -0
  96. clarifai/datasets/upload/__pycache__/text.cpython-39.pyc +0 -0
  97. clarifai/datasets/upload/__pycache__/utils.cpython-311.pyc +0 -0
  98. clarifai/datasets/upload/__pycache__/utils.cpython-39.pyc +0 -0
  99. clarifai/models/model_serving/README.md +0 -158
  100. clarifai/models/model_serving/__init__.py +0 -14
  101. clarifai/models/model_serving/cli/__init__.py +0 -12
  102. clarifai/models/model_serving/cli/_utils.py +0 -53
  103. clarifai/models/model_serving/cli/base.py +0 -14
  104. clarifai/models/model_serving/cli/build.py +0 -79
  105. clarifai/models/model_serving/cli/clarifai_clis.py +0 -33
  106. clarifai/models/model_serving/cli/create.py +0 -171
  107. clarifai/models/model_serving/cli/example_cli.py +0 -34
  108. clarifai/models/model_serving/cli/login.py +0 -26
  109. clarifai/models/model_serving/cli/upload.py +0 -179
  110. clarifai/models/model_serving/constants.py +0 -21
  111. clarifai/models/model_serving/docs/cli.md +0 -161
  112. clarifai/models/model_serving/docs/concepts.md +0 -229
  113. clarifai/models/model_serving/docs/dependencies.md +0 -11
  114. clarifai/models/model_serving/docs/inference_parameters.md +0 -139
  115. clarifai/models/model_serving/docs/model_types.md +0 -19
  116. clarifai/models/model_serving/model_config/__init__.py +0 -16
  117. clarifai/models/model_serving/model_config/base.py +0 -369
  118. clarifai/models/model_serving/model_config/config.py +0 -312
  119. clarifai/models/model_serving/model_config/inference_parameter.py +0 -129
  120. clarifai/models/model_serving/model_config/model_types_config/multimodal-embedder.yaml +0 -25
  121. clarifai/models/model_serving/model_config/model_types_config/text-classifier.yaml +0 -19
  122. clarifai/models/model_serving/model_config/model_types_config/text-embedder.yaml +0 -20
  123. clarifai/models/model_serving/model_config/model_types_config/text-to-image.yaml +0 -19
  124. clarifai/models/model_serving/model_config/model_types_config/text-to-text.yaml +0 -19
  125. clarifai/models/model_serving/model_config/model_types_config/visual-classifier.yaml +0 -22
  126. clarifai/models/model_serving/model_config/model_types_config/visual-detector.yaml +0 -32
  127. clarifai/models/model_serving/model_config/model_types_config/visual-embedder.yaml +0 -19
  128. clarifai/models/model_serving/model_config/model_types_config/visual-segmenter.yaml +0 -19
  129. clarifai/models/model_serving/model_config/output.py +0 -133
  130. clarifai/models/model_serving/model_config/triton/__init__.py +0 -14
  131. clarifai/models/model_serving/model_config/triton/serializer.py +0 -136
  132. clarifai/models/model_serving/model_config/triton/triton_config.py +0 -182
  133. clarifai/models/model_serving/model_config/triton/wrappers.py +0 -281
  134. clarifai/models/model_serving/repo_build/__init__.py +0 -14
  135. clarifai/models/model_serving/repo_build/build.py +0 -198
  136. clarifai/models/model_serving/repo_build/static_files/_requirements.txt +0 -2
  137. clarifai/models/model_serving/repo_build/static_files/base_test.py +0 -169
  138. clarifai/models/model_serving/repo_build/static_files/inference.py +0 -26
  139. clarifai/models/model_serving/repo_build/static_files/sample_clarifai_config.yaml +0 -25
  140. clarifai/models/model_serving/repo_build/static_files/test.py +0 -40
  141. clarifai/models/model_serving/repo_build/static_files/triton/model.py +0 -75
  142. clarifai/models/model_serving/utils.py +0 -23
  143. clarifai/runners/__pycache__/__init__.cpython-311.pyc +0 -0
  144. clarifai/runners/__pycache__/__init__.cpython-39.pyc +0 -0
  145. clarifai/runners/models/__pycache__/__init__.cpython-311.pyc +0 -0
  146. clarifai/runners/models/__pycache__/__init__.cpython-39.pyc +0 -0
  147. clarifai/runners/models/__pycache__/mcp_class.cpython-311.pyc +0 -0
  148. clarifai/runners/models/__pycache__/model_builder.cpython-311.pyc +0 -0
  149. clarifai/runners/models/__pycache__/model_builder.cpython-39.pyc +0 -0
  150. clarifai/runners/models/__pycache__/model_class.cpython-311.pyc +0 -0
  151. clarifai/runners/models/__pycache__/model_runner.cpython-311.pyc +0 -0
  152. clarifai/runners/models/__pycache__/openai_class.cpython-311.pyc +0 -0
  153. clarifai/runners/models/base_typed_model.py +0 -238
  154. clarifai/runners/models/model_upload.py +0 -607
  155. clarifai/runners/utils/__pycache__/__init__.cpython-311.pyc +0 -0
  156. clarifai/runners/utils/__pycache__/__init__.cpython-39.pyc +0 -0
  157. clarifai/runners/utils/__pycache__/code_script.cpython-311.pyc +0 -0
  158. clarifai/runners/utils/__pycache__/code_script.cpython-39.pyc +0 -0
  159. clarifai/runners/utils/__pycache__/const.cpython-311.pyc +0 -0
  160. clarifai/runners/utils/__pycache__/data_utils.cpython-311.pyc +0 -0
  161. clarifai/runners/utils/__pycache__/data_utils.cpython-39.pyc +0 -0
  162. clarifai/runners/utils/__pycache__/loader.cpython-311.pyc +0 -0
  163. clarifai/runners/utils/__pycache__/method_signatures.cpython-311.pyc +0 -0
  164. clarifai/runners/utils/__pycache__/model_utils.cpython-311.pyc +0 -0
  165. clarifai/runners/utils/__pycache__/openai_convertor.cpython-311.pyc +0 -0
  166. clarifai/runners/utils/__pycache__/serializers.cpython-311.pyc +0 -0
  167. clarifai/runners/utils/__pycache__/url_fetcher.cpython-311.pyc +0 -0
  168. clarifai/runners/utils/data_handler.py +0 -231
  169. clarifai/runners/utils/data_types/__pycache__/__init__.cpython-311.pyc +0 -0
  170. clarifai/runners/utils/data_types/__pycache__/__init__.cpython-39.pyc +0 -0
  171. clarifai/runners/utils/data_types/__pycache__/data_types.cpython-311.pyc +0 -0
  172. clarifai/runners/utils/data_types/__pycache__/data_types.cpython-39.pyc +0 -0
  173. clarifai/runners/utils/data_types.py +0 -471
  174. clarifai/runners/utils/temp.py +0 -59
  175. clarifai/schema/__pycache__/search.cpython-311.pyc +0 -0
  176. clarifai/urls/__pycache__/helper.cpython-311.pyc +0 -0
  177. clarifai/urls/__pycache__/helper.cpython-39.pyc +0 -0
  178. clarifai/utils/__pycache__/__init__.cpython-311.pyc +0 -0
  179. clarifai/utils/__pycache__/__init__.cpython-39.pyc +0 -0
  180. clarifai/utils/__pycache__/cli.cpython-39.pyc +0 -0
  181. clarifai/utils/__pycache__/config.cpython-311.pyc +0 -0
  182. clarifai/utils/__pycache__/config.cpython-39.pyc +0 -0
  183. clarifai/utils/__pycache__/constants.cpython-311.pyc +0 -0
  184. clarifai/utils/__pycache__/constants.cpython-39.pyc +0 -0
  185. clarifai/utils/__pycache__/logging.cpython-311.pyc +0 -0
  186. clarifai/utils/__pycache__/logging.cpython-39.pyc +0 -0
  187. clarifai/utils/__pycache__/misc.cpython-311.pyc +0 -0
  188. clarifai/utils/__pycache__/misc.cpython-39.pyc +0 -0
  189. clarifai/utils/__pycache__/model_train.cpython-311.pyc +0 -0
  190. clarifai/utils/__pycache__/protobuf.cpython-311.pyc +0 -0
  191. clarifai/utils/__pycache__/protobuf.cpython-39.pyc +0 -0
  192. clarifai/workflows/__pycache__/__init__.cpython-311.pyc +0 -0
  193. clarifai/workflows/__pycache__/export.cpython-311.pyc +0 -0
  194. clarifai/workflows/__pycache__/utils.cpython-311.pyc +0 -0
  195. clarifai/workflows/__pycache__/validate.cpython-311.pyc +0 -0
  196. clarifai-11.6.4rc1.dist-info/RECORD +0 -301
  197. {clarifai-11.6.4rc1.dist-info → clarifai-11.6.5.dist-info}/entry_points.txt +0 -0
  198. {clarifai-11.6.4rc1.dist-info → clarifai-11.6.5.dist-info}/licenses/LICENSE +0 -0
  199. {clarifai-11.6.4rc1.dist-info → clarifai-11.6.5.dist-info}/top_level.txt +0 -0
clarifai/utils/cli.py CHANGED
@@ -220,3 +220,130 @@ def validate_context_auth(pat: str, user_id: str, api_base: str = None):
220
220
  logger.error(f"❌ Validation failed: \n{error_msg}")
221
221
  logger.error("Please check your credentials and try again.")
222
222
  raise click.Abort() # Exit without saving the configuration
223
+
224
+
225
+ def customize_ollama_model(model_path, model_name, port, context_length):
226
+ """Customize the Ollama model name in the cloned template files.
227
+ Args:
228
+ model_path: Path to the cloned model directory
229
+ model_name: The model name to set (e.g., 'llama3.1', 'mistral')
230
+
231
+ """
232
+ model_py_path = os.path.join(model_path, "1", "model.py")
233
+
234
+ if not os.path.exists(model_py_path):
235
+ logger.warning(f"Model file {model_py_path} not found, skipping model name customization")
236
+ return
237
+
238
+ try:
239
+ # Read the model.py file
240
+ with open(model_py_path, 'r') as file:
241
+ content = file.read()
242
+ if model_name:
243
+ # Replace the default model name in the load_model method
244
+ content = content.replace(
245
+ 'self.model = os.environ.get("OLLAMA_MODEL_NAME", \'llama3.2\')',
246
+ f'self.model = os.environ.get("OLLAMA_MODEL_NAME", \'{model_name}\')',
247
+ )
248
+
249
+ if port:
250
+ # Replace the default port variable in the model.py file
251
+ content = content.replace("PORT = '23333'", f"PORT = '{port}'")
252
+
253
+ if context_length:
254
+ # Replace the default context length variable in the model.py file
255
+ content = content.replace(
256
+ "context_length = '8192'", f"context_length = '{context_length}'"
257
+ )
258
+
259
+ # Write the modified content back to model.py
260
+ with open(model_py_path, 'w') as file:
261
+ file.write(content)
262
+
263
+ except Exception as e:
264
+ logger.error(f"Failed to customize Ollama model name in {model_py_path}: {e}")
265
+ raise
266
+
267
+
268
+ def check_ollama_installed():
269
+ """Check if the Ollama CLI is installed."""
270
+ try:
271
+ import subprocess
272
+
273
+ result = subprocess.run(
274
+ ['ollama', '--version'], capture_output=True, text=True, check=False
275
+ )
276
+ if result.returncode == 0:
277
+ return True
278
+ else:
279
+ return False
280
+ except FileNotFoundError:
281
+ return False
282
+
283
+
284
+ def _is_package_installed(package_name):
285
+ """Helper function to check if a single package in requirements.txt is installed."""
286
+ import importlib.metadata
287
+
288
+ try:
289
+ importlib.metadata.distribution(package_name)
290
+ logger.debug(f"✅ {package_name} - installed")
291
+ return True
292
+ except importlib.metadata.PackageNotFoundError:
293
+ logger.debug(f"❌ {package_name} - not installed")
294
+ return False
295
+ except Exception as e:
296
+ logger.warning(f"Error checking {package_name}: {e}")
297
+ return False
298
+
299
+
300
+ def check_requirements_installed(model_path):
301
+ """Check if all dependencies in requirements.txt are installed."""
302
+ import re
303
+ from pathlib import Path
304
+
305
+ requirements_path = Path(model_path) / "requirements.txt"
306
+
307
+ if not requirements_path.exists():
308
+ logger.warning(f"requirements.txt not found at {requirements_path}")
309
+ return True
310
+
311
+ try:
312
+ package_pattern = re.compile(r'^([a-zA-Z0-9_-]+)')
313
+
314
+ # Getting package name and version (for logging)
315
+ requirements = [
316
+ (match.group(1), pack)
317
+ for line in requirements_path.read_text().splitlines()
318
+ if (pack := line.strip())
319
+ and not line.startswith('#')
320
+ and (match := package_pattern.match(line))
321
+ ]
322
+
323
+ if not requirements:
324
+ logger.info("No dependencies found in requirements.txt")
325
+ return True
326
+
327
+ logger.info(f"Checking {len(requirements)} dependencies...")
328
+
329
+ missing = [
330
+ full_req
331
+ for package_name, full_req in requirements
332
+ if not _is_package_installed(package_name)
333
+ ]
334
+
335
+ if not missing:
336
+ logger.info(f"✅ All {len(requirements)} dependencies are installed!")
337
+ return True
338
+
339
+ # Report missing packages
340
+ logger.error(
341
+ f"❌ {len(missing)} of {len(requirements)} required packages are missing in the current environment"
342
+ )
343
+ logger.error("\n".join(f" - {pkg}" for pkg in missing))
344
+ logger.warning(f"To install: pip install -r {requirements_path}")
345
+ return False
346
+
347
+ except Exception as e:
348
+ logger.error(f"Failed to check requirements: {e}")
349
+ return False
@@ -64,3 +64,8 @@ DEFAULT_LOCAL_RUNNER_NODEPOOL_CONFIG = {
64
64
  }
65
65
  DEFAULT_OLLAMA_MODEL_REPO = "https://github.com/Clarifai/runners-examples"
66
66
  DEFAULT_OLLAMA_MODEL_REPO_BRANCH = "ollama"
67
+
68
+ STATUS_OK = "200 OK"
69
+ STATUS_MIXED = "207 MIXED"
70
+ STATUS_FAIL = "500 FAIL"
71
+ STATUS_UNKNOWN = "UNKNOWN"
clarifai/utils/misc.py CHANGED
@@ -78,6 +78,53 @@ def get_from_env(key: str, env_key: str) -> str:
78
78
  )
79
79
 
80
80
 
81
+ def get_from_dict_env_or_config(key: str, env_key: str, **data) -> str:
82
+ """Get a value from a dictionary, environment variable, or CLI config context."""
83
+ # First try the provided data/kwargs
84
+ if key in data and data[key]:
85
+ return data[key]
86
+
87
+ # Then try environment variables
88
+ if env_key in os.environ and os.environ[env_key]:
89
+ return os.environ[env_key]
90
+
91
+ # Finally try CLI config context as fallback
92
+ try:
93
+ from clarifai.utils.config import Config
94
+ from clarifai.utils.constants import DEFAULT_CONFIG
95
+
96
+ config = Config.from_yaml(filename=DEFAULT_CONFIG)
97
+ current_context = config.current
98
+
99
+ # Convert env_key to the attribute name expected by Context
100
+ # e.g., CLARIFAI_PAT -> pat, CLARIFAI_USER_ID -> user_id, CLARIFAI_API_BASE -> api_base
101
+ if env_key == "CLARIFAI_PAT":
102
+ attr_name = "pat"
103
+ elif env_key == "CLARIFAI_USER_ID":
104
+ attr_name = "user_id"
105
+ elif env_key == "CLARIFAI_API_BASE":
106
+ attr_name = "api_base"
107
+ else:
108
+ # For other cases, convert CLARIFAI_SOMETHING to something
109
+ attr_name = env_key.replace("CLARIFAI_", "").lower()
110
+
111
+ if hasattr(current_context, attr_name):
112
+ value = getattr(current_context, attr_name)
113
+ if value:
114
+ return value
115
+ except Exception:
116
+ # If CLI config loading fails, fall through to raise error
117
+ pass
118
+
119
+ # If all methods fail, raise an error suggesting clarifai login
120
+ raise UserError(
121
+ f"Configuration Required. Could not find '{key}'. Please provide it in one of the following ways:\n\n"
122
+ f"- Pass '{key}' as a named parameter to your function.\n"
123
+ f"- Set the {env_key} environment variable in your environment.\n"
124
+ f"- Run `clarifai login` in your terminal to configure CLI authentication."
125
+ )
126
+
127
+
81
128
  def concept_relations_accumulation(
82
129
  relations_dict: Dict[str, Any], subject_concept: str, object_concept: str, predicate: str
83
130
  ) -> Dict[str, Any]:
@@ -242,7 +289,8 @@ class GitHubDownloader:
242
289
  return owner, repo, branch, folder_path
243
290
 
244
291
  except Exception as e:
245
- raise ValueError(f"Failed to parse GitHub URL: {e}")
292
+ logger.error(f"Failed to parse GitHub URL: {e}")
293
+ sys.exit(1)
246
294
 
247
295
  def get_folder_contents(self, owner: str, repo: str, path: str, branch: str = 'main') -> list:
248
296
  api_url = f"https://api.github.com/repos/{owner}/{repo}/contents/{path}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clarifai
3
- Version: 11.6.4rc1
3
+ Version: 11.6.5
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.1
22
+ Requires-Dist: clarifai-grpc>=11.6.4
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
@@ -0,0 +1,127 @@
1
+ clarifai/__init__.py,sha256=v1UMok1JAGjDjikTzsL5Gx86ndvD68_szNQj1A3xaVk,23
2
+ clarifai/cli.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ clarifai/errors.py,sha256=GXa6D4v_L404J83jnRNFPH7s-1V9lk7w6Ws99f1g-AY,2772
4
+ clarifai/versions.py,sha256=ecSuEB_nOL2XSoYHDw2n23XUbm_KPOGjudMXmQrGdS8,224
5
+ clarifai/cli/README.md,sha256=u-7Mgg1ZrygEokXS3RJepddq3GjhkSVkdUzXvxnCoIE,2633
6
+ clarifai/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ clarifai/cli/__main__.py,sha256=7nPbLW7Jr2shkgMPvnxpn4xYGMvIcnqluJ69t9w4H_k,74
8
+ clarifai/cli/base.py,sha256=rMmbjo5VIiAq35cTFb9IrNPVFBfiXU366_rv7V4ULus,8889
9
+ clarifai/cli/compute_cluster.py,sha256=8Xss0Obrp6l1XuxJe0luOqU_pf8vXGDRi6jyIe8qR6k,2282
10
+ clarifai/cli/deployment.py,sha256=9C4I6_kyMxRkWl6h681wc79-3mAtDHtTUaxRv05OZMs,4262
11
+ clarifai/cli/model.py,sha256=bL6jiM8UMBZUG7yDPVNvrulWgV2-PfGWj3R52kyG0PI,41276
12
+ clarifai/cli/nodepool.py,sha256=H6OIdUW_EiyDUwZogzEDoYmVwEjLMsgoDlPyE7gjIuU,4245
13
+ clarifai/cli/pipeline.py,sha256=smWPCK9kLCqnjTCb3w8BAeiAcowY20Bdxfk-OCzCi0I,10601
14
+ clarifai/cli/pipeline_step.py,sha256=Unrq63w5rjwyhHHmRhV-enztO1HuVTnimAXltNCotQs,3814
15
+ clarifai/cli/templates/__init__.py,sha256=HbMlZuYOMyVJde73ijNAevmSRUpIttGlHdwyO4W-JOs,44
16
+ clarifai/cli/templates/model_templates.py,sha256=q1dKF5jHhX_1g4qtiYcEbJdWQaxCv2BSEAXI4AR2JOo,9709
17
+ clarifai/cli/templates/pipeline_step_templates.py,sha256=HU1BoU7wG71MviQAvyecxT_qo70XhTtPGYtoIQ-U-l0,1663
18
+ clarifai/cli/templates/pipeline_templates.py,sha256=mfHrEoRxICIv00zxfgIct2IpxcMmZ6zjHG8WLF1TPcI,4409
19
+ clarifai/client/__init__.py,sha256=KXvZFE9TCJf1k_GNUHCZ4icsUlKr1lz0cnBR91LuY8M,765
20
+ clarifai/client/app.py,sha256=eMXFYea-bopfcQ30JuAQqdhzhEsxAB3w4vDOsXOVO6c,41445
21
+ clarifai/client/base.py,sha256=aduMVVSPUSQ-MsDpj4yuHmCTUNbCTPt76dhRZ14euVg,10284
22
+ clarifai/client/compute_cluster.py,sha256=q-JuBai4pKpSeDAn-P61IKyGjizX-IV-O5huWAYx5DU,10279
23
+ clarifai/client/dataset.py,sha256=OgdpZkQ_vYmRxL8-qphcNozpvPV1bWTlte9Jv6UkKb8,35299
24
+ clarifai/client/deployment.py,sha256=QBf0tzkKBEpzNgmOEmWUJMOlVWdFEFc70Y44o8y75Gs,2875
25
+ clarifai/client/input.py,sha256=jpX47qwn7aUBBIEuSSLHF5jk70XaWEh0prD065c9b-E,51205
26
+ clarifai/client/lister.py,sha256=1YEm2suNxPaJO4x9V5szgD_YX6N_00vgSO-7m0HagY8,2208
27
+ clarifai/client/model.py,sha256=DeB-es6rp0FJQVY46oO2eR_-Ux5tTmkM_qYsN1X6WcE,90793
28
+ clarifai/client/model_client.py,sha256=4gIS0mKBdiNMA1x_6Wo6H7WbfLsmQix64EpONcQjQV4,37129
29
+ clarifai/client/module.py,sha256=jLViQYvVV3FmRN_ivvbk83uwsx7CgYGeEx4dYAr6yD4,4537
30
+ clarifai/client/nodepool.py,sha256=Qjk_-GfjtdlQdR5hHh28kRENW7rLi6zNqxeFYf7dioc,16473
31
+ clarifai/client/pipeline.py,sha256=Hy3qnSX1pcoi-OAtdzr-qxkRYi1CxsaUzsfS3GDtETM,14358
32
+ clarifai/client/runner.py,sha256=5xCiqByGGscfNm0IjHelhDTx8-9l8G0C3HL-3YZogK8,2253
33
+ clarifai/client/search.py,sha256=3LLfATrdU43a0mRNITmJV-E53bhfafZkYsbwkTtlnyU,15661
34
+ clarifai/client/user.py,sha256=ssfqHAE_GOh1c4dX74HH1xC09Rv4pVWxD08PTIfSjS8,22071
35
+ clarifai/client/workflow.py,sha256=Bqh8lAmJcSbviJebckchTxucYlU11UQEhFSov7elpsk,13417
36
+ clarifai/client/auth/__init__.py,sha256=7EwR0NrozkAUwpUnCsqXvE_p0wqx_SelXlSpKShKJK0,136
37
+ clarifai/client/auth/helper.py,sha256=eitq1uQBoJ1TPjsTtbJ9g7eqT3mFm9vgc4HQR1s-zNg,16283
38
+ clarifai/client/auth/register.py,sha256=xIg1OoZ_GGnc0KQKII-R6q_cKN1JXW3BGcU2eyS-Kkc,871
39
+ clarifai/client/auth/stub.py,sha256=nKod8eNWaBnmsaNZ59dEt42TTcwC9mMgCzEMYPZggxc,9537
40
+ clarifai/constants/base.py,sha256=ogmFSZYoF0YhGjHg5aiOc3MLqPr_poKAls6xaD0_C3U,89
41
+ clarifai/constants/dataset.py,sha256=9saFE_VxCTCMlPTQbOU4KM_SzN_TQjwsrsFnpsc_Epo,556
42
+ clarifai/constants/input.py,sha256=WcHwToUVIK9ItAhDefaSohQHCLNeR55PSjZ0BFnoZ3U,28
43
+ clarifai/constants/model.py,sha256=ghcdvKIbx-g22H9RwxmMfUt1CrKz5Oa-iTExt0VpUVU,463
44
+ clarifai/constants/rag.py,sha256=WcHwToUVIK9ItAhDefaSohQHCLNeR55PSjZ0BFnoZ3U,28
45
+ clarifai/constants/search.py,sha256=yYEqTaFg-KdnpJE_Ytp-EPVHIIC395iNtZrpVlLIf4o,101
46
+ clarifai/constants/workflow.py,sha256=cECq1xdvf44MCdtK2AbkiuuwhyL-6OWZdQfYbsLKy_o,33
47
+ clarifai/datasets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
+ clarifai/datasets/export/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
+ clarifai/datasets/export/inputs_annotations.py,sha256=1PFjIw30dRO9NSUa_yvox_07W30tlAnrk4mEAVgfXBY,10980
50
+ clarifai/datasets/upload/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
51
+ clarifai/datasets/upload/base.py,sha256=8b13tmAokgZVH0d-HRpU-O15Swa46eJy2Fp6zU7jQkU,2441
52
+ clarifai/datasets/upload/features.py,sha256=Yy0MP1F_ev2IbWnEyXDLt5SaEb11bXSUu5ux8tD1oxY,2115
53
+ clarifai/datasets/upload/image.py,sha256=0Fs02KK1WuDE24RAJ2ZOdktva1iOqzE25J9jJJYJUDk,10122
54
+ clarifai/datasets/upload/multimodal.py,sha256=IZYjmyxVJpNjwyNyzptQENZcCKDbdTU_t70QSdK23Ec,2762
55
+ clarifai/datasets/upload/text.py,sha256=L2IEbickNhZcmrhbBfQciCXQf4JPcqWulRWJ7HDpJLc,2482
56
+ clarifai/datasets/upload/utils.py,sha256=VdTn7AqIWB8D60rX9YD4T-4fi-7xMEocHATJvvaPjxQ,10508
57
+ clarifai/datasets/upload/loaders/README.md,sha256=aNRutSCTzLp2ruIZx74ZkN5AxpzwKOxMa7OzabnKpwg,2980
58
+ clarifai/datasets/upload/loaders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
59
+ clarifai/datasets/upload/loaders/coco_captions.py,sha256=v6e8lh6BCUFOlurnvDfBEY-drl6JhpIE9nt2Qnz7XQ8,1623
60
+ clarifai/datasets/upload/loaders/coco_detection.py,sha256=0FsGV84MT0IkerXoe9hdxQSr9wd96j9cPOne-rhzBPw,3190
61
+ clarifai/datasets/upload/loaders/imagenet_classification.py,sha256=w2Tiot_YK0QYiyAVbWSxoKthZgUsRo9LiWWY2lVzPrQ,2247
62
+ clarifai/datasets/upload/loaders/xview_detection.py,sha256=dukodZRdyVH-s5MtmCDtKwseKGwSCWAK2Uwuwa6kJu4,8035
63
+ clarifai/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
64
+ clarifai/models/api.py,sha256=YhbGqZMC5mH_ZqnbaEmgfJdrIhSkLevpWih8ZqC3BL4,12193
65
+ clarifai/modules/README.md,sha256=mx8pVx6cPp-pP4LcFPT_nX3ngGmhygVK0WiXeD3cbIo,367
66
+ clarifai/modules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
67
+ clarifai/modules/css.py,sha256=Jg67jXo2mZoGQp7M-At74ywyk4cN90s-aJTLjfqsaB4,2176
68
+ clarifai/modules/pages.py,sha256=DZVO7YjIjYQdUyHYF-zxLkc5qkYC5KNnUxGiKQGo3Uk,1509
69
+ clarifai/modules/style.css,sha256=j7FNPZVhLPj35vvBksAJ90RuX5sLuqzDR5iM2WIEhiA,6073
70
+ clarifai/rag/__init__.py,sha256=wu3PzAzo7uqgrEzuaC9lY_3gj1HFiR3GU3elZIKTT5g,40
71
+ clarifai/rag/rag.py,sha256=EG3GoFrHFCmA70Tz49_0Jo1-3WIaHSgWGHecPeErcdc,14170
72
+ clarifai/rag/utils.py,sha256=_gVZdABuMnraCKViLruV75x0F3IpgFXN6amYSGE5_xc,4462
73
+ clarifai/runners/__init__.py,sha256=wXLaSljH7qLeJCrZdKEnlQh2tNqTQAIZKWOu2rZ6wGs,279
74
+ clarifai/runners/server.py,sha256=E7VtQcGuFYS_CIfrBIvdRVgjLwzHO9LEUpD_gtU-ye4,4873
75
+ clarifai/runners/dockerfile_template/Dockerfile.template,sha256=nEnIMqzhAXDbd0Ht7QQm0U7AVPIHWQD6kYnFZ0TKJUM,2428
76
+ clarifai/runners/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
77
+ clarifai/runners/models/dummy_openai_model.py,sha256=pcmAVbqTTGG4J3BLVjKfvM_SQ-GET_XexIUdLcr9Zvo,8373
78
+ clarifai/runners/models/mcp_class.py,sha256=RdKn7rW4vYol0VRDZiLTSMfkqjLhO1ijXAQ0Rq0Jfnw,6647
79
+ clarifai/runners/models/model_builder.py,sha256=6DEwMo-Aq5CSWxTgMNgQISq2H37HXlkPauOgnmSWhZk,64704
80
+ clarifai/runners/models/model_class.py,sha256=Ndh437BNMkpFBo6B108GuKL8sGYaGnSplZ6FxOgd_v8,20010
81
+ clarifai/runners/models/model_run_locally.py,sha256=6-6WjEKc0ba3gAv4wOLdMs2XOzS3b-2bZHJS0wdVqJY,20088
82
+ clarifai/runners/models/model_runner.py,sha256=RxhYawEX6vJKTZZ_AmcHwo2ONwT7V7e3W-vXuunY7eI,11874
83
+ clarifai/runners/models/model_servicer.py,sha256=415RqiXCPH-1WgFHrtZMDH1nb8gaQDpVlrQ_tvtbjOg,4523
84
+ clarifai/runners/models/openai_class.py,sha256=OVYe4dWJPhskyZn53X9yJorzKZA7mjRCqYbu1rzRTFU,6715
85
+ clarifai/runners/models/visual_classifier_class.py,sha256=1ZoLfCT2crrgRbejjTMAIwpTRgQMiH9N9yflOVpFxSg,2721
86
+ clarifai/runners/models/visual_detector_class.py,sha256=ky4oFAkGCKPpGPdgaOso-n6D3HcmnbKee_8hBsNiV8U,2883
87
+ clarifai/runners/pipeline_steps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
88
+ clarifai/runners/pipeline_steps/pipeline_step_builder.py,sha256=X2xWg4QM4kX3cr8JkG1RmAiVE8-XH8XbomjmXa16zmY,21333
89
+ clarifai/runners/pipelines/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
90
+ clarifai/runners/pipelines/pipeline_builder.py,sha256=z_bCwjwQPFa_1AYkorhh5r6t6r5hC5K2D8Z1LTEzIpg,12801
91
+ clarifai/runners/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
92
+ clarifai/runners/utils/code_script.py,sha256=dzvHKgD-3B25KtQVCnCLz9rGzvgrxi4w7DoVkd6AxaI,14312
93
+ clarifai/runners/utils/const.py,sha256=MK7lTzzJKbOiyiUtG_jlJXfz_xNKMn5LjkQ9vjbttXE,1538
94
+ clarifai/runners/utils/data_utils.py,sha256=HRpMYR2O0OiDpXXhOManLHTeomC4bFnXMHVAiT_12yE,20856
95
+ clarifai/runners/utils/loader.py,sha256=K5Y8MPbIe5STw2gDnrL8KqFgKNxEo7bz-RV0ip1T4PM,10900
96
+ clarifai/runners/utils/method_signatures.py,sha256=qdHaO8ZIgP6BBXXMhMPhcQ46dse-XMP2t4VJCNG7O3Q,18335
97
+ clarifai/runners/utils/model_utils.py,sha256=eTIGOZpt0icOGfVnmYM9yO9g7CTsb_plLkzvJIH1QRo,6288
98
+ clarifai/runners/utils/openai_convertor.py,sha256=ZlIrvvfHttD_DavLvmKZdL8gNq_TQvQtZVnYamwdWz4,8248
99
+ clarifai/runners/utils/pipeline_validation.py,sha256=RWWWUA3mNCXHCSNpuofMGfXfWEYe7LrYKwIc-1VFvQs,6444
100
+ clarifai/runners/utils/serializers.py,sha256=pI7GqMTC0T3Lu_X8v8TO4RiplO-gC_49Ns37jYwsPtg,7908
101
+ clarifai/runners/utils/url_fetcher.py,sha256=pGkrpj692FEvMsV6pNbmidfYKzQV7APzjja_fwd1Aig,4792
102
+ clarifai/runners/utils/data_types/__init__.py,sha256=iBtmPkIoLK9ew6ZiXElGt2YBBTDLEA0fmxE_eOYzvhk,478
103
+ clarifai/runners/utils/data_types/data_types.py,sha256=UBHTNPshr94qUs2KqkYis0VlArm23rcSG_EyO_Uetgc,19823
104
+ clarifai/schema/search.py,sha256=o9-ct8ulLZByB3RCVwZWPgaDwdcW7cM5s-g8oyAz89s,2421
105
+ clarifai/urls/helper.py,sha256=z6LnLGgLHxD8scFtyRdxqYIRJNhxqPkfLe53UtTLUBY,11727
106
+ clarifai/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
107
+ clarifai/utils/cli.py,sha256=-r4qtzBQHRo3XeO4GSRwGHv5-_ndTcJ_4IkFY3eXvSg,11574
108
+ clarifai/utils/config.py,sha256=jMSWYxJfp_D8eoGqz-HTdsngn5bg_1ymjLidYz6rdLA,7073
109
+ clarifai/utils/constants.py,sha256=klcdSiVccrdJVRXL9qq08p2lWL3KerXcQOTIG6y9298,2414
110
+ clarifai/utils/logging.py,sha256=0we53uTqUvzrulC86whu-oeWNxn1JjJL0OQ98Bwf9vo,15198
111
+ clarifai/utils/misc.py,sha256=ld7_lls4CrjHzKchsSgJs4T-rVpUVEzRy4MDWBEQlyA,22812
112
+ clarifai/utils/model_train.py,sha256=0XSAoTkSsrwf4f-W9yw2mkXZtkal7LBLJSoi86CFCn4,9250
113
+ clarifai/utils/protobuf.py,sha256=VMhnNsPuWQ16VarKm8BOr5zccXMe26UlrxdJxIzEZNM,6220
114
+ clarifai/utils/evaluation/__init__.py,sha256=PYkurUrXrGevByj7RFb6CoU1iC7fllyQSfnnlo9WnY8,69
115
+ clarifai/utils/evaluation/helpers.py,sha256=0t6eIDXeZEoiVvnmHTnsIF_-v4BzrQW1hFaqc_psifU,21079
116
+ clarifai/utils/evaluation/main.py,sha256=N_sfRuMjHrUeuWN0Pzms65M1PbkQkgYg3WoQVaDR1Jw,17764
117
+ clarifai/utils/evaluation/testset_annotation_parser.py,sha256=Nmodfi5BYFYEbybWcC8tmU5-wtwRBsWIbnpd3OvKSmA,5414
118
+ clarifai/workflows/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
119
+ clarifai/workflows/export.py,sha256=HvUYG9N_-UZoRR0-_tdGbZ950_AeBqawSppgUxQebR0,1913
120
+ clarifai/workflows/utils.py,sha256=ESL3INcouNcLKCh-nMpfXX-YbtCzX7tz7hT57_RGQ3M,2079
121
+ clarifai/workflows/validate.py,sha256=UhmukyHkfxiMFrPPeBdUTiCOHQT5-shqivlBYEyKTlU,2931
122
+ clarifai-11.6.5.dist-info/licenses/LICENSE,sha256=mUqF_d12-qE2n41g7C5_sq-BMLOcj6CNN-jevr15YHU,555
123
+ clarifai-11.6.5.dist-info/METADATA,sha256=2wCjPH9Fg3ojVf27yb5CBrnA2a2ZGuzEoikvnf5U4cY,22737
124
+ clarifai-11.6.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
125
+ clarifai-11.6.5.dist-info/entry_points.txt,sha256=X9FZ4Z-i_r2Ud1RpZ9sNIFYuu_-9fogzCMCRUD9hyX0,51
126
+ clarifai-11.6.5.dist-info/top_level.txt,sha256=wUMdCQGjkxaynZ6nZ9FAnvBUCgp5RJUVFSy2j-KYo0s,9
127
+ clarifai-11.6.5.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.1)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
Binary file
Binary file
@@ -1,243 +0,0 @@
1
- """Templates for model initialization."""
2
-
3
- from clarifai import __version__
4
-
5
-
6
- def get_model_class_template() -> str:
7
- """Return the template for a basic ModelClass-based model."""
8
- return '''from typing import Iterator, List
9
- from clarifai.runners.models.model_class import ModelClass
10
- from clarifai.runners.util.data_utils import Param
11
-
12
- class MyModel(ModelClass):
13
- """A custom model implementation using ModelClass."""
14
-
15
- def load_model(self):
16
- """Load the model here.
17
- # TODO: please fill in
18
- # Add your model loading logic here
19
- """
20
- pass
21
-
22
- @ModelClass.method
23
- def predict(
24
- self,
25
- prompt: str = "",
26
- chat_history: List[dict] = None,
27
- max_tokens: int = Param(default=256, description="The maximum number of tokens to generate. Shorter token lengths will provide faster performance."),
28
- temperature: float = Param(default=1.0, description="A decimal number that determines the degree of randomness in the response"),
29
- top_p: float = Param(default=1.0, description="An alternative to sampling with temperature, where the model considers the results of the tokens with top_p probability mass."),
30
- ) -> str:
31
- """This is the method that will be called when the runner is run. It takes in an input and returns an output."""
32
- # TODO: please fill in
33
- # Implement your prediction logic here
34
- pass # Replace with your actual logic
35
-
36
- @ModelClass.method
37
- def generate(
38
- self,
39
- prompt: str = "",
40
- chat_history: List[dict] = None,
41
- max_tokens: int = Param(default=256, description="The maximum number of tokens to generate. Shorter token lengths will provide faster performance."),
42
- temperature: float = Param(default=1.0, description="A decimal number that determines the degree of randomness in the response"),
43
- top_p: float = Param(default=1.0, description="An alternative to sampling with temperature, where the model considers the results of the tokens with top_p probability mass."),
44
- ) -> Iterator[str]:
45
- """Example yielding a streamed response."""
46
- # TODO: please fill in
47
- # Implement your generation logic here
48
- pass # Replace with your actual logic
49
- '''
50
-
51
-
52
- def get_mcp_model_class_template() -> str:
53
- """Return the template for an MCPModelClass-based model."""
54
- return '''from typing import Any
55
-
56
- from fastmcp import FastMCP # use fastmcp v2 not the built in mcp
57
- from pydantic import Field
58
-
59
- from clarifai.runners.models.mcp_class import MCPModelClass
60
-
61
- # TODO: please fill in
62
- # Configure your FastMCP server
63
- server = FastMCP("my-mcp-server", instructions="", stateless_http=True)
64
-
65
-
66
- # TODO: please fill in
67
- # Add your tools, resources, and prompts here
68
- @server.tool("example_tool", description="An example tool")
69
- def example_tool(input_param: Any = Field(description="Example input parameter")):
70
- """Example tool implementation."""
71
- # TODO: please fill in
72
- # Implement your tool logic here
73
- return f"Processed: {input_param}"
74
-
75
-
76
- # Static resource example
77
- @server.resource("config://version")
78
- def get_version():
79
- """Example static resource."""
80
- # TODO: please fill in
81
- # Return your resource data
82
- return "1.0.0"
83
-
84
-
85
- @server.prompt()
86
- def example_prompt(text: str) -> str:
87
- """Example prompt template."""
88
- # TODO: please fill in
89
- # Define your prompt template
90
- return f"Process this text: {text}"
91
-
92
-
93
- class MyModel(MCPModelClass):
94
- """A custom model implementation using MCPModelClass."""
95
-
96
- def get_server(self) -> FastMCP:
97
- """Return the FastMCP server instance."""
98
- return server
99
- '''
100
-
101
-
102
- def get_openai_model_class_template() -> str:
103
- """Return the template for an OpenAIModelClass-based model."""
104
- return '''from typing import List
105
- from openai import OpenAI
106
- from clarifai.runners.models.openai_class import OpenAIModelClass
107
- from clarifai.runners.util.data_utils import Param
108
- from clarifai.runners.utils.openai_convertor import build_openai_messages
109
-
110
- class MyModel(OpenAIModelClass):
111
- """A custom model implementation using OpenAIModelClass."""
112
-
113
- # TODO: please fill in
114
- # Configure your OpenAI-compatible client for local model
115
- client = OpenAI(
116
- api_key="local-key", # TODO: please fill in - use your local API key
117
- base_url="http://localhost:8000/v1", # TODO: please fill in - your local model server endpoint
118
- )
119
-
120
- # TODO: please fill in
121
- # Specify the model name to use
122
- model = "my-local-model" # TODO: please fill in - replace with your local model name
123
-
124
- def load_model(self):
125
- """Optional: Add any additional model loading logic here."""
126
- # TODO: please fill in (optional)
127
- # Add any initialization logic if needed
128
- pass
129
-
130
- @OpenAIModelClass.method
131
- def predict(
132
- self,
133
- prompt: str = "",
134
- chat_history: List[dict] = None,
135
- max_tokens: int = Param(default=256, description="The maximum number of tokens to generate. Shorter token lengths will provide faster performance."),
136
- temperature: float = Param(default=1.0, description="A decimal number that determines the degree of randomness in the response"),
137
- top_p: float = Param(default=1.0, description="An alternative to sampling with temperature, where the model considers the results of the tokens with top_p probability mass."),
138
- ) -> str:
139
- """Run a single prompt completion using the OpenAI client."""
140
- # TODO: please fill in
141
- # Implement your prediction logic here
142
- messages = build_openai_messages(prompt, chat_history)
143
- response = self.client.chat.completions.create(
144
- model=self.model,
145
- messages=messages,
146
- max_completion_tokens=max_tokens,
147
- temperature=temperature,
148
- top_p=top_p,
149
- )
150
- return response.choices[0].message.content
151
-
152
- @OpenAIModelClass.method
153
- def generate(
154
- self,
155
- prompt: str = "",
156
- chat_history: List[dict] = None,
157
- max_tokens: int = Param(default=256, description="The maximum number of tokens to generate. Shorter token lengths will provide faster performance."),
158
- temperature: float = Param(default=1.0, description="A decimal number that determines the degree of randomness in the response"),
159
- top_p: float = Param(default=1.0, description="An alternative to sampling with temperature, where the model considers the results of the tokens with top_p probability mass."),
160
- ):
161
- """Stream a completion response using the OpenAI client."""
162
- # TODO: please fill in
163
- # Implement your streaming logic here
164
- messages = build_openai_messages(prompt, chat_history)
165
- stream = self.client.chat.completions.create(
166
- model=self.model,
167
- messages=messages,
168
- max_completion_tokens=max_tokens,
169
- temperature=temperature,
170
- top_p=top_p,
171
- stream=True,
172
- )
173
- for chunk in stream:
174
- if chunk.choices:
175
- text = (chunk.choices[0].delta.content
176
- if (chunk and chunk.choices[0].delta.content) is not None else '')
177
- yield text
178
- '''
179
-
180
-
181
- def get_config_template(model_type_id: str = "text-to-text") -> str:
182
- """Return the template for config.yaml."""
183
- return f'''# Configuration file for your Clarifai model
184
-
185
- model:
186
- id: "my-model" # TODO: please fill in - replace with your model ID
187
- user_id: "user_id" # TODO: please fill in - replace with your user ID
188
- app_id: "app_id" # TODO: please fill in - replace with your app ID
189
- model_type_id: "{model_type_id}" # TODO: please fill in - replace if different model type ID
190
-
191
- build_info:
192
- python_version: "3.12"
193
-
194
- # TODO: please fill in - adjust compute requirements for your model
195
- inference_compute_info:
196
- cpu_limit: "1" # TODO: please fill in - Amount of CPUs to use as a limit
197
- cpu_memory: "1Gi" # TODO: please fill in - Amount of CPU memory to use as a limit
198
- cpu_requests: "0.5" # TODO: please fill in - Amount of CPUs to use as a minimum
199
- cpu_memory_requests: "512Mi" # TODO: please fill in - Amount of CPU memory to use as a minimum
200
- num_accelerators: 1 # TODO: please fill in - Amount of GPU/TPUs to use
201
- accelerator_type: ["NVIDIA-*"] # TODO: please fill in - type of accelerators requested
202
- accelerator_memory: "1Gi" # TODO: please fill in - Amount of accelerator/GPU memory to use as a minimum
203
-
204
- # TODO: please fill in (optional) - add checkpoints section if needed
205
- # checkpoints:
206
- # type: "huggingface" # supported type
207
- # repo_id: "your-model-repo" # for huggingface
208
- # when: "build" # or "runtime", "upload"
209
- '''
210
-
211
-
212
- def get_requirements_template(model_type_id: str = None) -> str:
213
- """Return the template for requirements.txt."""
214
- requirements = f'''# Clarifai SDK - required
215
- clarifai>={__version__}
216
- '''
217
- if model_type_id == "mcp":
218
- requirements += "fastmcp\n"
219
- elif model_type_id == "openai":
220
- requirements += "openai\n"
221
- requirements += '''
222
- # TODO: please fill in - add your model's dependencies here
223
- # Examples:
224
- # torch>=2.0.0
225
- # transformers>=4.30.0
226
- # numpy>=1.21.0
227
- # pillow>=9.0.0
228
- '''
229
- return requirements
230
-
231
-
232
- # Mapping of model type IDs to their corresponding templates
233
- MODEL_TYPE_TEMPLATES = {
234
- "mcp": get_mcp_model_class_template,
235
- "openai": get_openai_model_class_template,
236
- }
237
-
238
-
239
- def get_model_template(model_type_id: str = None) -> str:
240
- """Get the appropriate model template based on model_type_id."""
241
- if model_type_id in MODEL_TYPE_TEMPLATES:
242
- return MODEL_TYPE_TEMPLATES[model_type_id]()
243
- return get_model_class_template()