clarifai 11.2.3rc1__py3-none-any.whl → 11.2.3rc3__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 (248) hide show
  1. clarifai/__init__.py +1 -1
  2. clarifai/__pycache__/__init__.cpython-310.pyc +0 -0
  3. clarifai/__pycache__/__init__.cpython-39.pyc +0 -0
  4. clarifai/__pycache__/errors.cpython-310.pyc +0 -0
  5. clarifai/__pycache__/versions.cpython-310.pyc +0 -0
  6. clarifai/cli/__pycache__/__init__.cpython-310.pyc +0 -0
  7. clarifai/cli/__pycache__/base.cpython-310.pyc +0 -0
  8. clarifai/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
  9. clarifai/cli/__pycache__/compute_cluster.cpython-310.pyc +0 -0
  10. clarifai/cli/__pycache__/deployment.cpython-310.pyc +0 -0
  11. clarifai/cli/__pycache__/model.cpython-310.pyc +0 -0
  12. clarifai/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
  13. clarifai/cli/__pycache__/nodepool.cpython-310.pyc +0 -0
  14. clarifai/cli/base.py +81 -228
  15. clarifai/cli/compute_cluster.py +17 -25
  16. clarifai/cli/deployment.py +41 -67
  17. clarifai/cli/model.py +39 -26
  18. clarifai/cli/nodepool.py +40 -59
  19. clarifai/client/__pycache__/__init__.cpython-310.pyc +0 -0
  20. clarifai/client/__pycache__/__init__.cpython-39.pyc +0 -0
  21. clarifai/client/__pycache__/app.cpython-310.pyc +0 -0
  22. clarifai/client/__pycache__/app.cpython-39.pyc +0 -0
  23. clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
  24. clarifai/client/__pycache__/compute_cluster.cpython-310.pyc +0 -0
  25. clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
  26. clarifai/client/__pycache__/deployment.cpython-310.pyc +0 -0
  27. clarifai/client/__pycache__/input.cpython-310.pyc +0 -0
  28. clarifai/client/__pycache__/lister.cpython-310.pyc +0 -0
  29. clarifai/client/__pycache__/model.cpython-310.pyc +0 -0
  30. clarifai/client/__pycache__/module.cpython-310.pyc +0 -0
  31. clarifai/client/__pycache__/nodepool.cpython-310.pyc +0 -0
  32. clarifai/client/__pycache__/search.cpython-310.pyc +0 -0
  33. clarifai/client/__pycache__/user.cpython-310.pyc +0 -0
  34. clarifai/client/__pycache__/workflow.cpython-310.pyc +0 -0
  35. clarifai/client/app.py +1 -1
  36. clarifai/client/auth/__pycache__/__init__.cpython-310.pyc +0 -0
  37. clarifai/client/auth/__pycache__/helper.cpython-310.pyc +0 -0
  38. clarifai/client/auth/__pycache__/register.cpython-310.pyc +0 -0
  39. clarifai/client/auth/__pycache__/stub.cpython-310.pyc +0 -0
  40. clarifai/client/cli/__init__.py +0 -0
  41. clarifai/client/cli/__pycache__/__init__.cpython-310.pyc +0 -0
  42. clarifai/client/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
  43. clarifai/client/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
  44. clarifai/client/cli/base_cli.py +88 -0
  45. clarifai/client/cli/model_cli.py +29 -0
  46. clarifai/client/model.py +159 -393
  47. clarifai/client/model_client.py +502 -0
  48. clarifai/constants/__pycache__/base.cpython-310.pyc +0 -0
  49. clarifai/constants/__pycache__/dataset.cpython-310.pyc +0 -0
  50. clarifai/constants/__pycache__/input.cpython-310.pyc +0 -0
  51. clarifai/constants/__pycache__/{model.cpython-312.pyc → model.cpython-310.pyc} +0 -0
  52. clarifai/constants/__pycache__/rag.cpython-310.pyc +0 -0
  53. clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
  54. clarifai/constants/__pycache__/workflow.cpython-310.pyc +0 -0
  55. clarifai/datasets/__pycache__/__init__.cpython-310.pyc +0 -0
  56. clarifai/datasets/__pycache__/__init__.cpython-39.pyc +0 -0
  57. clarifai/datasets/export/__pycache__/__init__.cpython-310.pyc +0 -0
  58. clarifai/datasets/export/__pycache__/__init__.cpython-39.pyc +0 -0
  59. clarifai/datasets/export/__pycache__/inputs_annotations.cpython-310.pyc +0 -0
  60. clarifai/datasets/upload/__pycache__/__init__.cpython-310.pyc +0 -0
  61. clarifai/datasets/upload/__pycache__/__init__.cpython-39.pyc +0 -0
  62. clarifai/datasets/upload/__pycache__/base.cpython-310.pyc +0 -0
  63. clarifai/datasets/upload/__pycache__/features.cpython-310.pyc +0 -0
  64. clarifai/datasets/upload/__pycache__/image.cpython-310.pyc +0 -0
  65. clarifai/datasets/upload/__pycache__/multimodal.cpython-310.pyc +0 -0
  66. clarifai/datasets/upload/__pycache__/text.cpython-310.pyc +0 -0
  67. clarifai/datasets/upload/__pycache__/utils.cpython-310.pyc +0 -0
  68. clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-39.pyc +0 -0
  69. clarifai/models/__pycache__/__init__.cpython-39.pyc +0 -0
  70. clarifai/modules/__pycache__/__init__.cpython-39.pyc +0 -0
  71. clarifai/rag/__pycache__/__init__.cpython-310.pyc +0 -0
  72. clarifai/rag/__pycache__/__init__.cpython-39.pyc +0 -0
  73. clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
  74. clarifai/rag/__pycache__/rag.cpython-39.pyc +0 -0
  75. clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
  76. clarifai/runners/__init__.py +2 -7
  77. clarifai/runners/__pycache__/__init__.cpython-310.pyc +0 -0
  78. clarifai/runners/__pycache__/__init__.cpython-39.pyc +0 -0
  79. clarifai/runners/dockerfile_template/Dockerfile.cpu.template +31 -0
  80. clarifai/runners/dockerfile_template/Dockerfile.cuda.template +42 -0
  81. clarifai/runners/dockerfile_template/Dockerfile.nim +71 -0
  82. clarifai/runners/models/__pycache__/__init__.cpython-310.pyc +0 -0
  83. clarifai/runners/models/__pycache__/__init__.cpython-39.pyc +0 -0
  84. clarifai/runners/models/__pycache__/base_typed_model.cpython-310.pyc +0 -0
  85. clarifai/runners/models/__pycache__/base_typed_model.cpython-39.pyc +0 -0
  86. clarifai/runners/models/__pycache__/model_class.cpython-310.pyc +0 -0
  87. clarifai/runners/models/__pycache__/model_run_locally.cpython-310-pytest-7.1.2.pyc +0 -0
  88. clarifai/runners/models/__pycache__/model_run_locally.cpython-310.pyc +0 -0
  89. clarifai/runners/models/__pycache__/model_runner.cpython-310.pyc +0 -0
  90. clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc +0 -0
  91. clarifai/runners/models/model_builder.py +138 -51
  92. clarifai/runners/models/model_class.py +441 -28
  93. clarifai/runners/models/model_class_refract.py +80 -0
  94. clarifai/runners/models/model_run_locally.py +25 -89
  95. clarifai/runners/models/model_runner.py +8 -0
  96. clarifai/runners/models/model_servicer.py +11 -2
  97. clarifai/runners/models/model_upload.py +607 -0
  98. clarifai/runners/models/temp.py +25 -0
  99. clarifai/runners/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  100. clarifai/runners/utils/__pycache__/__init__.cpython-38.pyc +0 -0
  101. clarifai/runners/utils/__pycache__/__init__.cpython-39.pyc +0 -0
  102. clarifai/runners/utils/__pycache__/buffered_stream.cpython-310.pyc +0 -0
  103. clarifai/runners/utils/__pycache__/buffered_stream.cpython-38.pyc +0 -0
  104. clarifai/runners/utils/__pycache__/buffered_stream.cpython-39.pyc +0 -0
  105. clarifai/runners/utils/__pycache__/const.cpython-310.pyc +0 -0
  106. clarifai/runners/utils/__pycache__/constants.cpython-310.pyc +0 -0
  107. clarifai/runners/utils/__pycache__/constants.cpython-38.pyc +0 -0
  108. clarifai/runners/utils/__pycache__/constants.cpython-39.pyc +0 -0
  109. clarifai/runners/utils/__pycache__/data_handler.cpython-310.pyc +0 -0
  110. clarifai/runners/utils/__pycache__/data_handler.cpython-38.pyc +0 -0
  111. clarifai/runners/utils/__pycache__/data_handler.cpython-39.pyc +0 -0
  112. clarifai/runners/utils/__pycache__/data_utils.cpython-310.pyc +0 -0
  113. clarifai/runners/utils/__pycache__/data_utils.cpython-38.pyc +0 -0
  114. clarifai/runners/utils/__pycache__/data_utils.cpython-39.pyc +0 -0
  115. clarifai/runners/utils/__pycache__/grpc_server.cpython-310.pyc +0 -0
  116. clarifai/runners/utils/__pycache__/grpc_server.cpython-38.pyc +0 -0
  117. clarifai/runners/utils/__pycache__/grpc_server.cpython-39.pyc +0 -0
  118. clarifai/runners/utils/__pycache__/health.cpython-310.pyc +0 -0
  119. clarifai/runners/utils/__pycache__/health.cpython-38.pyc +0 -0
  120. clarifai/runners/utils/__pycache__/health.cpython-39.pyc +0 -0
  121. clarifai/runners/utils/__pycache__/loader.cpython-310.pyc +0 -0
  122. clarifai/runners/utils/__pycache__/logging.cpython-310.pyc +0 -0
  123. clarifai/runners/utils/__pycache__/logging.cpython-38.pyc +0 -0
  124. clarifai/runners/utils/__pycache__/logging.cpython-39.pyc +0 -0
  125. clarifai/runners/utils/__pycache__/stream_source.cpython-310.pyc +0 -0
  126. clarifai/runners/utils/__pycache__/stream_source.cpython-39.pyc +0 -0
  127. clarifai/runners/utils/__pycache__/url_fetcher.cpython-310.pyc +0 -0
  128. clarifai/runners/utils/__pycache__/url_fetcher.cpython-38.pyc +0 -0
  129. clarifai/runners/utils/__pycache__/url_fetcher.cpython-39.pyc +0 -0
  130. clarifai/runners/utils/code_script.py +217 -0
  131. clarifai/runners/utils/const.py +8 -9
  132. clarifai/runners/utils/data_handler.py +271 -210
  133. clarifai/runners/utils/data_handler_refract.py +213 -0
  134. clarifai/runners/utils/data_types.py +473 -0
  135. clarifai/runners/utils/data_utils.py +165 -0
  136. clarifai/runners/utils/loader.py +6 -36
  137. clarifai/runners/utils/logger.py +0 -0
  138. clarifai/runners/utils/method_signatures.py +518 -0
  139. clarifai/runners/utils/serializers.py +222 -0
  140. clarifai/schema/__pycache__/search.cpython-310.pyc +0 -0
  141. clarifai/urls/__pycache__/helper.cpython-310.pyc +0 -0
  142. clarifai/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  143. clarifai/utils/__pycache__/__init__.cpython-39.pyc +0 -0
  144. clarifai/utils/__pycache__/cli.cpython-310.pyc +0 -0
  145. clarifai/utils/__pycache__/constants.cpython-310.pyc +0 -0
  146. clarifai/utils/__pycache__/logging.cpython-310.pyc +0 -0
  147. clarifai/utils/__pycache__/misc.cpython-310.pyc +0 -0
  148. clarifai/utils/__pycache__/model_train.cpython-310.pyc +0 -0
  149. clarifai/utils/cli.py +33 -132
  150. clarifai/utils/constants.py +0 -4
  151. clarifai/utils/evaluation/__pycache__/__init__.cpython-39.pyc +0 -0
  152. clarifai/utils/evaluation/__pycache__/main.cpython-39.pyc +0 -0
  153. clarifai/utils/misc.py +0 -2
  154. clarifai/workflows/__pycache__/__init__.cpython-310.pyc +0 -0
  155. clarifai/workflows/__pycache__/__init__.cpython-39.pyc +0 -0
  156. clarifai/workflows/__pycache__/export.cpython-310.pyc +0 -0
  157. clarifai/workflows/__pycache__/utils.cpython-310.pyc +0 -0
  158. clarifai/workflows/__pycache__/validate.cpython-310.pyc +0 -0
  159. {clarifai-11.2.3rc1.dist-info → clarifai-11.2.3rc3.dist-info}/METADATA +14 -3
  160. clarifai-11.2.3rc3.dist-info/RECORD +238 -0
  161. {clarifai-11.2.3rc1.dist-info → clarifai-11.2.3rc3.dist-info}/WHEEL +1 -1
  162. clarifai/__pycache__/__init__.cpython-312.pyc +0 -0
  163. clarifai/__pycache__/errors.cpython-312.pyc +0 -0
  164. clarifai/__pycache__/versions.cpython-312.pyc +0 -0
  165. clarifai/cli/__pycache__/__init__.cpython-312.pyc +0 -0
  166. clarifai/cli/__pycache__/base.cpython-312.pyc +0 -0
  167. clarifai/cli/__pycache__/compute_cluster.cpython-312.pyc +0 -0
  168. clarifai/cli/__pycache__/deployment.cpython-312.pyc +0 -0
  169. clarifai/cli/__pycache__/model.cpython-312.pyc +0 -0
  170. clarifai/cli/__pycache__/nodepool.cpython-312.pyc +0 -0
  171. clarifai/client/__pycache__/__init__.cpython-312.pyc +0 -0
  172. clarifai/client/__pycache__/app.cpython-312.pyc +0 -0
  173. clarifai/client/__pycache__/base.cpython-312.pyc +0 -0
  174. clarifai/client/__pycache__/compute_cluster.cpython-312.pyc +0 -0
  175. clarifai/client/__pycache__/dataset.cpython-312.pyc +0 -0
  176. clarifai/client/__pycache__/deployment.cpython-312.pyc +0 -0
  177. clarifai/client/__pycache__/input.cpython-312.pyc +0 -0
  178. clarifai/client/__pycache__/lister.cpython-312.pyc +0 -0
  179. clarifai/client/__pycache__/model.cpython-312.pyc +0 -0
  180. clarifai/client/__pycache__/model_client.cpython-312.pyc +0 -0
  181. clarifai/client/__pycache__/module.cpython-312.pyc +0 -0
  182. clarifai/client/__pycache__/nodepool.cpython-312.pyc +0 -0
  183. clarifai/client/__pycache__/search.cpython-312.pyc +0 -0
  184. clarifai/client/__pycache__/user.cpython-312.pyc +0 -0
  185. clarifai/client/__pycache__/workflow.cpython-312.pyc +0 -0
  186. clarifai/client/auth/__pycache__/__init__.cpython-312.pyc +0 -0
  187. clarifai/client/auth/__pycache__/helper.cpython-312.pyc +0 -0
  188. clarifai/client/auth/__pycache__/register.cpython-312.pyc +0 -0
  189. clarifai/client/auth/__pycache__/stub.cpython-312.pyc +0 -0
  190. clarifai/constants/__pycache__/base.cpython-312.pyc +0 -0
  191. clarifai/constants/__pycache__/dataset.cpython-312.pyc +0 -0
  192. clarifai/constants/__pycache__/input.cpython-312.pyc +0 -0
  193. clarifai/constants/__pycache__/search.cpython-312.pyc +0 -0
  194. clarifai/constants/__pycache__/workflow.cpython-312.pyc +0 -0
  195. clarifai/datasets/__pycache__/__init__.cpython-312.pyc +0 -0
  196. clarifai/datasets/export/__pycache__/__init__.cpython-312.pyc +0 -0
  197. clarifai/datasets/export/__pycache__/inputs_annotations.cpython-312.pyc +0 -0
  198. clarifai/datasets/upload/__pycache__/__init__.cpython-312.pyc +0 -0
  199. clarifai/datasets/upload/__pycache__/base.cpython-312.pyc +0 -0
  200. clarifai/datasets/upload/__pycache__/features.cpython-312.pyc +0 -0
  201. clarifai/datasets/upload/__pycache__/image.cpython-312.pyc +0 -0
  202. clarifai/datasets/upload/__pycache__/multimodal.cpython-312.pyc +0 -0
  203. clarifai/datasets/upload/__pycache__/text.cpython-312.pyc +0 -0
  204. clarifai/datasets/upload/__pycache__/utils.cpython-312.pyc +0 -0
  205. clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-312.pyc +0 -0
  206. clarifai/datasets/upload/loaders/__pycache__/coco_detection.cpython-312.pyc +0 -0
  207. clarifai/modules/__pycache__/__init__.cpython-312.pyc +0 -0
  208. clarifai/modules/__pycache__/css.cpython-312.pyc +0 -0
  209. clarifai/runners/__pycache__/__init__.cpython-312.pyc +0 -0
  210. clarifai/runners/__pycache__/server.cpython-312.pyc +0 -0
  211. clarifai/runners/models/__pycache__/__init__.cpython-312.pyc +0 -0
  212. clarifai/runners/models/__pycache__/base_typed_model.cpython-312.pyc +0 -0
  213. clarifai/runners/models/__pycache__/model_builder.cpython-312.pyc +0 -0
  214. clarifai/runners/models/__pycache__/model_class.cpython-312.pyc +0 -0
  215. clarifai/runners/models/__pycache__/model_run_locally.cpython-312.pyc +0 -0
  216. clarifai/runners/models/__pycache__/model_runner.cpython-312.pyc +0 -0
  217. clarifai/runners/models/__pycache__/model_servicer.cpython-312.pyc +0 -0
  218. clarifai/runners/utils/__pycache__/__init__.cpython-312.pyc +0 -0
  219. clarifai/runners/utils/__pycache__/const.cpython-312.pyc +0 -0
  220. clarifai/runners/utils/__pycache__/data_handler.cpython-312.pyc +0 -0
  221. clarifai/runners/utils/__pycache__/data_types.cpython-312.pyc +0 -0
  222. clarifai/runners/utils/__pycache__/data_utils.cpython-312.pyc +0 -0
  223. clarifai/runners/utils/__pycache__/loader.cpython-312.pyc +0 -0
  224. clarifai/runners/utils/__pycache__/method_signatures.cpython-312.pyc +0 -0
  225. clarifai/runners/utils/__pycache__/serializers.cpython-312.pyc +0 -0
  226. clarifai/runners/utils/__pycache__/url_fetcher.cpython-312.pyc +0 -0
  227. clarifai/schema/__pycache__/search.cpython-312.pyc +0 -0
  228. clarifai/urls/__pycache__/helper.cpython-312.pyc +0 -0
  229. clarifai/utils/__pycache__/__init__.cpython-312.pyc +0 -0
  230. clarifai/utils/__pycache__/cli.cpython-312.pyc +0 -0
  231. clarifai/utils/__pycache__/config.cpython-312.pyc +0 -0
  232. clarifai/utils/__pycache__/constants.cpython-312.pyc +0 -0
  233. clarifai/utils/__pycache__/logging.cpython-312.pyc +0 -0
  234. clarifai/utils/__pycache__/misc.cpython-312.pyc +0 -0
  235. clarifai/utils/__pycache__/model_train.cpython-312.pyc +0 -0
  236. clarifai/utils/config.py +0 -105
  237. clarifai/utils/config.py~ +0 -145
  238. clarifai/utils/evaluation/__pycache__/__init__.cpython-312.pyc +0 -0
  239. clarifai/utils/evaluation/__pycache__/helpers.cpython-312.pyc +0 -0
  240. clarifai/utils/evaluation/__pycache__/main.cpython-312.pyc +0 -0
  241. clarifai/workflows/__pycache__/__init__.cpython-312.pyc +0 -0
  242. clarifai/workflows/__pycache__/export.cpython-312.pyc +0 -0
  243. clarifai/workflows/__pycache__/utils.cpython-312.pyc +0 -0
  244. clarifai/workflows/__pycache__/validate.cpython-312.pyc +0 -0
  245. clarifai-11.2.3rc1.dist-info/RECORD +0 -185
  246. {clarifai-11.2.3rc1.dist-info → clarifai-11.2.3rc3.dist-info}/LICENSE +0 -0
  247. {clarifai-11.2.3rc1.dist-info → clarifai-11.2.3rc3.dist-info}/entry_points.txt +0 -0
  248. {clarifai-11.2.3rc1.dist-info → clarifai-11.2.3rc3.dist-info}/top_level.txt +0 -0
