clarifai 11.3.0rc1__py3-none-any.whl → 11.3.0rc3__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 (300) hide show
  1. clarifai/__init__.py +1 -1
  2. clarifai/cli/__main__.py +1 -1
  3. clarifai/cli/base.py +144 -136
  4. clarifai/cli/compute_cluster.py +45 -31
  5. clarifai/cli/deployment.py +93 -76
  6. clarifai/cli/model.py +578 -180
  7. clarifai/cli/nodepool.py +100 -82
  8. clarifai/client/__init__.py +12 -2
  9. clarifai/client/app.py +973 -911
  10. clarifai/client/auth/helper.py +351 -342
  11. clarifai/client/auth/register.py +7 -7
  12. clarifai/client/auth/stub.py +107 -106
  13. clarifai/client/base.py +185 -178
  14. clarifai/client/compute_cluster.py +214 -180
  15. clarifai/client/dataset.py +793 -698
  16. clarifai/client/deployment.py +55 -50
  17. clarifai/client/input.py +1223 -1088
  18. clarifai/client/lister.py +47 -45
  19. clarifai/client/model.py +1939 -1717
  20. clarifai/client/model_client.py +525 -502
  21. clarifai/client/module.py +82 -73
  22. clarifai/client/nodepool.py +358 -213
  23. clarifai/client/runner.py +58 -0
  24. clarifai/client/search.py +342 -309
  25. clarifai/client/user.py +419 -414
  26. clarifai/client/workflow.py +294 -274
  27. clarifai/constants/dataset.py +11 -17
  28. clarifai/constants/model.py +8 -2
  29. clarifai/datasets/export/inputs_annotations.py +233 -217
  30. clarifai/datasets/upload/base.py +63 -51
  31. clarifai/datasets/upload/features.py +43 -38
  32. clarifai/datasets/upload/image.py +237 -207
  33. clarifai/datasets/upload/loaders/coco_captions.py +34 -32
  34. clarifai/datasets/upload/loaders/coco_detection.py +72 -65
  35. clarifai/datasets/upload/loaders/imagenet_classification.py +57 -53
  36. clarifai/datasets/upload/loaders/xview_detection.py +274 -132
  37. clarifai/datasets/upload/multimodal.py +55 -46
  38. clarifai/datasets/upload/text.py +55 -47
  39. clarifai/datasets/upload/utils.py +250 -234
  40. clarifai/errors.py +51 -50
  41. clarifai/models/api.py +260 -238
  42. clarifai/modules/css.py +50 -50
  43. clarifai/modules/pages.py +33 -33
  44. clarifai/rag/rag.py +312 -288
  45. clarifai/rag/utils.py +91 -84
  46. clarifai/runners/models/model_builder.py +906 -802
  47. clarifai/runners/models/model_class.py +370 -331
  48. clarifai/runners/models/model_run_locally.py +459 -419
  49. clarifai/runners/models/model_runner.py +170 -162
  50. clarifai/runners/models/model_servicer.py +78 -70
  51. clarifai/runners/server.py +111 -101
  52. clarifai/runners/utils/code_script.py +225 -187
  53. clarifai/runners/utils/const.py +4 -1
  54. clarifai/runners/utils/data_types/__init__.py +12 -0
  55. clarifai/runners/utils/data_types/data_types.py +598 -0
  56. clarifai/runners/utils/data_utils.py +388 -348
  57. clarifai/runners/utils/loader.py +247 -227
  58. clarifai/runners/utils/method_signatures.py +411 -386
  59. clarifai/runners/utils/openai_convertor.py +108 -109
  60. clarifai/runners/utils/serializers.py +175 -179
  61. clarifai/runners/utils/url_fetcher.py +35 -35
  62. clarifai/schema/search.py +56 -63
  63. clarifai/urls/helper.py +125 -102
  64. clarifai/utils/cli.py +129 -123
  65. clarifai/utils/config.py +127 -87
  66. clarifai/utils/constants.py +49 -0
  67. clarifai/utils/evaluation/helpers.py +503 -466
  68. clarifai/utils/evaluation/main.py +431 -393
  69. clarifai/utils/evaluation/testset_annotation_parser.py +154 -144
  70. clarifai/utils/logging.py +324 -306
  71. clarifai/utils/misc.py +60 -56
  72. clarifai/utils/model_train.py +165 -146
  73. clarifai/utils/protobuf.py +126 -103
  74. clarifai/versions.py +3 -1
  75. clarifai/workflows/export.py +48 -50
  76. clarifai/workflows/utils.py +39 -36
  77. clarifai/workflows/validate.py +55 -43
  78. {clarifai-11.3.0rc1.dist-info → clarifai-11.3.0rc3.dist-info}/METADATA +5 -6
  79. clarifai-11.3.0rc3.dist-info/RECORD +109 -0
  80. {clarifai-11.3.0rc1.dist-info → clarifai-11.3.0rc3.dist-info}/WHEEL +1 -1
  81. clarifai/__pycache__/__init__.cpython-310.pyc +0 -0
  82. clarifai/__pycache__/__init__.cpython-311.pyc +0 -0
  83. clarifai/__pycache__/__init__.cpython-39.pyc +0 -0
  84. clarifai/__pycache__/errors.cpython-310.pyc +0 -0
  85. clarifai/__pycache__/errors.cpython-311.pyc +0 -0
  86. clarifai/__pycache__/versions.cpython-310.pyc +0 -0
  87. clarifai/__pycache__/versions.cpython-311.pyc +0 -0
  88. clarifai/cli/__pycache__/__init__.cpython-310.pyc +0 -0
  89. clarifai/cli/__pycache__/__init__.cpython-311.pyc +0 -0
  90. clarifai/cli/__pycache__/base.cpython-310.pyc +0 -0
  91. clarifai/cli/__pycache__/base.cpython-311.pyc +0 -0
  92. clarifai/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
  93. clarifai/cli/__pycache__/compute_cluster.cpython-310.pyc +0 -0
  94. clarifai/cli/__pycache__/compute_cluster.cpython-311.pyc +0 -0
  95. clarifai/cli/__pycache__/deployment.cpython-310.pyc +0 -0
  96. clarifai/cli/__pycache__/deployment.cpython-311.pyc +0 -0
  97. clarifai/cli/__pycache__/model.cpython-310.pyc +0 -0
  98. clarifai/cli/__pycache__/model.cpython-311.pyc +0 -0
  99. clarifai/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
  100. clarifai/cli/__pycache__/nodepool.cpython-310.pyc +0 -0
  101. clarifai/cli/__pycache__/nodepool.cpython-311.pyc +0 -0
  102. clarifai/client/__pycache__/__init__.cpython-310.pyc +0 -0
  103. clarifai/client/__pycache__/__init__.cpython-311.pyc +0 -0
  104. clarifai/client/__pycache__/__init__.cpython-39.pyc +0 -0
  105. clarifai/client/__pycache__/app.cpython-310.pyc +0 -0
  106. clarifai/client/__pycache__/app.cpython-311.pyc +0 -0
  107. clarifai/client/__pycache__/app.cpython-39.pyc +0 -0
  108. clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
  109. clarifai/client/__pycache__/base.cpython-311.pyc +0 -0
  110. clarifai/client/__pycache__/compute_cluster.cpython-310.pyc +0 -0
  111. clarifai/client/__pycache__/compute_cluster.cpython-311.pyc +0 -0
  112. clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
  113. clarifai/client/__pycache__/dataset.cpython-311.pyc +0 -0
  114. clarifai/client/__pycache__/deployment.cpython-310.pyc +0 -0
  115. clarifai/client/__pycache__/deployment.cpython-311.pyc +0 -0
  116. clarifai/client/__pycache__/input.cpython-310.pyc +0 -0
  117. clarifai/client/__pycache__/input.cpython-311.pyc +0 -0
  118. clarifai/client/__pycache__/lister.cpython-310.pyc +0 -0
  119. clarifai/client/__pycache__/lister.cpython-311.pyc +0 -0
  120. clarifai/client/__pycache__/model.cpython-310.pyc +0 -0
  121. clarifai/client/__pycache__/model.cpython-311.pyc +0 -0
  122. clarifai/client/__pycache__/module.cpython-310.pyc +0 -0
  123. clarifai/client/__pycache__/module.cpython-311.pyc +0 -0
  124. clarifai/client/__pycache__/nodepool.cpython-310.pyc +0 -0
  125. clarifai/client/__pycache__/nodepool.cpython-311.pyc +0 -0
  126. clarifai/client/__pycache__/search.cpython-310.pyc +0 -0
  127. clarifai/client/__pycache__/search.cpython-311.pyc +0 -0
  128. clarifai/client/__pycache__/user.cpython-310.pyc +0 -0
  129. clarifai/client/__pycache__/user.cpython-311.pyc +0 -0
  130. clarifai/client/__pycache__/workflow.cpython-310.pyc +0 -0
  131. clarifai/client/__pycache__/workflow.cpython-311.pyc +0 -0
  132. clarifai/client/auth/__pycache__/__init__.cpython-310.pyc +0 -0
  133. clarifai/client/auth/__pycache__/__init__.cpython-311.pyc +0 -0
  134. clarifai/client/auth/__pycache__/helper.cpython-310.pyc +0 -0
  135. clarifai/client/auth/__pycache__/helper.cpython-311.pyc +0 -0
  136. clarifai/client/auth/__pycache__/register.cpython-310.pyc +0 -0
  137. clarifai/client/auth/__pycache__/register.cpython-311.pyc +0 -0
  138. clarifai/client/auth/__pycache__/stub.cpython-310.pyc +0 -0
  139. clarifai/client/auth/__pycache__/stub.cpython-311.pyc +0 -0
  140. clarifai/client/cli/__init__.py +0 -0
  141. clarifai/client/cli/__pycache__/__init__.cpython-310.pyc +0 -0
  142. clarifai/client/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
  143. clarifai/client/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
  144. clarifai/client/cli/base_cli.py +0 -88
  145. clarifai/client/cli/model_cli.py +0 -29
  146. clarifai/constants/__pycache__/base.cpython-310.pyc +0 -0
  147. clarifai/constants/__pycache__/base.cpython-311.pyc +0 -0
  148. clarifai/constants/__pycache__/dataset.cpython-310.pyc +0 -0
  149. clarifai/constants/__pycache__/dataset.cpython-311.pyc +0 -0
  150. clarifai/constants/__pycache__/input.cpython-310.pyc +0 -0
  151. clarifai/constants/__pycache__/input.cpython-311.pyc +0 -0
  152. clarifai/constants/__pycache__/model.cpython-310.pyc +0 -0
  153. clarifai/constants/__pycache__/model.cpython-311.pyc +0 -0
  154. clarifai/constants/__pycache__/rag.cpython-310.pyc +0 -0
  155. clarifai/constants/__pycache__/rag.cpython-311.pyc +0 -0
  156. clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
  157. clarifai/constants/__pycache__/search.cpython-311.pyc +0 -0
  158. clarifai/constants/__pycache__/workflow.cpython-310.pyc +0 -0
  159. clarifai/constants/__pycache__/workflow.cpython-311.pyc +0 -0
  160. clarifai/datasets/__pycache__/__init__.cpython-310.pyc +0 -0
  161. clarifai/datasets/__pycache__/__init__.cpython-311.pyc +0 -0
  162. clarifai/datasets/__pycache__/__init__.cpython-39.pyc +0 -0
  163. clarifai/datasets/export/__pycache__/__init__.cpython-310.pyc +0 -0
  164. clarifai/datasets/export/__pycache__/__init__.cpython-311.pyc +0 -0
  165. clarifai/datasets/export/__pycache__/__init__.cpython-39.pyc +0 -0
  166. clarifai/datasets/export/__pycache__/inputs_annotations.cpython-310.pyc +0 -0
  167. clarifai/datasets/export/__pycache__/inputs_annotations.cpython-311.pyc +0 -0
  168. clarifai/datasets/upload/__pycache__/__init__.cpython-310.pyc +0 -0
  169. clarifai/datasets/upload/__pycache__/__init__.cpython-311.pyc +0 -0
  170. clarifai/datasets/upload/__pycache__/__init__.cpython-39.pyc +0 -0
  171. clarifai/datasets/upload/__pycache__/base.cpython-310.pyc +0 -0
  172. clarifai/datasets/upload/__pycache__/base.cpython-311.pyc +0 -0
  173. clarifai/datasets/upload/__pycache__/features.cpython-310.pyc +0 -0
  174. clarifai/datasets/upload/__pycache__/features.cpython-311.pyc +0 -0
  175. clarifai/datasets/upload/__pycache__/image.cpython-310.pyc +0 -0
  176. clarifai/datasets/upload/__pycache__/image.cpython-311.pyc +0 -0
  177. clarifai/datasets/upload/__pycache__/multimodal.cpython-310.pyc +0 -0
  178. clarifai/datasets/upload/__pycache__/multimodal.cpython-311.pyc +0 -0
  179. clarifai/datasets/upload/__pycache__/text.cpython-310.pyc +0 -0
  180. clarifai/datasets/upload/__pycache__/text.cpython-311.pyc +0 -0
  181. clarifai/datasets/upload/__pycache__/utils.cpython-310.pyc +0 -0
  182. clarifai/datasets/upload/__pycache__/utils.cpython-311.pyc +0 -0
  183. clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-311.pyc +0 -0
  184. clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-39.pyc +0 -0
  185. clarifai/datasets/upload/loaders/__pycache__/coco_detection.cpython-311.pyc +0 -0
  186. clarifai/datasets/upload/loaders/__pycache__/imagenet_classification.cpython-311.pyc +0 -0
  187. clarifai/models/__pycache__/__init__.cpython-39.pyc +0 -0
  188. clarifai/modules/__pycache__/__init__.cpython-39.pyc +0 -0
  189. clarifai/rag/__pycache__/__init__.cpython-310.pyc +0 -0
  190. clarifai/rag/__pycache__/__init__.cpython-311.pyc +0 -0
  191. clarifai/rag/__pycache__/__init__.cpython-39.pyc +0 -0
  192. clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
  193. clarifai/rag/__pycache__/rag.cpython-311.pyc +0 -0
  194. clarifai/rag/__pycache__/rag.cpython-39.pyc +0 -0
  195. clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
  196. clarifai/rag/__pycache__/utils.cpython-311.pyc +0 -0
  197. clarifai/runners/__pycache__/__init__.cpython-310.pyc +0 -0
  198. clarifai/runners/__pycache__/__init__.cpython-311.pyc +0 -0
  199. clarifai/runners/__pycache__/__init__.cpython-39.pyc +0 -0
  200. clarifai/runners/dockerfile_template/Dockerfile.cpu.template +0 -31
  201. clarifai/runners/dockerfile_template/Dockerfile.cuda.template +0 -42
  202. clarifai/runners/dockerfile_template/Dockerfile.nim +0 -71
  203. clarifai/runners/models/__pycache__/__init__.cpython-310.pyc +0 -0
  204. clarifai/runners/models/__pycache__/__init__.cpython-311.pyc +0 -0
  205. clarifai/runners/models/__pycache__/__init__.cpython-39.pyc +0 -0
  206. clarifai/runners/models/__pycache__/base_typed_model.cpython-310.pyc +0 -0
  207. clarifai/runners/models/__pycache__/base_typed_model.cpython-311.pyc +0 -0
  208. clarifai/runners/models/__pycache__/base_typed_model.cpython-39.pyc +0 -0
  209. clarifai/runners/models/__pycache__/model_builder.cpython-311.pyc +0 -0
  210. clarifai/runners/models/__pycache__/model_class.cpython-310.pyc +0 -0
  211. clarifai/runners/models/__pycache__/model_class.cpython-311.pyc +0 -0
  212. clarifai/runners/models/__pycache__/model_run_locally.cpython-310-pytest-7.1.2.pyc +0 -0
  213. clarifai/runners/models/__pycache__/model_run_locally.cpython-310.pyc +0 -0
  214. clarifai/runners/models/__pycache__/model_run_locally.cpython-311.pyc +0 -0
  215. clarifai/runners/models/__pycache__/model_runner.cpython-310.pyc +0 -0
  216. clarifai/runners/models/__pycache__/model_runner.cpython-311.pyc +0 -0
  217. clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc +0 -0
  218. clarifai/runners/models/base_typed_model.py +0 -238
  219. clarifai/runners/models/model_class_refract.py +0 -80
  220. clarifai/runners/models/model_upload.py +0 -607
  221. clarifai/runners/models/temp.py +0 -25
  222. clarifai/runners/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  223. clarifai/runners/utils/__pycache__/__init__.cpython-311.pyc +0 -0
  224. clarifai/runners/utils/__pycache__/__init__.cpython-38.pyc +0 -0
  225. clarifai/runners/utils/__pycache__/__init__.cpython-39.pyc +0 -0
  226. clarifai/runners/utils/__pycache__/buffered_stream.cpython-310.pyc +0 -0
  227. clarifai/runners/utils/__pycache__/buffered_stream.cpython-38.pyc +0 -0
  228. clarifai/runners/utils/__pycache__/buffered_stream.cpython-39.pyc +0 -0
  229. clarifai/runners/utils/__pycache__/const.cpython-310.pyc +0 -0
  230. clarifai/runners/utils/__pycache__/const.cpython-311.pyc +0 -0
  231. clarifai/runners/utils/__pycache__/constants.cpython-310.pyc +0 -0
  232. clarifai/runners/utils/__pycache__/constants.cpython-38.pyc +0 -0
  233. clarifai/runners/utils/__pycache__/constants.cpython-39.pyc +0 -0
  234. clarifai/runners/utils/__pycache__/data_handler.cpython-310.pyc +0 -0
  235. clarifai/runners/utils/__pycache__/data_handler.cpython-311.pyc +0 -0
  236. clarifai/runners/utils/__pycache__/data_handler.cpython-38.pyc +0 -0
  237. clarifai/runners/utils/__pycache__/data_handler.cpython-39.pyc +0 -0
  238. clarifai/runners/utils/__pycache__/data_utils.cpython-310.pyc +0 -0
  239. clarifai/runners/utils/__pycache__/data_utils.cpython-311.pyc +0 -0
  240. clarifai/runners/utils/__pycache__/data_utils.cpython-38.pyc +0 -0
  241. clarifai/runners/utils/__pycache__/data_utils.cpython-39.pyc +0 -0
  242. clarifai/runners/utils/__pycache__/grpc_server.cpython-310.pyc +0 -0
  243. clarifai/runners/utils/__pycache__/grpc_server.cpython-38.pyc +0 -0
  244. clarifai/runners/utils/__pycache__/grpc_server.cpython-39.pyc +0 -0
  245. clarifai/runners/utils/__pycache__/health.cpython-310.pyc +0 -0
  246. clarifai/runners/utils/__pycache__/health.cpython-38.pyc +0 -0
  247. clarifai/runners/utils/__pycache__/health.cpython-39.pyc +0 -0
  248. clarifai/runners/utils/__pycache__/loader.cpython-310.pyc +0 -0
  249. clarifai/runners/utils/__pycache__/loader.cpython-311.pyc +0 -0
  250. clarifai/runners/utils/__pycache__/logging.cpython-310.pyc +0 -0
  251. clarifai/runners/utils/__pycache__/logging.cpython-38.pyc +0 -0
  252. clarifai/runners/utils/__pycache__/logging.cpython-39.pyc +0 -0
  253. clarifai/runners/utils/__pycache__/stream_source.cpython-310.pyc +0 -0
  254. clarifai/runners/utils/__pycache__/stream_source.cpython-39.pyc +0 -0
  255. clarifai/runners/utils/__pycache__/url_fetcher.cpython-310.pyc +0 -0
  256. clarifai/runners/utils/__pycache__/url_fetcher.cpython-311.pyc +0 -0
  257. clarifai/runners/utils/__pycache__/url_fetcher.cpython-38.pyc +0 -0
  258. clarifai/runners/utils/__pycache__/url_fetcher.cpython-39.pyc +0 -0
  259. clarifai/runners/utils/data_handler.py +0 -231
  260. clarifai/runners/utils/data_handler_refract.py +0 -213
  261. clarifai/runners/utils/data_types.py +0 -469
  262. clarifai/runners/utils/logger.py +0 -0
  263. clarifai/runners/utils/openai_format.py +0 -87
  264. clarifai/schema/__pycache__/search.cpython-310.pyc +0 -0
  265. clarifai/schema/__pycache__/search.cpython-311.pyc +0 -0
  266. clarifai/urls/__pycache__/helper.cpython-310.pyc +0 -0
  267. clarifai/urls/__pycache__/helper.cpython-311.pyc +0 -0
  268. clarifai/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  269. clarifai/utils/__pycache__/__init__.cpython-311.pyc +0 -0
  270. clarifai/utils/__pycache__/__init__.cpython-39.pyc +0 -0
  271. clarifai/utils/__pycache__/cli.cpython-310.pyc +0 -0
  272. clarifai/utils/__pycache__/cli.cpython-311.pyc +0 -0
  273. clarifai/utils/__pycache__/config.cpython-311.pyc +0 -0
  274. clarifai/utils/__pycache__/constants.cpython-310.pyc +0 -0
  275. clarifai/utils/__pycache__/constants.cpython-311.pyc +0 -0
  276. clarifai/utils/__pycache__/logging.cpython-310.pyc +0 -0
  277. clarifai/utils/__pycache__/logging.cpython-311.pyc +0 -0
  278. clarifai/utils/__pycache__/misc.cpython-310.pyc +0 -0
  279. clarifai/utils/__pycache__/misc.cpython-311.pyc +0 -0
  280. clarifai/utils/__pycache__/model_train.cpython-310.pyc +0 -0
  281. clarifai/utils/__pycache__/model_train.cpython-311.pyc +0 -0
  282. clarifai/utils/__pycache__/protobuf.cpython-311.pyc +0 -0
  283. clarifai/utils/evaluation/__pycache__/__init__.cpython-311.pyc +0 -0
  284. clarifai/utils/evaluation/__pycache__/__init__.cpython-39.pyc +0 -0
  285. clarifai/utils/evaluation/__pycache__/helpers.cpython-311.pyc +0 -0
  286. clarifai/utils/evaluation/__pycache__/main.cpython-311.pyc +0 -0
  287. clarifai/utils/evaluation/__pycache__/main.cpython-39.pyc +0 -0
  288. clarifai/workflows/__pycache__/__init__.cpython-310.pyc +0 -0
  289. clarifai/workflows/__pycache__/__init__.cpython-311.pyc +0 -0
  290. clarifai/workflows/__pycache__/__init__.cpython-39.pyc +0 -0
  291. clarifai/workflows/__pycache__/export.cpython-310.pyc +0 -0
  292. clarifai/workflows/__pycache__/export.cpython-311.pyc +0 -0
  293. clarifai/workflows/__pycache__/utils.cpython-310.pyc +0 -0
  294. clarifai/workflows/__pycache__/utils.cpython-311.pyc +0 -0
  295. clarifai/workflows/__pycache__/validate.cpython-310.pyc +0 -0
  296. clarifai/workflows/__pycache__/validate.cpython-311.pyc +0 -0
  297. clarifai-11.3.0rc1.dist-info/RECORD +0 -322
  298. {clarifai-11.3.0rc1.dist-info → clarifai-11.3.0rc3.dist-info}/entry_points.txt +0 -0
  299. {clarifai-11.3.0rc1.dist-info → clarifai-11.3.0rc3.dist-info/licenses}/LICENSE +0 -0
  300. {clarifai-11.3.0rc1.dist-info → clarifai-11.3.0rc3.dist-info}/top_level.txt +0 -0
