clarifai 11.3.0rc2__py3-none-any.whl → 11.4.0__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 +345 -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 +387 -440
  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.0rc2.dist-info → clarifai-11.4.0.dist-info}/METADATA +16 -6
  79. clarifai-11.4.0.dist-info/RECORD +109 -0
  80. {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.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.0rc2.dist-info/RECORD +0 -322
  298. {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/entry_points.txt +0 -0
  299. {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info/licenses}/LICENSE +0 -0
  300. {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/top_level.txt +0 -0
clarifai/utils/cli.py CHANGED
@@ -12,157 +12,163 @@ from tabulate import tabulate
12
12
 
13
13
 
14
14
  def from_yaml(filename: str):
15
- try:
16
- with open(filename, 'r') as f:
17
- return yaml.safe_load(f)
18
- except yaml.YAMLError as e:
19
- click.echo(f"Error reading YAML file: {e}", err=True)
20
- return {}
15
+ try:
16
+ with open(filename, 'r') as f:
17
+ return yaml.safe_load(f)
18
+ except yaml.YAMLError as e:
19
+ click.echo(f"Error reading YAML file: {e}", err=True)
20
+ return {}
21
21
 
22
22
 
23
23
  def dump_yaml(data, filename: str):
24
- try:
25
- with open(filename, 'w') as f:
26
- yaml.dump(data, f)
27
- except Exception as e:
28
- click.echo(f"Error writing YAML file: {e}", err=True)
24
+ try:
25
+ with open(filename, 'w') as f:
26
+ yaml.dump(data, f)
27
+ except Exception as e:
28
+ click.echo(f"Error writing YAML file: {e}", err=True)
29
29
 
30
30
 
31
31
  # Dynamically find and import all command modules from the cli directory
32
32
  def load_command_modules():
33
- package_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'cli')
33
+ package_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'cli')
34
34
 
35
- for _, module_name, _ in pkgutil.iter_modules([package_dir]):
36
- if module_name not in ['base', '__main__']: # Skip the base.py and __main__ file itself
37
- importlib.import_module(f'clarifai.cli.{module_name}')
35
+ for _, module_name, _ in pkgutil.iter_modules([package_dir]):
36
+ if module_name not in ['base', '__main__']: # Skip the base.py and __main__ file itself
37
+ importlib.import_module(f'clarifai.cli.{module_name}')
38
38
 
39
39
 
40
- def display_co_resources(response,
41
- custom_columns={
42
- 'ID': lambda c: c.id,
43
- 'USER_ID': lambda c: c.user_id,
44
- 'DESCRIPTION': lambda c: c.description,
45
- }):
46
- """Display compute orchestration resources listing results using rich."""
40
+ def display_co_resources(
41
+ response,
42
+ custom_columns={
43
+ 'ID': lambda c: c.id,
44
+ 'USER_ID': lambda c: c.user_id,
45
+ 'DESCRIPTION': lambda c: c.description,
46
+ },
47
+ ):
48
+ """Display compute orchestration resources listing results using rich."""
47
49
 
48
- formatter = TableFormatter(custom_columns)
49
- print(formatter.format(list(response), fmt="plain"))
50
+ formatter = TableFormatter(custom_columns)
51
+ print(formatter.format(list(response), fmt="plain"))
50
52
 
51
53
 
52
54
  class TableFormatter:
53
-
54
- def __init__(self, custom_columns: OrderedDict):
55
- """
55
+ def __init__(self, custom_columns: OrderedDict):
56
+ """
56
57
  Initializes the TableFormatter with column headers and custom column mappings.
57
58
 
58
59
  :param headers: List of column headers for the table.
59
60
  """
60
- self.custom_columns = custom_columns
61
+ self.custom_columns = custom_columns
61
62
 
62
- def format(self, objects, fmt='plain'):
63
- """
63
+ def format(self, objects, fmt='plain'):
64
+ """
64
65
  Formats a list of objects into a table with custom columns.
65
66
 
66
67
  :param objects: List of objects to format into a table.
67
68
  :return: A string representing the table.
68
69
  """
69
- # Prepare the rows by applying the custom column functions to each object
70
- rows = []
71
- for obj in objects:
72
- # row = [self.custom_columns[header](obj) for header in self.headers]
73
- row = [f(obj) for f in self.custom_columns.values()]
74
- rows.append(row)
70
+ # Prepare the rows by applying the custom column functions to each object
71
+ rows = []
72
+ for obj in objects:
73
+ # row = [self.custom_columns[header](obj) for header in self.headers]
74
+ row = [f(obj) for f in self.custom_columns.values()]
75
+ rows.append(row)
75
76
 
76
- # Create the table
77
- table = tabulate(rows, headers=self.custom_columns.keys(), tablefmt=fmt)
78
- return table
77
+ # Create the table
78
+ table = tabulate(rows, headers=self.custom_columns.keys(), tablefmt=fmt)
79
+ return table
79
80
 
80
81
 
81
82
  class AliasedGroup(click.Group):
82
-
83
- def __init__(self,
84
- name: t.Optional[str] = None,
85
- commands: t.Optional[t.Union[t.MutableMapping[str, click.Command], t.Sequence[
86
- click.Command]]] = None,
87
- **attrs: t.Any) -> None:
88
- super().__init__(name, commands, **attrs)
89
- self.alias_map = {}
90
- self.command_to_aliases = defaultdict(list)
91
-
92
- def add_alias(self, cmd: click.Command, alias: str) -> None:
93
- self.alias_map[alias] = cmd
94
- if alias != cmd.name:
95
- self.command_to_aliases[cmd].append(alias)
96
-
97
- def command(self, aliases=None, *args,
98
- **kwargs) -> t.Callable[[t.Callable[..., t.Any]], click.Command]:
99
- cmd_decorator = super().command(*args, **kwargs)
100
- if aliases is None:
101
- aliases = []
102
-
103
- def aliased_decorator(f):
104
- cmd = cmd_decorator(f)
105
- if cmd.name:
106
- self.add_alias(cmd, cmd.name)
107
- for alias in aliases:
108
- self.add_alias(cmd, alias)
109
- return cmd
110
-
111
- f = None
112
- if args and callable(args[0]):
113
- (f,) = args
114
- if f is not None:
115
- return aliased_decorator(f)
116
- return aliased_decorator
117
-
118
- def group(self, aliases=None, *args,
119
- **kwargs) -> t.Callable[[t.Callable[..., t.Any]], click.Group]:
120
- cmd_decorator = super().group(*args, **kwargs)
121
- if aliases is None:
122
- aliases = []
123
-
124
- def aliased_decorator(f):
125
- cmd = cmd_decorator(f)
126
- if cmd.name:
127
- self.add_alias(cmd, cmd.name)
128
- for alias in aliases:
129
- self.add_alias(cmd, alias)
130
- return cmd
131
-
132
- f = None
133
- if args and callable(args[0]):
134
- (f,) = args
135
- if f is not None:
136
- return aliased_decorator(f)
137
- return aliased_decorator
138
-
139
- def get_command(self, ctx: click.Context, cmd_name: str) -> t.Optional[click.Command]:
140
- rv = click.Group.get_command(self, ctx, cmd_name)
141
- if rv is not None:
142
- return rv
143
- return self.alias_map.get(cmd_name)
144
-
145
- def format_commands(self, ctx, formatter):
146
- sub_commands = self.list_commands(ctx)
147
-
148
- rows = []
149
- for sub_command in sub_commands:
150
- cmd = self.get_command(ctx, sub_command)
151
- if cmd is None or getattr(cmd, 'hidden', False):
152
- continue
153
- if cmd in self.command_to_aliases:
154
- aliases = ', '.join(self.command_to_aliases[cmd])
155
- sub_command = f'{sub_command} ({aliases})'
156
- cmd_help = cmd.help
157
- rows.append((sub_command, cmd_help))
158
-
159
- if rows:
160
- with formatter.section("Commands"):
161
- formatter.write_dl(rows)
83
+ def __init__(
84
+ self,
85
+ name: t.Optional[str] = None,
86
+ commands: t.Optional[
87
+ t.Union[t.MutableMapping[str, click.Command], t.Sequence[click.Command]]
88
+ ] = None,
89
+ **attrs: t.Any,
90
+ ) -> None:
91
+ super().__init__(name, commands, **attrs)
92
+ self.alias_map = {}
93
+ self.command_to_aliases = defaultdict(list)
94
+
95
+ def add_alias(self, cmd: click.Command, alias: str) -> None:
96
+ self.alias_map[alias] = cmd
97
+ if alias != cmd.name:
98
+ self.command_to_aliases[cmd].append(alias)
99
+
100
+ def command(
101
+ self, aliases=None, *args, **kwargs
102
+ ) -> t.Callable[[t.Callable[..., t.Any]], click.Command]:
103
+ cmd_decorator = super().command(*args, **kwargs)
104
+ if aliases is None:
105
+ aliases = []
106
+
107
+ def aliased_decorator(f):
108
+ cmd = cmd_decorator(f)
109
+ if cmd.name:
110
+ self.add_alias(cmd, cmd.name)
111
+ for alias in aliases:
112
+ self.add_alias(cmd, alias)
113
+ return cmd
114
+
115
+ f = None
116
+ if args and callable(args[0]):
117
+ (f,) = args
118
+ if f is not None:
119
+ return aliased_decorator(f)
120
+ return aliased_decorator
121
+
122
+ def group(
123
+ self, aliases=None, *args, **kwargs
124
+ ) -> t.Callable[[t.Callable[..., t.Any]], click.Group]:
125
+ cmd_decorator = super().group(*args, **kwargs)
126
+ if aliases is None:
127
+ aliases = []
128
+
129
+ def aliased_decorator(f):
130
+ cmd = cmd_decorator(f)
131
+ if cmd.name:
132
+ self.add_alias(cmd, cmd.name)
133
+ for alias in aliases:
134
+ self.add_alias(cmd, alias)
135
+ return cmd
136
+
137
+ f = None
138
+ if args and callable(args[0]):
139
+ (f,) = args
140
+ if f is not None:
141
+ return aliased_decorator(f)
142
+ return aliased_decorator
143
+
144
+ def get_command(self, ctx: click.Context, cmd_name: str) -> t.Optional[click.Command]:
145
+ rv = click.Group.get_command(self, ctx, cmd_name)
146
+ if rv is not None:
147
+ return rv
148
+ return self.alias_map.get(cmd_name)
149
+
150
+ def format_commands(self, ctx, formatter):
151
+ sub_commands = self.list_commands(ctx)
152
+
153
+ rows = []
154
+ for sub_command in sub_commands:
155
+ cmd = self.get_command(ctx, sub_command)
156
+ if cmd is None or getattr(cmd, 'hidden', False):
157
+ continue
158
+ if cmd in self.command_to_aliases:
159
+ aliases = ', '.join(self.command_to_aliases[cmd])
160
+ sub_command = f'{sub_command} ({aliases})'
161
+ cmd_help = cmd.help
162
+ rows.append((sub_command, cmd_help))
163
+
164
+ if rows:
165
+ with formatter.section("Commands"):
166
+ formatter.write_dl(rows)
162
167
 
163
168
 
164
169
  def validate_context(ctx):
165
- from clarifai.utils.logging import logger
166
- if ctx.obj == {}:
167
- logger.error("CLI config file missing. Run `clarifai login` to set up the CLI config.")
168
- sys.exit(1)
170
+ from clarifai.utils.logging import logger
171
+
172
+ if ctx.obj == {}:
173
+ logger.error("CLI config file missing. Run `clarifai login` to set up the CLI config.")
174
+ sys.exit(1)
clarifai/utils/config.py CHANGED
@@ -8,98 +8,138 @@ from clarifai.utils.constants import DEFAULT_CONFIG
8
8
 
9
9
 
10
10
  class Context(OrderedDict):
11
- """
11
+ """
12
12
  A context which has a name and a set of key-values as a dict under env.
13
13
 
14
14
  You can access the keys directly.
15
15
  """
16
16
 
17
- def __init__(self, name, **kwargs):
18
- self['name'] = name
19
- # when loading from config we may have the env: section in yaml already so we get it here.
20
- if 'env' in kwargs:
21
- self['env'] = kwargs['env']
22
- else: # when consructing as Context(name, key=value) we set it here.
23
- self['env'] = kwargs
24
-
25
- def __getattr__(self, key):
26
- try:
27
- if key == 'name':
28
- return self[key]
29
- if key == 'env':
30
- raise AttributeError("Don't access .env directly")
31
-
32
- # Allow accessing CLARIFAI_PAT type env var names from config as .pat
33
- envvar_name = 'CLARIFAI_' + key.upper()
34
- env = self['env']
35
- if envvar_name in env:
36
- value = env[envvar_name]
37
- if value == "ENVVAR":
38
- return os.environ[envvar_name]
39
- else:
40
- value = env[key]
41
-
42
- if isinstance(value, dict):
43
- return Context(value)
44
-
45
- return value
46
- except KeyError as e:
47
- raise AttributeError(f"'{type(self).__name__}' object has no attribute '{key}'") from e
48
-
49
- def __setattr__(self, key, value):
50
- if key == "name":
51
- self['name'] = value
52
- else:
53
- self['env'][key] = value
54
-
55
- def __delattr__(self, key):
56
- try:
57
- del self['env'][key]
58
- except KeyError as e:
59
- raise AttributeError(f"'{type(self).__name__}' object has no attribute '{key}'") from e
60
-
61
- def to_serializable_dict(self):
62
- return dict(self['env'])
17
+ def __init__(self, name, **kwargs):
18
+ self['name'] = name
19
+ # when loading from config we may have the env: section in yaml already so we get it here.
20
+ if 'env' in kwargs:
21
+ self['env'] = kwargs['env']
22
+ else: # when consructing as Context(name, key=value) we set it here.
23
+ self['env'] = kwargs
24
+
25
+ def __getattr__(self, key):
26
+ try:
27
+ if key == 'name':
28
+ return self[key]
29
+ if key == 'env':
30
+ raise AttributeError("Don't access .env directly")
31
+
32
+ # Allow accessing CLARIFAI_PAT type env var names from config as .pat
33
+ envvar_name = 'CLARIFAI_' + key.upper()
34
+ env = self['env']
35
+ if envvar_name in env:
36
+ value = env[envvar_name]
37
+ if value == "ENVVAR":
38
+ if envvar_name not in os.environ:
39
+ raise AttributeError(
40
+ f"Environment variable '{envvar_name}' not set. Attempting to load it for config '{self['name']}'. Please set it in your terminal."
41
+ )
42
+ return os.environ[envvar_name]
43
+ else:
44
+ value = env[key]
45
+
46
+ if isinstance(value, dict):
47
+ return Context(value)
48
+
49
+ return value
50
+ except KeyError as e:
51
+ raise AttributeError(f"'{type(self).__name__}' object has no attribute '{key}'") from e
52
+
53
+ def __hasattr__(self, key):
54
+ if key == "name":
55
+ return True
56
+ else:
57
+ envvar_name = 'CLARIFAI_' + key.upper()
58
+ return envvar_name in self['env'] or key in self['env']
59
+
60
+ def __setattr__(self, key, value):
61
+ if key == "name":
62
+ self['name'] = value
63
+ else:
64
+ self['env'][key] = value
65
+
66
+ def __delattr__(self, key):
67
+ try:
68
+ del self['env'][key]
69
+ except KeyError as e:
70
+ raise AttributeError(f"'{type(self).__name__}' object has no attribute '{key}'") from e
71
+
72
+ def to_column_names(self):
73
+ """used for displaying on terminal."""
74
+ keys = []
75
+ for k in self['env'].keys():
76
+ if k.startswith("CLARIFAI_"):
77
+ keys.append(k.replace("CLARIFAI_", "", 1))
78
+ return keys
79
+
80
+ def to_stripped_lowercase(self):
81
+ dict(self['env'])
82
+
83
+ def to_serializable_dict(self):
84
+ return dict(self['env'])
85
+
86
+ def set_to_env(self):
87
+ """sets the context env vars to the current os.environ
88
+
89
+ Example:
90
+ # This is helpful in scripts so you can do
91
+
92
+ from clarifai.utils.config import Config
93
+
94
+ Config.from_yaml().current.set_to_env()
95
+
96
+ """
97
+ for k, v in self['env'].items():
98
+ if isinstance(v, dict):
99
+ continue
100
+ envvar_name = k.upper()
101
+ if not envvar_name.startswith('CLARIFAI_'):
102
+ envvar_name = 'CLARIFAI_' + envvar_name
103
+ os.environ[envvar_name] = str(v)
63
104
 
64
105
 
65
106
  @dataclass
66
- class Config():
67
- current_context: str
68
- filename: str
69
- contexts: OrderedDict[str, Context] = field(default_factory=OrderedDict)
70
-
71
- def __post_init__(self):
72
- for k, v in self.contexts.items():
73
- if 'name' not in v:
74
- v['name'] = k
75
- self.contexts = {k: Context(**v) for k, v in self.contexts.items()}
76
-
77
- @classmethod
78
- def from_yaml(cls, filename: str = DEFAULT_CONFIG):
79
- with open(filename, 'r') as f:
80
- cfg = yaml.safe_load(f)
81
- return cls(**cfg, filename=filename)
82
-
83
- def to_dict(self):
84
- return {
85
- 'current_context': self.current_context,
86
- 'contexts': {k: v.to_serializable_dict()
87
- for k, v in self.contexts.items()}
88
- }
89
-
90
- def to_yaml(self, filename: str = None):
91
- if filename is None:
92
- filename = self.filename
93
- dir = os.path.dirname(filename)
94
- if len(dir):
95
- os.makedirs(dir, exist_ok=True)
96
- _dict = self.to_dict()
97
- for k, v in _dict['contexts'].items():
98
- v.pop('name', None)
99
- with open(filename, 'w') as f:
100
- yaml.safe_dump(_dict, f)
101
-
102
- @property
103
- def current(self) -> Context:
104
- """ get the current Context """
105
- return self.contexts[self.current_context]
107
+ class Config:
108
+ current_context: str
109
+ filename: str
110
+ contexts: OrderedDict[str, Context] = field(default_factory=OrderedDict)
111
+
112
+ def __post_init__(self):
113
+ for k, v in self.contexts.items():
114
+ if 'name' not in v:
115
+ v['name'] = k
116
+ self.contexts = {k: Context(**v) for k, v in self.contexts.items()}
117
+
118
+ @classmethod
119
+ def from_yaml(cls, filename: str = DEFAULT_CONFIG):
120
+ with open(filename, 'r') as f:
121
+ cfg = yaml.safe_load(f)
122
+ return cls(**cfg, filename=filename)
123
+
124
+ def to_dict(self):
125
+ return {
126
+ 'current_context': self.current_context,
127
+ 'contexts': {k: v.to_serializable_dict() for k, v in self.contexts.items()},
128
+ }
129
+
130
+ def to_yaml(self, filename: str = None):
131
+ if filename is None:
132
+ filename = self.filename
133
+ dir = os.path.dirname(filename)
134
+ if len(dir):
135
+ os.makedirs(dir, exist_ok=True)
136
+ _dict = self.to_dict()
137
+ for k, v in _dict['contexts'].items():
138
+ v.pop('name', None)
139
+ with open(filename, 'w') as f:
140
+ yaml.safe_dump(_dict, f)
141
+
142
+ @property
143
+ def current(self) -> Context:
144
+ """get the current Context"""
145
+ return self.contexts[self.current_context]
@@ -5,3 +5,52 @@ CLARIFAI_SESSION_TOKEN_ENV_VAR = "CLARIFAI_SESSION_TOKEN"
5
5
  CLARIFAI_USER_ID_ENV_VAR = "CLARIFAI_USER_ID"
6
6
 
7
7
  DEFAULT_CONFIG = f'{os.environ["HOME"]}/.config/clarifai/config'
8
+
9
+ # Default clusters, etc. for local dev runner easy setup
10
+ DEFAULT_LOCAL_DEV_COMPUTE_CLUSTER_ID = "local-dev-compute-cluster"
11
+ DEFAULT_LOCAL_DEV_NODEPOOL_ID = "local-dev-nodepool"
12
+ DEFAULT_LOCAL_DEV_DEPLOYMENT_ID = "local-dev-deployment"
13
+ DEFAULT_LOCAL_DEV_MODEL_ID = "local-dev-model"
14
+ DEFAULT_LOCAL_DEV_APP_ID = "local-dev-runner-app"
15
+
16
+ # FIXME: should have any-to-any for these cases.
17
+ DEFAULT_LOCAL_DEV_MODEL_TYPE = "text-to-text"
18
+
19
+ DEFAULT_LOCAL_DEV_COMPUTE_CLUSTER_CONFIG = {
20
+ "compute_cluster": {
21
+ "id": DEFAULT_LOCAL_DEV_COMPUTE_CLUSTER_ID,
22
+ "description": "Default Local Dev Compute Cluster",
23
+ "cloud_provider": {
24
+ "id": "local",
25
+ },
26
+ "region": "na",
27
+ "managed_by": "user",
28
+ "cluster_type": "local-dev",
29
+ }
30
+ }
31
+
32
+ DEFAULT_LOCAL_DEV_NODEPOOL_CONFIG = {
33
+ "nodepool": {
34
+ "id": DEFAULT_LOCAL_DEV_NODEPOOL_ID,
35
+ "description": "Default Local Dev Nodepool",
36
+ "compute_cluster": {
37
+ "id": DEFAULT_LOCAL_DEV_COMPUTE_CLUSTER_ID,
38
+ "user_id": None, # This will be set when creating the compute cluster
39
+ },
40
+ "instance_types": [
41
+ {
42
+ "id": "local-cpu",
43
+ "compute_info": {
44
+ "cpu_limit": str(os.cpu_count()),
45
+ "cpu_memory": "16Gi", # made up as we don't schedule based on this for local dev.
46
+ "num_accelerators": 0, # TODO if we need accelerator detection for local dev.
47
+ },
48
+ }
49
+ ],
50
+ "node_capacity_type": {
51
+ "capacity_types": [1],
52
+ },
53
+ "min_instances": 1,
54
+ "max_instances": 1,
55
+ }
56
+ }