clarifai/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "11.2.3rc1"
1
+ __version__ = "11.2.3rc3"
clarifai/cli/base.py CHANGED
@@ -1,255 +1,108 @@
1
- import json
2
1
  import os
3
- import sys
4
2
 
5
3
  import click
6
- import yaml
7
4
 
8
- from clarifai.utils.cli import AliasedGroup, TableFormatter, load_command_modules
9
- from clarifai.utils.config import Config, Context
10
- from clarifai.utils.constants import DEFAULT_CONFIG
11
- from clarifai.utils.logging import logger
5
+ from ..utils.cli import dump_yaml, from_yaml, load_command_modules, set_base_url
12
6
 
13
7
 
14
- #@click.group(cls=CustomMultiGroup)
15
- @click.group(cls=AliasedGroup)
16
- @click.option('--config', default=DEFAULT_CONFIG)
17
- @click.pass_context
18
- def cli(ctx, config):
19
- """Clarifai CLI"""
20
- ctx.ensure_object(dict)
21
- if os.path.exists(config):
22
- cfg = Config.from_yaml(filename=config)
23
- ctx.obj = cfg
24
- else:
25
- cfg = Config(
26
- filename=config,
27
- current_context='default',
28
- contexts={
29
- 'default':
30
- Context(
31
- 'default',
32
- CLARIFAI_PAT=os.environ.get('CLARIFAI_PAT', ''),
33
- CLARIFAI_USER_ID=os.environ.get('CLARIFAI_USER_ID', ''),
34
- CLARIFAI_API_BASE=os.environ.get('CLARIFAI_API_BASE', 'api.clarifai.com'),
35
- )
36
- })
37
- try:
38
- cfg.to_yaml(config)
39
- except Exception:
40
- logger.warning("Could not write configuration to disk. Could be a read only file system.")
41
- ctx.obj = cfg # still have the default config even if couldn't write.
42
-
43
-
44
- @cli.command()
45
- @click.argument('shell', type=click.Choice(['bash', 'zsh']))
46
- def shell_completion(shell):
47
- """Shell completion script"""
48
- os.system(f"_CLARIFAI_COMPLETE={shell}_source clarifai")
49
-
50
-
51
- @cli.group(['cfg'], cls=AliasedGroup)
52
- def config():
53
- """Manage CLI configuration"""
8
+ class CustomMultiGroup(click.Group):
54
9
 