clarifai/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "11.3.0rc1"
1
+ __version__ = "11.3.0rc3"
clarifai/cli/__main__.py CHANGED
@@ -1,4 +1,4 @@
1
1
  from clarifai.cli.base import main
2
2
 
3
3
  if __name__ == "__main__":
4
- main()
4
+ main()
clarifai/cli/base.py CHANGED
@@ -1,5 +1,6 @@
1
1
  import json
2
2
  import os
3
+ import shutil
3
4
  import sys
4
5
 
5
6
  import click
@@ -11,117 +12,135 @@ from clarifai.utils.constants import DEFAULT_CONFIG
11
12
  from clarifai.utils.logging import logger
12
13
 
13
14
 
14
- #@click.group(cls=CustomMultiGroup)
15
+ # @click.group(cls=CustomMultiGroup)
15
16
  @click.group(cls=AliasedGroup)
16
17
  @click.option('--config', default=DEFAULT_CONFIG)
17
18
  @click.pass_context
18
19
  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(
20
+ """Clarifai CLI"""
21
+ ctx.ensure_object(dict)
22
+ if os.path.exists(config):
23
+ cfg = Config.from_yaml(filename=config)
24
+ ctx.obj = cfg
25
+ else:
26
+ cfg = Config(
27
+ filename=config,
28
+ current_context='default',
29
+ contexts={
30
+ 'default': Context(
31
31
  'default',
32
32
  CLARIFAI_PAT=os.environ.get('CLARIFAI_PAT', ''),
33
33
  CLARIFAI_USER_ID=os.environ.get('CLARIFAI_USER_ID', ''),
34
34
  CLARIFAI_API_BASE=os.environ.get('CLARIFAI_API_BASE', 'api.clarifai.com'),
35
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.
36
+ },
37
+ )
38
+ try:
39
+ cfg.to_yaml(config)
40
+ except Exception:
41
+ logger.warning(
42
+ "Could not write configuration to disk. Could be a read only file system."
43
+ )
44
+ ctx.obj = cfg # still have the default config even if couldn't write.
42
45
 
43
46
 
44
47
  @cli.command()
45
48
  @click.argument('shell', type=click.Choice(['bash', 'zsh']))
46
49
  def shell_completion(shell):
47
- """Shell completion script"""
48
- os.system(f"_CLARIFAI_COMPLETE={shell}_source clarifai")
50
+ """Shell completion script"""
51
+ os.system(f"_CLARIFAI_COMPLETE={shell}_source clarifai")
49
52
 
50
53
 
51
- @cli.group(['cfg'], cls=AliasedGroup)
54
+ @cli.group(
55
+ ['cfg'],
56
+ cls=AliasedGroup,
57
+ context_settings={'max_content_width': shutil.get_terminal_size().columns - 10},
58
+ )
52
59
  def config():
53
- """Manage CLI configuration"""
60
+ """Manage CLI configuration"""
54
61
 
55
62
 
56
63
  @config.command(['e'])
57
64
  @click.pass_context
58
65
  def edit(ctx):
59
- """Edit the configuration file"""
60
- os.system(f'{os.environ.get("EDITOR", "vi")} {ctx.obj.filename}')
66
+ """Edit the configuration file"""
67
+ os.system(f'{os.environ.get("EDITOR", "vi")} {ctx.obj.filename}')
61
68
 
62
69
 
63
70
  @config.command(['current'])
64
71
  @click.option('-o', '--output-format', default='name', type=click.Choice(['name', 'json', 'yaml']))
65
72
  @click.pass_context
66
73
  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()))
