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
@@ -14,184 +14,218 @@ from clarifai.utils.logging import logger
14
14
 
15
15
 
16
16
  class ComputeCluster(Lister, BaseClient):
17
- """ComputeCluster is a class that provides access to Clarifai API endpoints related to Compute Cluster information."""
18
-
19
- def __init__(self,
20
- compute_cluster_id: str = None,
21
- user_id: str = None,
22
- base_url: str = "https://api.clarifai.com",
23
- pat: str = None,
24
- token: str = None,
25
- root_certificates_path: str = None,
26
- **kwargs):
27
- """Initializes an ComputeCluster object.
28
-
29
- Args:
30
- compute_cluster_id (str): The ComputeCluster ID for the ComputeCluster to interact with.
31
- user_id (str): The user ID of the user.
32
- base_url (str): Base API url. Default "https://api.clarifai.com"
33
- pat (str): A personal access token for authentication. Can be set as env var CLARIFAI_PAT
34
- token (str): A session token for authentication. Accepts either a session token or a pat. Can be set as env var CLARIFAI_SESSION_TOKEN
35
- root_certificates_path (str): Path to the SSL root certificates file, used to establish secure gRPC connections.
36
- **kwargs: Additional keyword arguments to be passed to the compute cluster.
37
- """
38
- self.kwargs = {**kwargs, 'id': compute_cluster_id, 'user_id': user_id}
39
- self.compute_cluster_info = resources_pb2.ComputeCluster(**self.kwargs)
40
- self.logger = logger
41
- BaseClient.__init__(
17
+ """ComputeCluster is a class that provides access to Clarifai API endpoints related to Compute Cluster information."""
18
+
19
+ def __init__(
20
+ self,
21
+ compute_cluster_id: str = None,
22
+ user_id: str = None,
23
+ base_url: str = "https://api.clarifai.com",
24
+ pat: str = None,
25
+ token: str = None,
26
+ root_certificates_path: str = None,
27
+ **kwargs,
28
+ ):
29
+ """Initializes an ComputeCluster object.
30
+
31
+ Args:
32
+ compute_cluster_id (str): The ComputeCluster ID for the ComputeCluster to interact with.
33
+ user_id (str): The user ID of the user.
34
+ base_url (str): Base API url. Default "https://api.clarifai.com"
35
+ pat (str): A personal access token for authentication. Can be set as env var CLARIFAI_PAT
36
+ token (str): A session token for authentication. Accepts either a session token or a pat. Can be set as env var CLARIFAI_SESSION_TOKEN
37
+ root_certificates_path (str): Path to the SSL root certificates file, used to establish secure gRPC connections.
38
+ **kwargs: Additional keyword arguments to be passed to the compute cluster.
39
+ """
40
+ self.kwargs = {**kwargs, 'id': compute_cluster_id, 'user_id': user_id}
41
+ self.compute_cluster_info = resources_pb2.ComputeCluster(**self.kwargs)
42
+ self.logger = logger
43
+ BaseClient.__init__(
44
+ self,
45
+ user_id=self.user_id,
46
+ base=base_url,
47
+ pat=pat,
48
+ token=token,
49
+ root_certificates_path=root_certificates_path,
50
+ )
51
+ Lister.__init__(self)
52
+
53
+ def list_nodepools(
54
+ self, page_no: int = None, per_page: int = None
55
+ ) -> Generator[Nodepool, None, None]:
56
+ """Lists all the available nodepools of the compute cluster.
57
+
58
+ Args:
59
+ compute_cluster_id (str): The compute cluster ID to list the nodepools.
60
+ page_no (int): The page number to list.
61
+ per_page (int): The number of items per page.
62
+
63
+ Yields:
64
+ Nodepool: Nodepool objects for the nodepools in the compute cluster.
65
+
66
+ Example:
67
+ >>> from clarifai.client.compute_cluster import ComputeCluster
68
+ >>> compute_cluster = ComputeCluster(compute_cluster_id="compute_cluster_id", user_id="user_id")
69
+ >>> all_nodepools = list(compute_cluster.list_nodepools())
70
+
71
+ Note:
72
+ Defaults to 16 per page if page_no is specified and per_page is not specified.
73
+ If both page_no and per_page are None, then lists all the resources.
74
+ """
75
+ request_data = dict(user_app_id=self.user_app_id, compute_cluster_id=self.id)
76
+ all_nodepools_info = self.list_pages_generator(
77
+ self.STUB.ListNodepools,
78
+ service_pb2.ListNodepoolsRequest,
79
+ request_data,
80
+ per_page=per_page,
81
+ page_no=page_no,
82
+ )
83
+
84
+ for nodepool_info in all_nodepools_info:
85
+ yield Nodepool.from_auth_helper(auth=self.auth_helper, **nodepool_info)
86
+
87
+ def _process_nodepool_config(self, nodepool_config: str) -> Dict[str, Any]:
88
+ assert "nodepool" in nodepool_config, "nodepool info not found in the config file"
89
+ nodepool = nodepool_config['nodepool']
90
+ assert "instance_types" in nodepool, "instance_types not found in the config file"
91
+ assert "node_capacity_type" in nodepool, "node_capacity_type not found in the config file"
92
+ assert "min_instances" in nodepool, "min_instances not found in the config file"
93
+ assert "max_instances" in nodepool, "max_instances not found in the config file"
94
+ nodepool['compute_cluster'] = resources_pb2.ComputeCluster(
95
+ id=self.id, user_id=self.user_id
96
+ )
97
+ nodepool['node_capacity_type'] = resources_pb2.NodeCapacityType(
98
+ capacity_types=[
99
+ capacity_type for capacity_type in nodepool['node_capacity_type']['capacity_types']
100
+ ]
101
+ )
102
+ instance_types = []
103
+ for instance_type in nodepool['instance_types']:
104
+ if 'compute_info' in instance_type:
105
+ instance_type['compute_info'] = resources_pb2.ComputeInfo(
106
+ **instance_type['compute_info']
107
+ )
108
+ instance_types.append(resources_pb2.InstanceType(**instance_type))
109
+ nodepool['instance_types'] = instance_types
110
+ if "visibility" in nodepool:
111
+ nodepool["visibility"] = resources_pb2.Visibility(**nodepool["visibility"])
112
+ return nodepool
113
+
114
+ def create_nodepool(
42
115
  self,
43
- user_id=self.user_id,
44
- base=base_url,
45
- pat=pat,
46
- token=token,
47
- root_certificates_path=root_certificates_path)
48
- Lister.__init__(self)
49
-
50
- def list_nodepools(self, page_no: int = None,
51
- per_page: int = None) -> Generator[Nodepool, None, None]:
52
- """Lists all the available nodepools of the compute cluster.
53
-
54
- Args:
55
- compute_cluster_id (str): The compute cluster ID to list the nodepools.
56
- page_no (int): The page number to list.
57
- per_page (int): The number of items per page.
58
-
59
- Yields:
60
- Nodepool: Nodepool objects for the nodepools in the compute cluster.
61
-
62
- Example:
63
- >>> from clarifai.client.compute_cluster import ComputeCluster
64
- >>> compute_cluster = ComputeCluster(compute_cluster_id="compute_cluster_id", user_id="user_id")
65
- >>> all_nodepools = list(compute_cluster.list_nodepools())
66
-
67
- Note:
68
- Defaults to 16 per page if page_no is specified and per_page is not specified.
69
- If both page_no and per_page are None, then lists all the resources.
70
- """
71
- request_data = dict(user_app_id=self.user_app_id, compute_cluster_id=self.id)
72
- all_nodepools_info = self.list_pages_generator(
73
- self.STUB.ListNodepools,
74
- service_pb2.ListNodepoolsRequest,
75
- request_data,
76
- per_page=per_page,
77
- page_no=page_no)
78
-
79
- for nodepool_info in all_nodepools_info:
80
- yield Nodepool.from_auth_helper(auth=self.auth_helper, **nodepool_info)
81
-
82
- def _process_nodepool_config(self, config_filepath: str) -> Dict[str, Any]:
83
- with open(config_filepath, "r") as file:
84
- nodepool_config = yaml.safe_load(file)
85
-
86
- assert "nodepool" in nodepool_config, "nodepool info not found in the config file"
87
- nodepool = nodepool_config['nodepool']
88
- assert "instance_types" in nodepool, "region not found in the config file"
89
- assert "node_capacity_type" in nodepool, "managed_by not found in the config file"
90
- assert "max_instances" in nodepool, "cluster_type not found in the config file"
91
- nodepool['compute_cluster'] = resources_pb2.ComputeCluster(id=self.id, user_id=self.user_id)
92
- nodepool['node_capacity_type'] = resources_pb2.NodeCapacityType(capacity_types=[
93
- capacity_type for capacity_type in nodepool['node_capacity_type']['capacity_types']
94
- ])
95
- instance_types = []
96
- for instance_type in nodepool['instance_types']:
97
- if 'compute_info' in instance_type:
98
- instance_type['compute_info'] = resources_pb2.ComputeInfo(**instance_type['compute_info'])
99
- instance_types.append(resources_pb2.InstanceType(**instance_type))
100
- nodepool['instance_types'] = instance_types
101
- if "visibility" in nodepool:
102
- nodepool["visibility"] = resources_pb2.Visibility(**nodepool["visibility"])
103
- return nodepool
104
-
105
- def create_nodepool(self, config_filepath: str, nodepool_id: str = None) -> Nodepool:
106
- """Creates a nodepool for the compute cluster.
107
-
108
- Args:
109
- config_filepath (str): The path to the nodepool config file.
110
- nodepool_id (str): New nodepool ID for the nodepool to create.
111
-
112
- Returns:
113
- Nodepool: A Nodepool object for the specified nodepool ID.
114
-
115
- Example:
116
- >>> from clarifai.client.compute_cluster import ComputeCluster
117
- >>> compute_cluster = ComputeCluster(compute_cluster_id="compute_cluster_id", user_id="user_id")
118
- >>> nodepool = compute_cluster.create_nodepool(config_filepath="config.yml")
119
- """
120
- if not os.path.exists(config_filepath):
121
- raise UserError(f"Nodepool config file not found at {config_filepath}")
122
-
123
- nodepool_config = self._process_nodepool_config(config_filepath)
124
-
125
- if 'id' in nodepool_config:
126
- if nodepool_id is None:
127
- nodepool_id = nodepool_config['id']
128
- nodepool_config.pop('id')
129
-
130
- request = service_pb2.PostNodepoolsRequest(
131
- user_app_id=self.user_app_id,
132
- compute_cluster_id=self.id,
133
- nodepools=[resources_pb2.Nodepool(id=nodepool_id, **nodepool_config)])
134
- response = self._grpc_request(self.STUB.PostNodepools, request)
135
- if response.status.code != status_code_pb2.SUCCESS:
136
- raise Exception(response.status)
137
- self.logger.info("\nNodepool created\n%s", response.status)
138
-
139
- return Nodepool.from_auth_helper(self.auth_helper, nodepool_id=nodepool_id)
140
-
141
- def nodepool(self, nodepool_id: str) -> Nodepool:
142
- """Returns a Nodepool object for the existing nodepool ID.
143
-
144
- Args:
145
- nodepool_id (str): The nodepool ID for the nodepool to interact with.
146
-
147
- Returns:
148
- Nodepool: A Nodepool object for the existing nodepool ID.
149
-
150
- Example:
151
- >>> from clarifai.client.compute_cluster import ComputeCluster
152
- >>> compute_cluster = ComputeCluster(compute_cluster_id="compute_cluster_id", user_id="user_id")
153
- >>> nodepool = compute_cluster.nodepool(nodepool_id="nodepool_id")
154
- """
155
- request = service_pb2.GetNodepoolRequest(
156
- user_app_id=self.user_app_id, compute_cluster_id=self.id, nodepool_id=nodepool_id)
157
- response = self._grpc_request(self.STUB.GetNodepool, request)
158
-
159
- if response.status.code != status_code_pb2.SUCCESS:
160
- raise Exception(response.status)
161
- dict_response = MessageToDict(response, preserving_proto_field_name=True)
162
- kwargs = self.process_response_keys(dict_response[list(dict_response.keys())[1]],
163
- list(dict_response.keys())[1])
164
-
165
- return Nodepool.from_auth_helper(auth=self.auth_helper, **kwargs)
166
-
167
- def delete_nodepools(self, nodepool_ids: List[str]) -> None:
168
- """Deletes list of nodepools for the compute cluster.
169
-
170
- Args:
171
- nodepool_ids (List[str]): The nodepool IDs of the compute cluster to delete.
172
-
173
- Example:
174
- >>> from clarifai.client.compute_cluster import ComputeCluster
175
- >>> compute_cluster = ComputeCluster(compute_cluster_id="compute_cluster_id", user_id="user_id")
176
- >>> compute_cluster.delete_nodepools(nodepool_ids=["nodepool_id1", "nodepool_id2"])
177
- """
178
- assert isinstance(nodepool_ids, list), "nodepool_ids param should be a list"
179
-
180
- request = service_pb2.DeleteNodepoolsRequest(
181
- user_app_id=self.user_app_id, compute_cluster_id=self.id, ids=nodepool_ids)
182
- response = self._grpc_request(self.STUB.DeleteNodepools, request)
183
-
184
- if response.status.code != status_code_pb2.SUCCESS:
185
- raise Exception(response.status)
186
- self.logger.info("\nNodepools Deleted\n%s", response.status)
187
-
188
- def __getattr__(self, name):
189
- return getattr(self.compute_cluster_info, name)
190
-
191
- def __str__(self):
192
- init_params = [param for param in self.kwargs.keys()]
193
- attribute_strings = [
194
- f"{param}={getattr(self.compute_cluster_info, param)}" for param in init_params
195
- if hasattr(self.compute_cluster_info, param)
196
- ]
197
- return f"Clarifai Compute Cluster Details: \n{', '.join(attribute_strings)}\n"
116
+ config_filepath: str = None,
117
+ nodepool_id: str = None,
118
+ nodepool_config: Dict[str, Any] = None,
119
+ ) -> Nodepool:
120
+ """Creates a nodepool for the compute cluster.
121
+
122
+ Args:
123
+ config_filepath (str): The path to the nodepool config file.
124
+ nodepool_id (str): New nodepool ID for the nodepool to create.
125
+ nodepool_config (Dict[str, Any]) = nodepool_config or {}
126
+
127
+ Returns:
128
+ Nodepool: A Nodepool object for the specified nodepool ID.
129
+
130
+ Example:
131
+ >>> from clarifai.client.compute_cluster import ComputeCluster
132
+ >>> compute_cluster = ComputeCluster(compute_cluster_id="compute_cluster_id", user_id="user_id")
133
+ >>> nodepool = compute_cluster.create_nodepool(config_filepath="config.yml")
134
+ """
135
+
136
+ if config_filepath is not None:
137
+ assert nodepool_config is None, (
138
+ "nodepool_config has to be None if config_filepath is provided"
139
+ )
140
+
141
+ if not os.path.exists(config_filepath):
142
+ raise UserError(f"Nodepool config file not found at {config_filepath}")
143
+ with open(config_filepath, "r") as file:
144
+ nodepool_config = yaml.safe_load(file)
145
+ elif nodepool_config is not None:
146
+ assert isinstance(nodepool_config, dict), (
147
+ "nodepool_config should be a dictionary if provided."
148
+ )
149
+ else:
150
+ raise AssertionError("Either config_filepath or nodepool_config must be provided.")
151
+
152
+ nodepool_config = self._process_nodepool_config(nodepool_config)
153
+
154
+ if 'id' in nodepool_config:
155
+ if nodepool_id is None:
156
+ nodepool_id = nodepool_config['id']
157
+ nodepool_config.pop('id')
158
+
159
+ request = service_pb2.PostNodepoolsRequest(
160
+ user_app_id=self.user_app_id,
161
+ compute_cluster_id=self.id,
162
+ nodepools=[resources_pb2.Nodepool(id=nodepool_id, **nodepool_config)],
163
+ )
164
+ response = self._grpc_request(self.STUB.PostNodepools, request)
165
+ if response.status.code != status_code_pb2.SUCCESS:
166
+ raise Exception(response.status)
167
+ self.logger.info("\nNodepool created\n%s", response.status)
168
+
169
+ dict_response = MessageToDict(response.nodepools[0], preserving_proto_field_name=True)
170
+ kwargs = self.process_response_keys(dict_response, 'nodepool')
171
+ return Nodepool.from_auth_helper(auth=self.auth_helper, **kwargs)
172
+
173
+ def nodepool(self, nodepool_id: str) -> Nodepool:
174
+ """Returns a Nodepool object for the existing nodepool ID.
175
+
176
+ Args:
177
+ nodepool_id (str): The nodepool ID for the nodepool to interact with.
178
+
179
+ Returns:
180
+ Nodepool: A Nodepool object for the existing nodepool ID.
181
+
182
+ Example:
183
+ >>> from clarifai.client.compute_cluster import ComputeCluster
184
+ >>> compute_cluster = ComputeCluster(compute_cluster_id="compute_cluster_id", user_id="user_id")
185
+ >>> nodepool = compute_cluster.nodepool(nodepool_id="nodepool_id")
186
+ """
187
+ request = service_pb2.GetNodepoolRequest(
188
+ user_app_id=self.user_app_id, compute_cluster_id=self.id, nodepool_id=nodepool_id
189
+ )
190
+ response = self._grpc_request(self.STUB.GetNodepool, request)
191
+
192
+ if response.status.code != status_code_pb2.SUCCESS:
193
+ raise Exception(response.status)
194
+ dict_response = MessageToDict(response, preserving_proto_field_name=True)
195
+
196
+ kwargs = self.process_response_keys(dict_response['nodepool'], 'nodepool')
197
+ return Nodepool.from_auth_helper(auth=self.auth_helper, **kwargs)
198
+
199
+ def delete_nodepools(self, nodepool_ids: List[str]) -> None:
200
+ """Deletes list of nodepools for the compute cluster.
201
+
202
+ Args:
203
+ nodepool_ids (List[str]): The nodepool IDs of the compute cluster to delete.
204
+
205
+ Example:
206
+ >>> from clarifai.client.compute_cluster import ComputeCluster
207
+ >>> compute_cluster = ComputeCluster(compute_cluster_id="compute_cluster_id", user_id="user_id")
208
+ >>> compute_cluster.delete_nodepools(nodepool_ids=["nodepool_id1", "nodepool_id2"])
209
+ """
210
+ assert isinstance(nodepool_ids, list), "nodepool_ids param should be a list"
211
+
212
+ request = service_pb2.DeleteNodepoolsRequest(
213
+ user_app_id=self.user_app_id, compute_cluster_id=self.id, ids=nodepool_ids
214
+ )
215
+ response = self._grpc_request(self.STUB.DeleteNodepools, request)
216
+
217
+ if response.status.code != status_code_pb2.SUCCESS:
218
+ raise Exception(response.status)
219
+ self.logger.info("\nNodepools Deleted\n%s", response.status)
220
+
221
+ def __getattr__(self, name):
222
+ return getattr(self.compute_cluster_info, name)
223
+
224
+ def __str__(self):
225
+ init_params = [param for param in self.kwargs.keys()]
226
+ attribute_strings = [
227
+ f"{param}={getattr(self.compute_cluster_info, param)}"
228
+ for param in init_params
229
+ if hasattr(self.compute_cluster_info, param)
230
+ ]
231
+ return f"Clarifai Compute Cluster Details: \n{', '.join(attribute_strings)}\n"