10
+ def group(self, *args, **kwargs):
11
+ """Behaves the same as `click.Group.group()` except if passed
12
+ a list of names, all after the first will be aliases for the first.
13
+ """
55
14
 
56
- @config.command(['e'])
57
- @click.pass_context
58
- def edit(ctx):
59
- """Edit the configuration file"""
60
- os.system(f'{os.environ.get("EDITOR", "vi")} {ctx.obj.filename}')
15
+ def decorator(f):
16
+ aliased_group = []
17
+ if isinstance(args[0], list):
18
+ # we have a list so create group aliases
19
+ _args = [args[0][0]] + list(args[1:])
20
+ for alias in args[0][1:]:
21
+ grp = super(CustomMultiGroup, self).group(alias, *args[1:], **kwargs)(f)
22
+ grp.short_help = "Alias for '{}'".format(_args[0])
23
+ aliased_group.append(grp)
24
+ else:
25
+ _args = args
61
26
 
27
+ # create the main group
28
+ grp = super(CustomMultiGroup, self).group(*_args, **kwargs)(f)
62
29
 
63
- @config.command(['current'])
64
- @click.option('-o', '--output-format', default='name', type=click.Choice(['name', 'json', 'yaml']))
65
- @click.pass_context
66
- def current_context(ctx, output_format):
67
- """Get the current context"""
68
- if output_format == 'name':
69
- print(ctx.obj.current_context)
70
- else:
71
- if output_format == 'json':
72
- print(json.dumps(ctx.obj.contexts[ctx.obj.current_context].to_serializable_dict()))
73
- else:
74
- print(yaml.safe_dump(ctx.obj.contexts[ctx.obj.current_context].to_serializable_dict()))
30
+ # for all of the aliased groups, share the main group commands
31
+ for aliased in aliased_group:
32
+ aliased.commands = grp.commands
75
33
 