74
+ """Get the current context"""
75
+ if output_format == 'name':
76
+ print(ctx.obj.current_context)
77
+ elif output_format == 'json':
78
+ print(json.dumps(ctx.obj.contexts[ctx.obj.current_context].to_serializable_dict()))
73
79
  else:
74
- print(yaml.safe_dump(ctx.obj.contexts[ctx.obj.current_context].to_serializable_dict()))
80
+ print(yaml.safe_dump(ctx.obj.contexts[ctx.obj.current_context].to_serializable_dict()))
75
81
 
76
82
 
77
83
  @config.command(['list', 'ls'])
78
84
  @click.option(
79
- '-o', '--output-format', default='wide', type=click.Choice(['wide', 'name', 'json', 'yaml']))
85
+ '-o', '--output-format', default='wide', type=click.Choice(['wide', 'name', 'json', 'yaml'])
86
+ )
80
87
  @click.pass_context
81
88
  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))
89
+ """Get all contexts"""
90
+ if output_format == 'wide':
91
+ columns = {
92
+ '': lambda c: '*' if c.name == ctx.obj.current_context else '',
93
+ 'NAME': lambda c: c.name,
94
+ 'USER_ID': lambda c: c.user_id,
95
+ 'API_BASE': lambda c: c.api_base,
96
+ 'PAT': lambda c: pat_display(c.pat),
97
+ }
98
+ additional_columns = set()
99
+ for cont in ctx.obj.contexts.values():
100
+ if 'env' in cont:
101
+ for key in cont.to_column_names():
102
+ if key not in columns:
103
+ additional_columns.add(key)
104
+ for key in sorted(additional_columns):
105
+ columns[key] = lambda c, k=key: getattr(c, k) if hasattr(c, k) else ""
106
+
107
+ formatter = TableFormatter(
108
+ custom_columns=columns,
109
+ )
110
+ print(formatter.format(ctx.obj.contexts.values(), fmt="plain"))
111
+ elif output_format == 'name':
112
+ print('\n'.join(ctx.obj.contexts))
113
+ elif output_format in ('json', 'yaml'):
114
+ dicts = [v.__dict__ for c, v in ctx.obj.contexts.items()]
115
+ for d in dicts:
116
+ d.pop('pat')
117
+ if output_format == 'json':
118
+ print(json.dumps(dicts))
119
+ elif output_format == 'yaml':
120
+ print(yaml.safe_dump(dicts))
102
121
 
