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
@@ -9,222 +9,367 @@ from google.protobuf.json_format import MessageToDict
9
9
  from clarifai.client.base import BaseClient
10
10
  from clarifai.client.deployment import Deployment
11
11
  from clarifai.client.lister import Lister
12
+ from clarifai.client.runner import Runner
12
13
  from clarifai.errors import UserError
13
14
  from clarifai.utils.logging import logger
14
15
 
15
16
 
16
17
  class Nodepool(Lister, BaseClient):
17
- """Nodepool is a class that provides access to Clarifai API endpoints related to Nodepool information."""
18
-
19
- def __init__(self,
20
- nodepool_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 a Nodepool object.
28
-
29
- Args:
30
- nodepool_id (str): The Nodepool ID for the Nodepool 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 nodepool.
37
- """
38
- self.kwargs = {**kwargs, 'id': nodepool_id}
39
- self.nodepool_info = resources_pb2.Nodepool(**self.kwargs)
40
- self.logger = logger
41
- BaseClient.__init__(
18
+ """Nodepool is a class that provides access to Clarifai API endpoints related to Nodepool information."""
19
+
20
+ def __init__(
21
+ self,
22
+ nodepool_id: str = None,
23
+ user_id: str = None,
24
+ base_url: str = "https://api.clarifai.com",
25
+ pat: str = None,
26
+ token: str = None,
27
+ root_certificates_path: str = None,
28
+ **kwargs,
29
+ ):
30
+ """Initializes a Nodepool object.
31
+
32
+ Args:
33
+ nodepool_id (str): The Nodepool ID for the Nodepool to interact with.
34
+ user_id (str): The user ID of the user.
35
+ base_url (str): Base API url. Default "https://api.clarifai.com"
36
+ pat (str): A personal access token for authentication. Can be set as env var CLARIFAI_PAT
37
+ token (str): A session token for authentication. Accepts either a session token or a pat. Can be set as env var CLARIFAI_SESSION_TOKEN
38
+ root_certificates_path (str): Path to the SSL root certificates file, used to establish secure gRPC connections.
39
+ **kwargs: Additional keyword arguments to be passed to the nodepool.
40
+ """
41
+ self.kwargs = {**kwargs, 'id': nodepool_id}
42
+ self.nodepool_info = resources_pb2.Nodepool(**self.kwargs)
43
+ self.logger = logger
44
+ BaseClient.__init__(
45
+ self,
46
+ user_id=user_id,
47
+ base=base_url,
48
+ pat=pat,
49
+ token=token,
50
+ root_certificates_path=root_certificates_path,
51
+ )
52
+ Lister.__init__(self)
53
+
54
+ def list_deployments(
55
+ self, filter_by: Dict[str, Any] = {}, page_no: int = None, per_page: int = None
56
+ ) -> Generator[Deployment, None, None]:
57
+ """Lists all the available deployments of compute cluster.
58
+
59
+ Args:
60
+ filter_by (Dict[str, Any]): The filter to apply to the list of deployments.
61
+ page_no (int): The page number to list.
62
+ per_page (int): The number of items per page.
63
+
64
+ Yields:
65
+ Deployment: Deployment objects for the nodepools in the compute cluster.
66
+
67
+ Example:
68
+ >>> from clarifai.client.nodepool import Nodepool
69
+ >>> nodepool = Nodepool(nodepool_id="nodepool_id", user_id="user_id")
70
+ >>> all_deployments = list(nodepool.list_deployments())
71
+
72
+ Note:
73
+ Defaults to 16 per page if page_no is specified and per_page is not specified.
74
+ If both page_no and per_page are None, then lists all the resources.
75
+ """
76
+ request_data = dict(user_app_id=self.user_app_id, nodepool_id=self.id, **filter_by)
77
+ all_deployments_info = self.list_pages_generator(
78
+ self.STUB.ListDeployments,
79
+ service_pb2.ListDeploymentsRequest,
80
+ request_data,
81
+ per_page=per_page,
82
+ page_no=page_no,
83
+ )
84
+
85
+ for deployment_info in all_deployments_info:
86
+ yield Deployment.from_auth_helper(auth=self.auth_helper, **deployment_info)
87
+
88
+ def _process_deployment_config(self, deployment_config: Dict[str, Any]) -> Dict[str, Any]:
89
+ assert "deployment" in deployment_config, "deployment info not found in the config file"
90
+ deployment = deployment_config['deployment']
91
+ assert ("worker" in deployment) and (
92
+ ("model" in deployment["worker"]) or ("workflow" in deployment["worker"])
93
+ ), "worker info not found in the config file"
94
+ assert "scheduling_choice" in deployment, "scheduling_choice not found in the config file"
95
+ assert "nodepools" in deployment, "nodepools not found in the config file"
96
+ deployment['user_id'] = self.user_app_id.user_id
97
+ if "autoscale_config" in deployment:
98
+ deployment['autoscale_config'] = resources_pb2.AutoscaleConfig(
99
+ **deployment['autoscale_config']
100
+ )
101
+ deployment['nodepools'] = [
102
+ resources_pb2.Nodepool(
103
+ id=nodepool['id'],
104
+ compute_cluster=resources_pb2.ComputeCluster(
105
+ id=nodepool['compute_cluster']['id'], user_id=self.user_app_id.user_id
106
+ ),
107
+ )
108
+ for nodepool in deployment['nodepools']
109
+ ]
110
+ if 'user' in deployment['worker']:
111
+ deployment['worker']['user'] = resources_pb2.User(**deployment['worker']['user'])
112
+ elif 'model' in deployment['worker']:
113
+ deployment['worker']['model'] = resources_pb2.Model(**deployment['worker']['model'])
114
+ elif 'workflow' in deployment['worker']:
115
+ deployment['worker']['workflow'] = resources_pb2.Workflow(
116
+ **deployment['worker']['workflow']
117
+ )
118
+ deployment['worker'] = resources_pb2.Worker(**deployment['worker'])
119
+ if "visibility" in deployment:
120
+ deployment["visibility"] = resources_pb2.Visibility(**deployment["visibility"])
121
+ return deployment
122
+
123
+ @staticmethod
124
+ def get_runner_selector(
125
+ user_id: str, compute_cluster_id: str, nodepool_id: str
126
+ ) -> resources_pb2.RunnerSelector:
127
+ """Returns a RunnerSelector object for the specified compute cluster and nodepool.
128
+
129
+ Args:
130
+ user_id (str): The user ID of the user.
131
+ compute_cluster_id (str): The compute cluster ID for the compute cluster.
132
+ nodepool_id (str): The nodepool ID for the nodepool.
133
+
134
+ Returns:
135
+ resources_pb2.RunnerSelector: A RunnerSelector object for the specified compute cluster and nodepool.
136
+
137
+ Example:
138
+ >>> from clarifai.client.nodepool import Nodepool
139
+ >>> nodepool = Nodepool(nodepool_id="nodepool_id", user_id="user_id")
140
+ >>> runner_selector = Nodepool.get_runner_selector(user_id="user_id", compute_cluster_id="compute_cluster_id", nodepool_id="nodepool_id")
141
+ """
142
+ compute_cluster = resources_pb2.ComputeCluster(id=compute_cluster_id, user_id=user_id)
143
+ nodepool = resources_pb2.Nodepool(id=nodepool_id, compute_cluster=compute_cluster)
144
+ return resources_pb2.RunnerSelector(nodepool=nodepool)
145
+
146
+ def create_deployment(
42
147
  self,
43
- user_id=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_deployments(self,
51
- filter_by: Dict[str, Any] = {},
52
- page_no: int = None,
53
- per_page: int = None) -> Generator[Deployment, None, None]:
54
- """Lists all the available deployments of compute cluster.
55
-
56
- Args:
57
- filter_by (Dict[str, Any]): The filter to apply to the list of deployments.
58
- page_no (int): The page number to list.
59
- per_page (int): The number of items per page.
60
-
61
- Yields:
62
- Deployment: Deployment objects for the nodepools in the compute cluster.
63
-
64
- Example:
65
- >>> from clarifai.client.nodepool import Nodepool
66
- >>> nodepool = Nodepool(nodepool_id="nodepool_id", user_id="user_id")
67
- >>> all_deployments = list(nodepool.list_deployments())
68
-
69
- Note:
70
- Defaults to 16 per page if page_no is specified and per_page is not specified.
71
- If both page_no and per_page are None, then lists all the resources.
72
- """
73
- request_data = dict(user_app_id=self.user_app_id, nodepool_id=self.id, **filter_by)
74
- all_deployments_info = self.list_pages_generator(
75
- self.STUB.ListDeployments,
76
- service_pb2.ListDeploymentsRequest,
77
- request_data,
78
- per_page=per_page,
79
- page_no=page_no)
80
-
81
- for deployment_info in all_deployments_info:
82
- yield Deployment.from_auth_helper(auth=self.auth_helper, **deployment_info)
83
-
84
- def _process_deployment_config(self, config_filepath: str) -> Dict[str, Any]:
85
- with open(config_filepath, "r") as file:
86
- deployment_config = yaml.safe_load(file)
87
-
88
- assert "deployment" in deployment_config, "deployment info not found in the config file"
89
- deployment = deployment_config['deployment']
90
- assert "autoscale_config" in deployment, "autoscale_config not found in the config file"
91
- assert ("worker" in deployment) and (
92
- ("model" in deployment["worker"]) or
93
- ("workflow" in deployment["worker"])), "worker info not found in the config file"
94
- assert "scheduling_choice" in deployment, "scheduling_choice not found in the config file"
95
- assert "nodepools" in deployment, "nodepools not found in the config file"
96
- deployment['user_id'] = self.user_app_id.user_id
97
- deployment['autoscale_config'] = resources_pb2.AutoscaleConfig(
98
- **deployment['autoscale_config'])
99
- deployment['nodepools'] = [
100
- resources_pb2.Nodepool(
101
- id=nodepool['id'],
102
- compute_cluster=resources_pb2.ComputeCluster(
103
- id=nodepool['compute_cluster']['id'], user_id=self.user_app_id.user_id))
104
- for nodepool in deployment['nodepools']
105
- ]
106
- if 'user' in deployment['worker']:
107
- deployment['worker']['user'] = resources_pb2.User(**deployment['worker']['user'])
108
- elif 'model' in deployment['worker']:
109
- deployment['worker']['model'] = resources_pb2.Model(**deployment['worker']['model'])
110
- elif 'workflow' in deployment['worker']:
111
- deployment['worker']['workflow'] = resources_pb2.Workflow(**deployment['worker']['workflow'])
112
- deployment['worker'] = resources_pb2.Worker(**deployment['worker'])
113
- if "visibility" in deployment:
114
- deployment["visibility"] = resources_pb2.Visibility(**deployment["visibility"])
115
- return deployment
116
-
117
- @staticmethod
118
- def get_runner_selector(user_id: str, compute_cluster_id: str,
119
- nodepool_id: str) -> resources_pb2.RunnerSelector:
120
- """Returns a RunnerSelector object for the specified compute cluster and nodepool.
121
-
122
- Args:
123
- user_id (str): The user ID of the user.
124
- compute_cluster_id (str): The compute cluster ID for the compute cluster.
125
- nodepool_id (str): The nodepool ID for the nodepool.
126
-
127
- Returns:
128
- resources_pb2.RunnerSelector: A RunnerSelector object for the specified compute cluster and nodepool.
129
-
130
- Example:
131
- >>> from clarifai.client.nodepool import Nodepool
132
- >>> nodepool = Nodepool(nodepool_id="nodepool_id", user_id="user_id")
133
- >>> runner_selector = Nodepool.get_runner_selector(user_id="user_id", compute_cluster_id="compute_cluster_id", nodepool_id="nodepool_id")
134
- """
135
- compute_cluster = resources_pb2.ComputeCluster(id=compute_cluster_id, user_id=user_id)
136
- nodepool = resources_pb2.Nodepool(id=nodepool_id, compute_cluster=compute_cluster)
137
- return resources_pb2.RunnerSelector(nodepool=nodepool)
138
-
139
- def create_deployment(self, config_filepath: str, deployment_id: str = None) -> Deployment:
140
- """Creates a deployment for the nodepool.
141
-
142
- Args:
143
- config_filepath (str): The path to the deployment config file.
144
- deployment_id (str): New deployment ID for the deployment to create.
145
-
146
- Returns:
147
- Deployment: A Deployment object for the specified deployment ID.
148
-
149
- Example:
150
- >>> from clarifai.client.nodepool import Nodepool
151
- >>> nodepool = Nodepool(nodepool_id="nodepool_id", user_id="user_id")
152
- >>> deployment = nodepool.create_deployment(config_filepath="config.yml")
153
- """
154
- if not os.path.exists(config_filepath):
155
- raise UserError(f"Deployment config file not found at {config_filepath}")
156
-
157
- deployment_config = self._process_deployment_config(config_filepath)
158
-
159
- if 'id' in deployment_config:
160
- if deployment_id is None:
161
- deployment_id = deployment_config['id']
162
- deployment_config.pop('id')
163
-
164
- request = service_pb2.PostDeploymentsRequest(
165
- user_app_id=self.user_app_id,
166
- deployments=[resources_pb2.Deployment(id=deployment_id, **deployment_config)])
167
- response = self._grpc_request(self.STUB.PostDeployments, request)
168
- if response.status.code != status_code_pb2.SUCCESS:
169
- raise Exception(response.status)
170
- self.logger.info("\nDeployment created\n%s", response.status)
171
-
172
- return Deployment.from_auth_helper(self.auth_helper, deployment_id=deployment_id)
173
-
174
- def deployment(self, deployment_id: str) -> Deployment:
175
- """Returns a Deployment object for the existing deployment ID.
176
-
177
- Args:
178
- deployment_id (str): The deployment ID for the deployment to interact with.
179
-
180
- Returns:
181
- Deployment: A Deployment object for the existing deployment ID.
182
-
183
- Example:
184
- >>> from clarifai.client.nodepool import Nodepool
185
- >>> nodepool = Nodepool(nodepool_id="nodepool_id", user_id="user_id")
186
- >>> deployment = nodepool.deployment(deployment_id="deployment_id")
187
- """
188
- request = service_pb2.GetDeploymentRequest(
189
- user_app_id=self.user_app_id, deployment_id=deployment_id)
190
- response = self._grpc_request(self.STUB.GetDeployment, 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
- kwargs = self.process_response_keys(dict_response[list(dict_response.keys())[1]],
196
- list(dict_response.keys())[1])
197
-
198
- return Deployment.from_auth_helper(auth=self.auth_helper, **kwargs)
199
-
200
- def delete_deployments(self, deployment_ids: List[str]) -> None:
201
- """Deletes list of deployments for the nodepool.
202
-
203
- Args:
204
- deployment_ids (List[str]): The list of deployment IDs to delete.
205
-
206
- Example:
207
- >>> from clarifai.client.nodepool import Nodepool
208
- >>> nodepool = Nodepool(nodepool_id="nodepool_id", user_id="user_id")
209
- >>> nodepool.delete_deployments(deployment_ids=["deployment_id1", "deployment_id2"])
210
- """
211
- assert isinstance(deployment_ids, list), "deployment_ids param should be a list"
212
-
213
- request = service_pb2.DeleteDeploymentsRequest(
214
- user_app_id=self.user_app_id, ids=deployment_ids)
215
- response = self._grpc_request(self.STUB.DeleteDeployments, request)
216
-
217
- if response.status.code != status_code_pb2.SUCCESS:
218
- raise Exception(response.status)
219
- self.logger.info("\nDeployments Deleted\n%s", response.status)
220
-
221
- def __getattr__(self, name):
222
- return getattr(self.nodepool_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.nodepool_info, param)}" for param in init_params
228
- if hasattr(self.nodepool_info, param)
229
- ]
230
- return f"Nodepool Details: \n{', '.join(attribute_strings)}\n"
148
+ config_filepath: str = None,
149
+ deployment_id: str = None,
150
+ deployment_config: Dict[str, Any] = None,
151
+ ) -> Deployment:
152
+ """Creates a deployment for the nodepool.
153
+
154
+ Args:
155
+ config_filepath (str): The path to the deployment config file.
156
+ deployment_id (str): New deployment ID for the deployment to create.
157
+
158
+ Returns:
159
+ Deployment: A Deployment object for the specified deployment ID.
160
+
161
+ Example:
162
+ >>> from clarifai.client.nodepool import Nodepool
163
+ >>> nodepool = Nodepool(nodepool_id="nodepool_id", user_id="user_id")
164
+ >>> deployment = nodepool.create_deployment(config_filepath="config.yml")
165
+ """
166
+
167
+ if config_filepath is not None:
168
+ assert deployment_config is None, (
169
+ "deployment_config has to be None if config_filepath is provided"
170
+ )
171
+
172
+ if not os.path.exists(config_filepath):
173
+ raise UserError(f"Deployment config file not found at {config_filepath}")
174
+ with open(config_filepath, "r") as file:
175
+ deployment_config = yaml.safe_load(file)
176
+ elif deployment_config is not None:
177
+ assert isinstance(deployment_config, dict), (
178
+ "deployment_config should be a dictionary if provided."
179
+ )
180
+ else:
181
+ raise AssertionError("Either config_filepath or deployment_config must be provided.")
182
+
183
+ deployment_config = self._process_deployment_config(deployment_config)
184
+
185
+ if 'id' in deployment_config:
186
+ if deployment_id is None:
187
+ deployment_id = deployment_config['id']
188
+ deployment_config.pop('id')
189
+
190
+ request = service_pb2.PostDeploymentsRequest(
191
+ user_app_id=self.user_app_id,
192
+ deployments=[resources_pb2.Deployment(id=deployment_id, **deployment_config)],
193
+ )
194
+ response = self._grpc_request(self.STUB.PostDeployments, request)
195
+ if response.status.code != status_code_pb2.SUCCESS:
196
+ raise Exception(response.status)
197
+ self.logger.info("\nDeployment created\n%s", response.status)
198
+
199
+ dict_response = MessageToDict(
200
+ response.deployments[0], preserving_proto_field_name=True, use_integers_for_enums=True
201
+ )
202
+ kwargs = self.process_response_keys(dict_response, "deployment")
203
+ return Deployment.from_auth_helper(auth=self.auth_helper, **kwargs)
204
+
205
+ def deployment(self, deployment_id: str) -> Deployment:
206
+ """Returns a Deployment object for the existing deployment ID.
207
+
208
+ Args:
209
+ deployment_id (str): The deployment ID for the deployment to interact with.
210
+
211
+ Returns:
212
+ Deployment: A Deployment object for the existing deployment ID.
213
+
214
+ Example:
215
+ >>> from clarifai.client.nodepool import Nodepool
216
+ >>> nodepool = Nodepool(nodepool_id="nodepool_id", user_id="user_id")
217
+ >>> deployment = nodepool.deployment(deployment_id="deployment_id")
218
+ """
219
+ request = service_pb2.GetDeploymentRequest(
220
+ user_app_id=self.user_app_id, deployment_id=deployment_id
221
+ )
222
+ response = self._grpc_request(self.STUB.GetDeployment, request)
223
+
224
+ if response.status.code != status_code_pb2.SUCCESS:
225
+ raise Exception(response.status)
226
+ dict_response = MessageToDict(
227
+ response, preserving_proto_field_name=True, use_integers_for_enums=True
228
+ )
229
+ kwargs = self.process_response_keys(dict_response["deployment"], "deployment")
230
+ return Deployment.from_auth_helper(auth=self.auth_helper, **kwargs)
231
+
232
+ def delete_deployments(self, deployment_ids: List[str]) -> None:
233
+ """Deletes list of deployments for the nodepool.
234
+
235
+ Args:
236
+ deployment_ids (List[str]): The list of deployment IDs to delete.
237
+
238
+ Example:
239
+ >>> from clarifai.client.nodepool import Nodepool
240
+ >>> nodepool = Nodepool(nodepool_id="nodepool_id", user_id="user_id")
241
+ >>> nodepool.delete_deployments(deployment_ids=["deployment_id1", "deployment_id2"])
242
+ """
243
+ assert isinstance(deployment_ids, list), "deployment_ids param should be a list"
244
+
245
+ request = service_pb2.DeleteDeploymentsRequest(
246
+ user_app_id=self.user_app_id, ids=deployment_ids
247
+ )
248
+ response = self._grpc_request(self.STUB.DeleteDeployments, request)
249
+
250
+ if response.status.code != status_code_pb2.SUCCESS:
251
+ raise Exception(response.status)
252
+ self.logger.info("\nDeployments Deleted\n%s", response.status)
253
+
254
+ def runner(self, runner_id: str) -> Runner:
255
+ """Returns a Runner object for the existing runner ID.
256
+
257
+ Args:
258
+ runner_id (str): The runner ID for the runner to interact with.
259
+
260
+ Returns:
261
+ Runner: A Runner object for the existing runner ID.
262
+
263
+ Example:
264
+ >>> from clarifai.client.nodepool import Nodepool
265
+ >>> nodepool = Nodepool(nodepool_id="nodepool_id", user_id="user_id")
266
+ >>> runner = nodepool.runner(runner_id="runner_id")
267
+ """
268
+ request = service_pb2.GetRunnerRequest(user_app_id=self.user_app_id, runner_id=runner_id)
269
+ response = self._grpc_request(self.STUB.GetRunner, request)
270
+
271
+ if response.status.code != status_code_pb2.SUCCESS:
272
+ raise Exception(response.status)
273
+ dict_response = MessageToDict(
274
+ response, preserving_proto_field_name=True, use_integers_for_enums=True
275
+ )
276
+ kwargs = self.process_response_keys(dict_response["runner"], "runner")
277
+ return Runner.from_auth_helper(auth=self.auth_helper, **kwargs)
278
+
279
+ def create_runner(
280
+ self, config_filepath: str = None, runner_config: Dict[str, Any] = None
281
+ ) -> Runner:
282
+ """Creates a runner for the nodepool. Only needed for local dev runners.
283
+
284
+ Args:
285
+ config_filepath (str): The path to the runner config file.
286
+ nodepool_config (Dict[str, Any]) = nodepool_config or {}
287
+
288
+ Returns:
289
+ resources_pb2.Runner: A Runner object for the specified deployment ID.
290
+
291
+ Example:
292
+ >>> from clarifai.client.nodepool import Nodepool
293
+ >>> nodepool = Nodepool(nodepool_id="nodepool_id", user_id="user_id")
294
+ >>> runner = nodepool.create_runner(deployment_id="deployment_id")
295
+ """
296
+
297
+ if config_filepath is not None:
298
+ assert runner_config is None, (
299
+ "runner_config has to be None if config_filepath is provided"
300
+ )
301
+
302
+ if not os.path.exists(config_filepath):
303
+ raise UserError(f"Runner config file not found at {config_filepath}")
304
+ with open(config_filepath, "r") as file:
305
+ runner_config = yaml.safe_load(file)
306
+ elif runner_config is not None:
307
+ assert isinstance(runner_config, dict), (
308
+ "runner_config should be a dictionary if provided."
309
+ )
310
+ else:
311
+ raise AssertionError("Either config_filepath or runner_config must be provided.")
312
+
313
+ runner_config = self._process_runner_config(runner_config)
314
+
315
+ request = service_pb2.PostRunnersRequest(
316
+ user_app_id=self.user_app_id,
317
+ nodepool_id=self.id,
318
+ compute_cluster_id=self.compute_cluster.id,
319
+ runners=[resources_pb2.Runner(**runner_config)],
320
+ )
321
+ response = self._grpc_request(self.STUB.PostRunners, request)
322
+
323
+ if response.status.code != status_code_pb2.SUCCESS:
324
+ raise Exception(response.status)
325
+ self.logger.info(
326
+ "\nRunner created\n%s with id: %s", response.status, response.runners[0].id
327
+ )
328
+
329
+ dict_response = MessageToDict(response.runners[0], preserving_proto_field_name=True)
330
+ kwargs = self.process_response_keys(dict_response, 'runner')
331
+ return Runner.from_auth_helper(auth=self.auth_helper, **kwargs)
332
+
333
+ def delete_runners(self, runner_ids: List[str]) -> None:
334
+ """Deletes list of runners for the nodepool.
335
+
336
+ Args:
337
+ runner_ids (List[str]): The list of runner IDs to delete.
338
+
339
+ Example:
340
+ >>> from clarifai.client.nodepool import Nodepool
341
+ >>> nodepool = Nodepool(nodepool_id="nodepool_id", user_id="user_id")
342
+ >>> nodepool.delete_runners(runner_ids=["runner_id1", "runner_id2"])
343
+ """
344
+ assert isinstance(runner_ids, list), "runner_ids param should be a list"
345
+
346
+ request = service_pb2.DeleteRunnersRequest(
347
+ user_app_id=self.user_app_id,
348
+ ids=runner_ids,
349
+ compute_cluster_id=self.compute_cluster.id,
350
+ nodepool_id=self.id,
351
+ )
352
+ response = self._grpc_request(self.STUB.DeleteRunners, request)
353
+
354
+ if response.status.code != status_code_pb2.SUCCESS:
355
+ raise Exception(response.status)
356
+ self.logger.info("\nRunners Deleted\n%s", response.status)
357
+
358
+ def _process_runner_config(self, runner_config: str) -> Dict[str, Any]:
359
+ assert "runner" in runner_config, "runner info not found in the config file"
360
+ runner = runner_config['runner']
361
+ assert "worker" in runner, "worker not found in the config file"
362
+ assert "num_replicas" in runner, "num_replicas not found in the config file"
363
+ return runner
364
+
365
+ def __getattr__(self, name):
366
+ return getattr(self.nodepool_info, name)
367
+
368
+ def __str__(self):
369
+ init_params = [param for param in self.kwargs.keys()]
370
+ attribute_strings = [
371
+ f"{param}={getattr(self.nodepool_info, param)}"
372
+ for param in init_params
373
+ if hasattr(self.nodepool_info, param)
374
+ ]
375
+ return f"Nodepool Details: \n{', '.join(attribute_strings)}\n"
@@ -0,0 +1,58 @@
1
+ from clarifai_grpc.grpc.api import resources_pb2
2
+
3
+ from clarifai.client.base import BaseClient
4
+ from clarifai.client.lister import Lister
5
+ from clarifai.utils.logging import logger
6
+ from clarifai.utils.protobuf import dict_to_protobuf
7
+
8
+
9
+ class Runner(Lister, BaseClient):
10
+ """Runner is a class that provides access to Clarifai API endpoints related to Runner information."""
11
+
12
+ def __init__(
13
+ self,
14
+ runner_id: str = None,
15
+ user_id: str = None,
16
+ base_url: str = "https://api.clarifai.com",
17
+ pat: str = None,
18
+ token: str = None,
19
+ root_certificates_path: str = None,
20
+ **kwargs,
21
+ ):
22
+ """Initializes a Runner object.
23
+
24
+ Args:
25
+ runner_id (str): The Runner ID for the Runner to interact with.
26
+ user_id (str): The user ID of the user.
27
+ base_url (str): Base API url. Default "https://api.clarifai.com"
28
+ pat (str): A personal access token for authentication. Can be set as env var CLARIFAI_PAT
29
+ token (str): A session token for authentication. Accepts either a session token or a pat. Can be set as env var CLARIFAI_SESSION_TOKEN
30
+ root_certificates_path (str): Path to the SSL root certificates file, used to establish secure gRPC connections.
31
+ **kwargs: Additional keyword arguments to be passed to the runner.
32
+ """
33
+ self.kwargs = {**kwargs, 'id': runner_id}
34
+ self.runner_info = resources_pb2.Runner()
35
+ dict_to_protobuf(self.runner_info, self.kwargs)
36
+
37
+ self.logger = logger
38
+ BaseClient.__init__(
39
+ self,
40
+ user_id=user_id,
41
+ base=base_url,
42
+ pat=pat,
43
+ token=token,
44
+ root_certificates_path=root_certificates_path,
45
+ )
46
+ Lister.__init__(self)
47
+
48
+ def __getattr__(self, name):
49
+ return getattr(self.runner_info, name)
50
+
51
+ def __str__(self):
52
+ init_params = [param for param in self.kwargs.keys()]
53
+ attribute_strings = [
54
+ f"{param}={getattr(self.runner_info, param)}"
55
+ for param in init_params
56
+ if hasattr(self.runner_info, param)
57
+ ]
58
+ return f"Runner Details: \n{', '.join(attribute_strings)}\n"