34
+ return grp
76
35
 
77
- @config.command(['list', 'ls'])
78
- @click.option(
79
- '-o', '--output-format', default='wide', type=click.Choice(['wide', 'name', 'json', 'yaml']))
80
- @click.pass_context
81
- def get_contexts(ctx, output_format):
82
- """Get all contexts"""
83
- if output_format == 'wide':
84
- formatter = TableFormatter(custom_columns={
85
- '': lambda c: '*' if c.name == ctx.obj.current_context else '',
86
- 'NAME': lambda c: c.name,
87
- 'USER_ID': lambda c: c.user_id,
88
- 'API_BASE': lambda c: c.api_base,
89
- 'PAT': lambda c: pat_display(c.pat),
90
- })
91
- print(formatter.format(ctx.obj.contexts.values(), fmt="plain"))
92
- elif output_format == 'name':
93
- print('\n'.join(ctx.obj.contexts))
94
- elif output_format in ('json', 'yaml'):
95
- dicts = [v.__dict__ for c, v in ctx.obj.contexts.items()]
96
- for d in dicts:
97
- d.pop('pat')
98
- if output_format == 'json':
99
- print(json.dumps(dicts))
100
- elif output_format == 'yaml':
101
- print(yaml.safe_dump(dicts))
36
+ return decorator
102
37
 