103
122
 
104
123
  @config.command(['use'])
105
124
  @click.argument('context-name', type=str)
106
125
  @click.pass_context
107
126
  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')
127
+ """Set the current context"""
128
+ if context_name not in ctx.obj.contexts:
129
+ raise click.UsageError('Context not found')
130
+ ctx.obj.current_context = context_name
131
+ ctx.obj.to_yaml()
132
+ print(f'Set {context_name} as the current context')
114
133
 
115
134
 
116
135
  @config.command(['cat'])
117
136
  @click.option('-o', '--output-format', default='yaml', type=click.Choice(['yaml', 'json']))
118
137
  @click.pass_obj
119
138
  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)
123
- else:
124
- json.dump(ctx_obj.to_dict(), sys.stdout, indent=2)
139
+ """Dump the configuration to stdout"""
140
+ if output_format == 'yaml':
141
+ yaml.safe_dump(ctx_obj.to_dict(), sys.stdout)
142
+ else:
143
+ json.dump(ctx_obj.to_dict(), sys.stdout, indent=2)
125
144
 
126
145
 
127
146
  @cli.command()
@@ -129,56 +148,43 @@ def dump(ctx_obj, output_format):
129
148
  @click.option('--user_id', required=False, help='User ID')
130
149
  @click.pass_context