103
38
 
104
- @config.command(['use'])
105
- @click.argument('context-name', type=str)
39
+ @click.group(cls=CustomMultiGroup)
106
40
  @click.pass_context
107
- def use_context(ctx, context_name):
108
- """Set the current context"""
109
- if context_name not in ctx.obj.contexts:
110
- raise click.UsageError('Context not found')
111
- ctx.obj.current_context = context_name
112
- ctx.obj.to_yaml()
113
- print(f'Set {context_name} as the current context')
114
-
115
-
116
- @config.command(['cat'])
117
- @click.option('-o', '--output-format', default='yaml', type=click.Choice(['yaml', 'json']))
118
- @click.pass_obj
119
- def dump(ctx_obj, output_format):
120
- """Dump the configuration to stdout"""
121
- if output_format == 'yaml':
122
- yaml.safe_dump(ctx_obj.to_dict(), sys.stdout)
41
+ def cli(ctx):
42
+ """Clarifai CLI"""
43
+ ctx.ensure_object(dict)
44
+ config_path = 'config.yaml'
45
+ if os.path.exists(config_path):
46
+ ctx.obj = from_yaml(config_path)
123
47
  else:
124
- json.dump(ctx_obj.to_dict(), sys.stdout, indent=2)
48
+ ctx.obj = {}
125
49
 
126
50
 
127
51
  @cli.command()
128
- @click.argument('api_url', default="https://api.clarifai.com")
52
+ @click.option('--config', type=click.Path(), required=False, help='Path to the config file')
53
+ @click.option(
54
+ '-e',
55
+ '--env',
56
+ required=False,
57
+ help='Environment to use, choose from prod, staging and dev',
58
+ type=click.Choice(['prod', 'staging', 'dev']))
129
59
  @click.option('--user_id', required=False, help='User ID')
130
60
  @click.pass_context
131
- def login(ctx, api_url, user_id):
61
+ def login(ctx, config, env, user_id):
132
62
  """Login command to set PAT and other configurations."""
133
63
 