131
150
  def login(ctx, api_url, user_id):
132
- """Login command to set PAT and other configurations."""
151
+ """Login command to set PAT and other configurations."""
133
152
 
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')
153
+ name = input('context name (default: "default"): ')
154
+ user_id = user_id if user_id is not None else input('user id: ')
155
+ pat = input_or_default(
156
+ 'personal access token value (default: "ENVVAR" to get our of env var rather than config): ',
157
+ 'ENVVAR',
158
+ )
139
159
 
140
- context = Context(
141
- name,
142
- CLARIFAI_API_BASE=api_url,
143
- CLARIFAI_USER_ID=user_id,
144
- CLARIFAI_PAT=pat,
145
- )
160
+ context = Context(
161
+ name,
162
+ CLARIFAI_API_BASE=api_url,
163
+ CLARIFAI_USER_ID=user_id,
164
+ CLARIFAI_PAT=pat,
165
+ )
146
166
 
147
- if context.name == '':
148
- context.name = 'default'
167
+ if context.name == '':
168
+ context.name = 'default'
149
169
 
150
- ctx.obj.contexts[context.name] = context
151
- ctx.obj.current_context = context.name
170
+ ctx.obj.contexts[context.name] = context
171
+ ctx.obj.current_context = context.name
152
172
 