134
- name = input('context name (default: "default"): ')
135
- user_id = user_id if user_id is not None else input('user id: ')
136
- pat = input_or_default(
137
- 'personal access token value (default: "ENVVAR" to get our of env var rather than config): ',
138
- 'ENVVAR')
139
-
140
- context = Context(
141
- name,
142
- CLARIFAI_API_BASE=api_url,
143
- CLARIFAI_USER_ID=user_id,
144
- CLARIFAI_PAT=pat,
145
- )
146
-
147
- if context.name == '':
148
- context.name = 'default'
149
-
150
- ctx.obj.contexts[context.name] = context
151
- ctx.obj.current_context = context.name
152
-
153
- ctx.obj.to_yaml()
154
-
64
+ if config and os.path.exists(config):
65
+ ctx.obj = from_yaml(config)
155
66
 
156
- @cli.group(cls=AliasedGroup)
157
- def context():
158
- """Manage contexts"""
159
-
160
-
161
- def pat_display(pat):
162
- return pat[:5] + "****"
163
-
164
-
165
- @context.command(['ls'])
166
- @click.pass_context
167
- def list(ctx):
168
- """List available contexts"""
169
- formatter = TableFormatter(custom_columns={
170
- '': lambda c: '*' if c.name == ctx.obj.current_context else '',
171
- 'NAME': lambda c: c.name,
172
- 'USER_ID': lambda c: c.user_id,
173
- 'API_BASE': lambda c: c.api_base,
174
- 'PAT': lambda c: pat_display(c.pat)
175
- })
176
- print(formatter.format(ctx.obj.contexts.values(), fmt="plain"))
177
-
178
-
179
- def input_or_default(prompt, default):
180
- value = input(prompt)
181
- return value if value else default
182
-
183
-
184
- @context.command()
185
- @click.argument('name')
186
- @click.option('--user-id', required=False, help='User ID')
187
- @click.option('--base-url', required=False, help='Base URL')
188
- @click.option('--pat', required=False, help='Personal access token')
189
- @click.pass_context
190
- def create(
191
- ctx,
192
- name,
193
- user_id=None,
194
- base_url=None,
195
- pat=None,
196
- ):
197
- """Create a new context"""
198
- if name in ctx.obj.contexts:
199
- print(f'{name} already exists')
200
- exit(1)
201
- if not user_id:
202
- user_id = input('user id: ')
203
- if not base_url:
204
- base_url = input_or_default('base url (default: https://api.clarifai.com): ',
205
- 'https://api.clarifai.com')
206
- if not pat:
207
- pat = input_or_default(
208
- 'personal access token value (default: "ENVVAR" to get our of env var rather than config): ',
209
- 'ENVVAR')
210
-
211
- context = Context(name, CLARIFAI_USER_ID=user_id, CLARIFAI_API_BASE=base_url, CLARIFAI_PAT=pat)
212
- ctx.obj.contexts[context.name] = context
213
- ctx.obj.to_yaml()
214
-
215
-
216
- # write a click command to delete a context
217
- @context.command(['rm'])
218
- @click.argument('name')
219
- @click.pass_context
220
- def delete(ctx, name):
221
- """Delete a context"""
222
- if name not in ctx.obj.contexts:
223
- print(f'{name} is not a valid context')
224
- exit(1)
225
- ctx.obj.contexts.pop(name)
226
- ctx.obj.to_yaml()
227
- print(f'{name} deleted')
228
-
229
-
230
- @context.command()
231
- @click.argument('name', type=str)
232
- @click.pass_context
233
- def use(ctx, name):
234
- """Set the current context"""
235
- if name not in ctx.obj.contexts:
236
- raise click.UsageError('Context not found')
237
- ctx.obj.current_context = name
238
- ctx.obj.to_yaml()
239
- print(f'Set {name} as the current context')
240
-
241
-
242
- @cli.command()
243
- @click.argument('script', type=str)
244
- @click.option('--context', type=str, help='Context to use')
245
- @click.pass_context
246
- def run(ctx, script, context=None):
247
- """Execute a script with the current context's environment"""
248
- context = ctx.obj.current if not context else context
249
- cmd = f'CLARIFAI_USER_ID={context.user_id} CLARIFAI_API_BASE={context.base_url} CLARIFAI_PAT={context.pat} '
250
- cmd += ' '.join([f'{k}={v}' for k, v in context.env.items()])
251
- cmd += f' {script}'
252
- os.system(cmd)
67
+ if 'pat' in ctx.obj:
68
+ os.environ["CLARIFAI_PAT"] = ctx.obj['pat']
69
+ click.echo("Loaded PAT from config file.")
70
+ elif 'CLARIFAI_PAT' in os.environ:
71
+ ctx.obj['pat'] = os.environ["CLARIFAI_PAT"]
72
+ click.echo("Loaded PAT from environment variable.")
73
+ else:
74
+ _pat = click.prompt(
75
+ "Get your PAT from https://clarifai.com/settings/security and pass it here", type=str)
76
+ os.environ["CLARIFAI_PAT"] = _pat
77
+ ctx.obj['pat'] = _pat
78
+ click.echo("PAT saved successfully.")
79
+
80
+ if user_id:
81
+ ctx.obj['user_id'] = user_id
82
+ os.environ["CLARIFAI_USER_ID"] = ctx.obj['user_id']
83
+ elif 'user_id' in ctx.obj:
84
+ ctx.obj['user_id'] = ctx.obj.get('user_id', "")
85
+ os.environ["CLARIFAI_USER_ID"] = ctx.obj['user_id']
86
+ elif 'CLARIFAI_USER_ID' in os.environ:
87
+ ctx.obj['user_id'] = os.environ["CLARIFAI_USER_ID"]
88
+ else:
89
+ user_id = click.prompt("Pass the User ID here", type=str)
90
+ os.environ["CLARIFAI_USER_ID"] = user_id
91
+ ctx.obj['user_id'] = user_id
92
+ click.echo("User ID saved successfully.")
93
+
94
+ if env:
95
+ ctx.obj['env'] = env
96
+ ctx.obj['base_url'] = set_base_url(env)
97
+ os.environ["CLARIFAI_API_BASE"] = ctx.obj['base_url']
98
+ elif 'env' in ctx.obj:
99
+ ctx.obj['env'] = ctx.obj.get('env', "prod")
100
+ ctx.obj['base_url'] = set_base_url(ctx.obj['env'])
101
+ os.environ["CLARIFAI_API_BASE"] = ctx.obj['base_url']
102
+ elif 'CLARIFAI_API_BASE' in os.environ:
103
+ ctx.obj['base_url'] = os.environ["CLARIFAI_API_BASE"]
104
+
105
+ dump_yaml(ctx.obj, 'config.yaml')
253
106
 