153
- ctx.obj.to_yaml()
173
+ ctx.obj.to_yaml()
154
174
 
155
175
 
156
176
  @cli.group(cls=AliasedGroup)
157
177
  def context():
158
- """Manage contexts"""
178
+ """Manage contexts"""
159
179
 
160
180
 
161
181
  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"))
182
+ return pat[:5] + "****"
177
183
 
178
184
 
179
185
  def input_or_default(prompt, default):
180
- value = input(prompt)
181
- return value if value else default
186
+ value = input(prompt)
187
+ return value if value else default
182
188
 
183
189
 
184
190
  @context.command()
@@ -194,23 +200,25 @@ def create(
194
200
  base_url=None,
195
201
  pat=None,
196
202
  ):
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()
203
+ """Create a new context"""
204
+ if name in ctx.obj.contexts:
205
+ print(f'{name} already exists')
206
+ sys.exit(1)
207
+ if not user_id:
208
+ user_id = input('user id: ')
209
+ if not base_url:
210
+ base_url = input_or_default(
211
+ 'base url (default: https://api.clarifai.com): ', 'https://api.clarifai.com'
212
+ )
213
+ if not pat:
214
+ pat = input_or_default(
215
+ 'personal access token value (default: "ENVVAR" to get our of env var rather than config): ',
216
+ 'ENVVAR',
217
+ )
218
+
219
+ context = Context(name, CLARIFAI_USER_ID=user_id, CLARIFAI_API_BASE=base_url, CLARIFAI_PAT=pat)
220
+ ctx.obj.contexts[context.name] = context
221
+ ctx.obj.to_yaml()
214
222
 