254
107
 
255
108
  # Import the CLI commands to register them
@@ -1,59 +1,51 @@
1
1
  import click
2
-
3
2
  from clarifai.cli.base import cli
4
3
  from clarifai.client.user import User
5
- from clarifai.utils.cli import AliasedGroup, display_co_resources, validate_context
4
+ from clarifai.utils.cli import display_co_resources
6
5
 
7
6
 
8
- @cli.group(['computecluster', 'cc'], cls=AliasedGroup)
7
+ @cli.group(['computecluster', 'cc'])
9
8
  def computecluster():
10
9
  """Manage Compute Clusters: create, delete, list"""
10
+ pass
11
11
 
12
12
 
13
- @computecluster.command(['c'])
14
- @click.argument('compute_cluster_id')
13
+ @computecluster.command()
15
14
  @click.option(
16
15
  '--config',
17
16
  type=click.Path(exists=True),
18
17
  required=True,
19
18
  help='Path to the compute cluster config file.')
19
+ @click.option(
20
+ '-cc_id',
21
+ '--compute_cluster_id',
22
+ required=False,
23
+ help='New Compute Cluster ID for the compute cluster to create.')
20
24
  @click.pass_context
21
- def create(ctx, compute_cluster_id, config):
25
+ def create(ctx, config, compute_cluster_id):
22
26
  """Create a new Compute Cluster with the given config file."""
23
- validate_context(ctx)
24
- user = User(
25
- user_id=ctx.obj.current.user_id, pat=ctx.obj.current.pat, base_url=ctx.obj.current.api_base)
27
+ user = User(user_id=ctx.obj['user_id'], pat=ctx.obj['pat'], base_url=ctx.obj['base_url'])
26
28
  if compute_cluster_id:
27
29
  user.create_compute_cluster(config, compute_cluster_id=compute_cluster_id)
28
30
  else:
29
31
  user.create_compute_cluster(config)
30
32
 
31
33
 
32
- @computecluster.command(['ls'])
34
+ @computecluster.command()
33
35
  @click.option('--page_no', required=False, help='Page number to list.', default=1)
34
36
  @click.option('--per_page', required=False, help='Number of items per page.', default=16)
35
37
  @click.pass_context
36
38
  def list(ctx, page_no, per_page):
37
39
  """List all compute clusters for the user."""
38
- validate_context(ctx)
39
- user = User(
40
- user_id=ctx.obj.current.user_id, pat=ctx.obj.current.pat, base_url=ctx.obj.current.api_base)
40
+ user = User(user_id=ctx.obj['user_id'], pat=ctx.obj['pat'], base_url=ctx.obj['base_url'])
41
41
  response = user.list_compute_clusters(page_no, per_page)
42
- display_co_resources(
43
- response,
44
- custom_columns={
45
- 'ID': lambda c: c.id,
46
- 'USER_ID': lambda c: c.user_id,
47
- 'DESCRIPTION': lambda c: c.description,
48
- })
42
+ display_co_resources(response, "Compute Cluster")
49
43
 
50
44
 
51
- @computecluster.command(['rm'])
52
- @click.argument('compute_cluster_id')
45
+ @computecluster.command()
46
+ @click.option('-cc_id', '--compute_cluster_id', help='Compute Cluster ID of the user to delete.')
53
47
  @click.pass_context
54
48
  def delete(ctx, compute_cluster_id):
55
49
  """Deletes a compute cluster for the user."""
56
- validate_context(ctx)
57
- user = User(
58
- user_id=ctx.obj.current.user_id, pat=ctx.obj.current.pat, base_url=ctx.obj.current.api_base)
50
+ user = User(user_id=ctx.obj['user_id'], pat=ctx.obj['pat'], base_url=ctx.obj['base_url'])
59
51
  user.delete_compute_clusters([compute_cluster_id])
@@ -1,110 +1,84 @@
1
1
  import click
2
-
3
2
  from clarifai.cli.base import cli
4
- from clarifai.client.compute_cluster import ComputeCluster
5
3
  from clarifai.client.nodepool import Nodepool
6
- from clarifai.client.user import User
7
- from clarifai.utils.cli import AliasedGroup, display_co_resources, from_yaml, validate_context
4
+ from clarifai.utils.cli import display_co_resources, from_yaml
8
5
 
9
6
 
10
- @cli.group(['deployment', 'dp'], cls=AliasedGroup)
7
+ @cli.group(['deployment', 'dpl'])
11
8
  def deployment():
12
9
  """Manage Deployments: create, delete, list"""
10
+ pass
13
11
 
14
12
 
15
- @deployment.command(['c'])
16
- @click.argument('nodepool_id')
17
- @click.argument('deployment_id')
13
+ @deployment.command()
14
+ @click.option(
15
+ '-np_id',
16
+ '--nodepool_id',
17
+ required=False,
18
+ help='Nodepool ID for the Nodepool to interact with.')
18
19
  @click.option(
19
20
  '--config',
20
21
  type=click.Path(exists=True),
21
22
  required=True,
22
23
  help='Path to the deployment config file.')
24
+ @click.option(
25
+ '-dpl_id',
26
+ '--deployment_id',
27
+ required=False,
28
+ help='New deployment ID for the deployment to create.')
23
29
  @click.pass_context
24
- def create(ctx, nodepool_id, deployment_id, config):
30
+ def create(ctx, nodepool_id, config, deployment_id):
25
31
  """Create a new Deployment with the given config file."""
26
-
27
- validate_context(ctx)
28
32
  if not nodepool_id:
29
33
  deployment_config = from_yaml(config)
30
34
  nodepool_id = deployment_config['deployment']['nodepools'][0]['id']
31
35
 
32
36
  nodepool = Nodepool(
33
37
  nodepool_id=nodepool_id,
34
- user_id=ctx.obj.current.user_id,
35
- pat=ctx.obj.current.pat,
36
- base_url=ctx.obj.current.api_base)
38
+ user_id=ctx.obj['user_id'],
39
+ pat=ctx.obj['pat'],
40
+ base_url=ctx.obj['base_url'])
37
41
  if deployment_id:
38
42
  nodepool.create_deployment(config, deployment_id=deployment_id)
39
43
  else:
40
44
  nodepool.create_deployment(config)
41
45
 
42
46
 
43
- @deployment.command(['ls'])
44
- @click.argument('nodepool_id', default="")
47
+ @deployment.command()
48
+ @click.option(
49
+ '-np_id',
50
+ '--nodepool_id',
51
+ required=True,
52
+ help='Nodepool ID for the Nodepool to interact with.')
45
53
  @click.option('--page_no', required=False, help='Page number to list.', default=1)
46
54
  @click.option('--per_page', required=False, help='Number of items per page.', default=16)
47
55
  @click.pass_context
48
56
  def list(ctx, nodepool_id, page_no, per_page):
49
57
  """List all deployments for the nodepool."""
50
58
 
51
- validate_context(ctx)
52
- if nodepool_id:
53
- nodepool = Nodepool(
54
- nodepool_id=nodepool_id,
55
- user_id=ctx.obj.current.user_id,
56
- pat=ctx.obj.current.pat,
57
- base_url=ctx.obj.current.api_base)
58
- response = nodepool.list_deployments(page_no=page_no, per_page=per_page)
59
- else:
60
- user = User(
61
- user_id=ctx.obj.current.user_id,
62
- pat=ctx.obj.current.pat,
63
- base_url=ctx.obj.current.api_base)
64
- ccs = user.list_compute_clusters(page_no, per_page)
65
- nps = []
66
- for cc in ccs:
67
- compute_cluster = ComputeCluster(
68
- compute_cluster_id=cc.id,
69
- user_id=ctx.obj.current.user_id,
70
- pat=ctx.obj.current.pat,
71
- base_url=ctx.obj.current.api_base)
72
- nps.extend([i for i in compute_cluster.list_nodepools(page_no, per_page)])
73
- response = []
74
- for np in nps:
75
- nodepool = Nodepool(
76
- nodepool_id=np.id,
77
- user_id=ctx.obj.current.user_id,
78
- pat=ctx.obj.current.pat,
79
- base_url=ctx.obj.current.api_base)
80
- response.extend([i for i in nodepool.list_deployments(page_no=page_no, per_page=per_page)])
81
-
82
- display_co_resources(
83
- response,
84
- custom_columns={
85
- 'ID': lambda c: c.id,
86
- 'USER_ID': lambda c: c.user_id,
87
- 'COMPUTE_CLUSTER_ID': lambda c: c.nodepools[0].compute_cluster.id,
88
- 'NODEPOOL_ID': lambda c: c.nodepools[0].id,
89
- 'MODEL_USER_ID': lambda c: c.worker.model.user_id,
90
- 'MODEL_APP_ID': lambda c: c.worker.model.app_id,
91
- 'MODEL_ID': lambda c: c.worker.model.id,
92
- 'MODEL_VERSION_ID': lambda c: c.worker.model.model_version.id,
93
- 'DESCRIPTION': lambda c: c.description,
94
- })
59
+ nodepool = Nodepool(
60
+ nodepool_id=nodepool_id,
61
+ user_id=ctx.obj['user_id'],
62
+ pat=ctx.obj['pat'],
63
+ base_url=ctx.obj['base_url'])
64
+ response = nodepool.list_deployments(page_no=page_no, per_page=per_page)
65
+ display_co_resources(response, "Deployment")
95
66
 
96
67
 
97
- @deployment.command(['rm'])
98
- @click.argument('nodepool_id')
99
- @click.argument('deployment_id')
68
+ @deployment.command()
69
+ @click.option(
70
+ '-np_id',
71
+ '--nodepool_id',
72
+ required=True,
73
+ help='Nodepool ID for the Nodepool to interact with.')
74
+ @click.option('-dpl_id', '--deployment_id', help='Deployment ID of the nodepool to delete.')
100
75
  @click.pass_context
101
76
  def delete(ctx, nodepool_id, deployment_id):
102
77
  """Deletes a deployment for the nodepool."""
103
78
 
104
- validate_context(ctx)
105
79
  nodepool = Nodepool(
106
80
  nodepool_id=nodepool_id,
107
- user_id=ctx.obj.current.user_id,
108
- pat=ctx.obj.current.pat,
109
- base_url=ctx.obj.current.api_base)
81
+ user_id=ctx.obj['user_id'],
82
+ pat=ctx.obj['pat'],
83
+ base_url=ctx.obj['base_url'])
110
84
  nodepool.delete_deployments([deployment_id])