215
223
 
216
224
  # write a click command to delete a context
@@ -218,25 +226,25 @@ def create(
218
226
  @click.argument('name')
219
227
  @click.pass_context
220
228
  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')
229
+ """Delete a context"""
230
+ if name not in ctx.obj.contexts:
231
+ print(f'{name} is not a valid context')
232
+ sys.exit(1)
233
+ ctx.obj.contexts.pop(name)
234
+ ctx.obj.to_yaml()
235
+ print(f'{name} deleted')
228
236
 
229
237
 
230
238
  @context.command()
231
239
  @click.argument('name', type=str)
232
240
  @click.pass_context
233
241
  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')
242
+ """Set the current context"""
243
+ if name not in ctx.obj.contexts:
244
+ raise click.UsageError('Context not found')
245
+ ctx.obj.current_context = name
246
+ ctx.obj.to_yaml()
247
+ print(f'Set {name} as the current context')
240
248
 
241
249
 
242
250
  @cli.command()
@@ -244,12 +252,12 @@ def use(ctx, name):
244
252
  @click.option('--context', type=str, help='Context to use')
245
253
  @click.pass_context
246
254
  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)
255
+ """Execute a script with the current context's environment"""
256
+ context = ctx.obj.current if not context else context
257
+ cmd = f'CLARIFAI_USER_ID={context.user_id} CLARIFAI_API_BASE={context.base_url} CLARIFAI_PAT={context.pat} '
258
+ cmd += ' '.join([f'{k}={v}' for k, v in context.env.items()])
259
+ cmd += f' {script}'
260
+ os.system(cmd)
253
261
 
254
262
 
255
263
  # Import the CLI commands to register them
@@ -257,4 +265,4 @@ load_command_modules()
257
265
 
258
266
 
259
267
  def main():
260
- cli()
268
+ cli()
@@ -1,12 +1,18 @@
1
+ import shutil
2
+
1
3
  import click
2
4
 
3
5
  from clarifai.cli.base import cli
4
6
  from clarifai.utils.cli import AliasedGroup, display_co_resources, validate_context
5
7
 
6
8
 
7
- @cli.group(['computecluster', 'cc'], cls=AliasedGroup)
9
+ @cli.group(
10
+ ['computecluster', 'cc'],
11
+ cls=AliasedGroup,
12
+ context_settings={'max_content_width': shutil.get_terminal_size().columns - 10},
13
+ )
8
14
  def computecluster():
9
- """Manage Compute Clusters: create, delete, list"""
15
+ """Manage Compute Clusters: create, delete, list"""
10
16
 
11
17
 
12
18
  @computecluster.command(['c'])
@@ -15,18 +21,21 @@ def computecluster():
15
21
  '--config',
16
22
  type=click.Path(exists=True),
17
23
  required=True,
18
- help='Path to the compute cluster config file.')
24
+ help='Path to the compute cluster config file.',
25
+ )
19
26
  @click.pass_context
20
27
  def create(ctx, compute_cluster_id, config):
21
- """Create a new Compute Cluster with the given config file."""
22
- from clarifai.client.user import User
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)
26
- if compute_cluster_id:
27
- user.create_compute_cluster(config, compute_cluster_id=compute_cluster_id)
28
- else:
29
- user.create_compute_cluster(config)
28
+ """Create a new Compute Cluster with the given config file."""
29
+ from clarifai.client.user import User
30
+
31
+ validate_context(ctx)
32
+ user = User(
33
+ user_id=ctx.obj.current.user_id, pat=ctx.obj.current.pat, base_url=ctx.obj.current.api_base
34
+ )
35
+ if compute_cluster_id:
36
+ user.create_compute_cluster(config, compute_cluster_id=compute_cluster_id)
37
+ else:
38
+ user.create_compute_cluster(config)
30
39
 
31
40
 
32
41
  @computecluster.command(['ls'])
@@ -34,28 +43,33 @@ def create(ctx, compute_cluster_id, config):
34
43
  @click.option('--per_page', required=False, help='Number of items per page.', default=16)
35
44
  @click.pass_context
36
45
  def list(ctx, page_no, per_page):
37
- """List all compute clusters for the user."""
38
- from clarifai.client.user import User
39
- validate_context(ctx)
40
- user = User(
41
- user_id=ctx.obj.current.user_id, pat=ctx.obj.current.pat, base_url=ctx.obj.current.api_base)
42
- response = user.list_compute_clusters(page_no, per_page)
43
- display_co_resources(
44
- response,
45
- custom_columns={
46
- 'ID': lambda c: c.id,
47
- 'USER_ID': lambda c: c.user_id,
48
- 'DESCRIPTION': lambda c: c.description,
49
- })
46
+ """List all compute clusters for the user."""
47
+ from clarifai.client.user import User
48
+
49
+ validate_context(ctx)
50
+ user = User(
51
+ user_id=ctx.obj.current.user_id, pat=ctx.obj.current.pat, base_url=ctx.obj.current.api_base
52
+ )
53
+ response = user.list_compute_clusters(page_no, per_page)
54
+ display_co_resources(
55
+ response,
56
+ custom_columns={
57
+ 'ID': lambda c: c.id,
58
+ 'USER_ID': lambda c: c.user_id,
59
+ 'DESCRIPTION': lambda c: c.description,
60
+ },
61
+ )
50
62
 
51
63
 
52
64
  @computecluster.command(['rm'])
53
65
  @click.argument('compute_cluster_id')
54
66
  @click.pass_context
55
67
  def delete(ctx, compute_cluster_id):
56
- """Deletes a compute cluster for the user."""
57
- from clarifai.client.user import User
58
- validate_context(ctx)
59
- user = User(
60
- user_id=ctx.obj.current.user_id, pat=ctx.obj.current.pat, base_url=ctx.obj.current.api_base)
61
- user.delete_compute_clusters([compute_cluster_id])
68
+ """Deletes a compute cluster for the user."""
69
+ from clarifai.client.user import User
70
+
71
+ validate_context(ctx)
72
+ user = User(
73
+ user_id=ctx.obj.current.user_id, pat=ctx.obj.current.pat, base_url=ctx.obj.current.api_base
74
+ )
75
+ user.delete_compute_clusters([compute_cluster_id])