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/client/user.py CHANGED
@@ -16,419 +16,424 @@ from clarifai.utils.logging import logger
16
16
 
17
17
 
18
18
  class User(Lister, BaseClient):
19
- """User is a class that provides access to Clarifai API endpoints related to user information."""
20
-
21
- def __init__(self,
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
- """Initializes an User object.
29
-
30
- Args:
31
- user_id (str): The user ID for the user to interact with.
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 User.
37
- """
38
- self.kwargs = {**kwargs, 'id': user_id}
39
- self.user_info = resources_pb2.User(**self.kwargs)
40
- self.logger = logger
41
- BaseClient.__init__(
19
+ """User is a class that provides access to Clarifai API endpoints related to user information."""
20
+
21
+ def __init__(
22
+ self,
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 an User object.
31
+
32
+ Args:
33
+ user_id (str): The user ID for the user to interact with.
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 User.
39
+ """
40
+ self.kwargs = {**kwargs, 'id': user_id}
41
+ self.user_info = resources_pb2.User(**self.kwargs)
42
+ self.logger = logger
43
+ BaseClient.__init__(
44
+ self,
45
+ user_id=self.id,
46
+ app_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_apps(
55
+ self, filter_by: Dict[str, Any] = {}, page_no: int = None, per_page: int = None
56
+ ) -> Generator[App, None, None]:
57
+ """Lists all the apps for the user.
58
+
59
+ Args:
60
+ filter_by (dict): A dictionary of filters to be applied to the list of apps.
61
+ page_no (int): The page number to list.
62
+ per_page (int): The number of items per page.
63
+
64
+ Yields:
65
+ App: App objects for the user.
66
+
67
+ Example:
68
+ >>> from clarifai.client.user import User
69
+ >>> apps = list(User("user_id").list_apps())
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, **filter_by)
76
+ all_apps_info = self.list_pages_generator(
77
+ self.STUB.ListApps,
78
+ service_pb2.ListAppsRequest,
79
+ request_data,
80
+ per_page=per_page,
81
+ page_no=page_no,
82
+ )
83
+ for app_info in all_apps_info:
84
+ yield App.from_auth_helper(
85
+ self.auth_helper, **app_info
86
+ ) # (base_url=self.base, pat=self.pat, token=self.token, **app_info)
87
+
88
+ def list_runners(
89
+ self, filter_by: Dict[str, Any] = {}, page_no: int = None, per_page: int = None
90
+ ) -> Generator[dict, None, None]:
91
+ """List all runners for the user
92
+
93
+ Args:
94
+ filter_by (dict): A dictionary of filters to apply to the list of runners.
95
+ page_no (int): The page number to list.
96
+ per_page (int): The number of items per page.
97
+
98
+ Yields:
99
+ Dict: Dictionaries containing information about the runners.
100
+
101
+ Example:
102
+ >>> from clarifai.client.user import User
103
+ >>> client = User(user_id="user_id")
104
+ >>> all_runners= list(client.list_runners())
105
+
106
+ Note:
107
+ Defaults to 16 per page if page_no is specified and per_page is not specified.
108
+ If both page_no and per_page are None, then lists all the resources.
109
+ """
110
+ request_data = dict(user_app_id=self.user_app_id, **filter_by)
111
+ all_runners_info = self.list_pages_generator(
112
+ self.STUB.ListRunners,
113
+ service_pb2.ListRunnersRequest,
114
+ request_data,
115
+ per_page=per_page,
116
+ page_no=page_no,
117
+ )
118
+
119
+ for runner_info in all_runners_info:
120
+ yield dict(auth=self.auth_helper, check_runner_exists=False, **runner_info)
121
+
122
+ def list_compute_clusters(
123
+ self, page_no: int = None, per_page: int = None
124
+ ) -> Generator[dict, None, None]:
125
+ """List all compute clusters for the user
126
+
127
+ Args:
128
+ page_no (int): The page number to list.
129
+ per_page (int): The number of items per page.
130
+
131
+ Yields:
132
+ Dict: Dictionaries containing information about the compute clusters.
133
+
134
+ Example:
135
+ >>> from clarifai.client.user import User
136
+ >>> client = User(user_id="user_id")
137
+ >>> all_compute_clusters= list(client.list_compute_clusters())
138
+
139
+ Note:
140
+ Defaults to 16 per page if page_no is specified and per_page is not specified.
141
+ If both page_no and per_page are None, then lists all the resources.
142
+ """
143
+ request_data = dict(user_app_id=self.user_app_id)
144
+ all_compute_clusters_info = self.list_pages_generator(
145
+ self.STUB.ListComputeClusters,
146
+ service_pb2.ListComputeClustersRequest,
147
+ request_data,
148
+ per_page=per_page,
149
+ page_no=page_no,
150
+ )
151
+
152
+ for compute_cluster_info in all_compute_clusters_info:
153
+ yield ComputeCluster.from_auth_helper(self.auth_helper, **compute_cluster_info)
154
+
155
+ def create_app(self, app_id: str, base_workflow: str = 'Empty', **kwargs) -> App:
156
+ """Creates an app for the user.
157
+
158
+ Args:
159
+ app_id (str): The app ID for the app to create.
160
+ base_workflow (str): The base workflow to use for the app.(Examples: 'Universal', 'Language-Understanding', 'General')
161
+ **kwargs: Additional keyword arguments to be passed to the App.
162
+
163
+ Returns:
164
+ App: An App object for the specified app ID.
165
+
166
+ Example:
167
+ >>> from clarifai.client.user import User
168
+ >>> client = User(user_id="user_id")
169
+ >>> app = client.create_app(app_id="app_id",base_workflow="Universal")
170
+ """
171
+ workflow = resources_pb2.Workflow(id=base_workflow, app_id="main", user_id="clarifai")
172
+ request = service_pb2.PostAppsRequest(
173
+ user_app_id=self.user_app_id,
174
+ apps=[resources_pb2.App(id=app_id, default_workflow=workflow, **kwargs)],
175
+ )
176
+ response = self._grpc_request(self.STUB.PostApps, request)
177
+ if response.status.code != status_code_pb2.SUCCESS:
178
+ raise Exception(response.status)
179
+ self.logger.info("\nApp created\n%s", response.status)
180
+ return App.from_auth_helper(auth=self.auth_helper, app_id=app_id)
181
+
182
+ def _process_compute_cluster_config(
183
+ self, compute_cluster_config: Dict[str, Any]
184
+ ) -> Dict[str, Any]:
185
+ assert "compute_cluster" in compute_cluster_config, (
186
+ "compute cluster info not found in the config file"
187
+ )
188
+ compute_cluster = compute_cluster_config['compute_cluster']
189
+ assert "region" in compute_cluster, "region not found in the config file"
190
+ assert "managed_by" in compute_cluster, "managed_by not found in the config file"
191
+ assert "cluster_type" in compute_cluster, "cluster_type not found in the config file"
192
+ compute_cluster['cloud_provider'] = resources_pb2.CloudProvider(
193
+ **compute_cluster['cloud_provider']
194
+ )
195
+ compute_cluster['key'] = resources_pb2.Key(id=self.pat)
196
+ if "visibility" in compute_cluster:
197
+ compute_cluster["visibility"] = resources_pb2.Visibility(
198
+ **compute_cluster["visibility"]
199
+ )
200
+ return compute_cluster
201
+
202
+ def create_compute_cluster(
42
203
  self,
43
- user_id=self.id,
44
- app_id="",
45
- base=base_url,
46
- pat=pat,
47
- token=token,
48
- root_certificates_path=root_certificates_path)
49
- Lister.__init__(self)
50
-
51
- def list_apps(self, filter_by: Dict[str, Any] = {}, page_no: int = None,
52
- per_page: int = None) -> Generator[App, None, None]:
53
- """Lists all the apps for the user.
54
-
55
- Args:
56
- filter_by (dict): A dictionary of filters to be applied to the list of apps.
57
- page_no (int): The page number to list.
58
- per_page (int): The number of items per page.
59
-
60
- Yields:
61
- App: App objects for the user.
62
-
63
- Example:
64
- >>> from clarifai.client.user import User
65
- >>> apps = list(User("user_id").list_apps())
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, **filter_by)
72
- all_apps_info = self.list_pages_generator(
73
- self.STUB.ListApps,
74
- service_pb2.ListAppsRequest,
75
- request_data,
76
- per_page=per_page,
77
- page_no=page_no)
78
- for app_info in all_apps_info:
79
- yield App.from_auth_helper(
80
- self.auth_helper,
81
- **app_info) #(base_url=self.base, pat=self.pat, token=self.token, **app_info)
82
-
83
- def list_runners(self, filter_by: Dict[str, Any] = {}, page_no: int = None,
84
- per_page: int = None) -> Generator[dict, None, None]:
85
- """List all runners for the user
86
-
87
- Args:
88
- filter_by (dict): A dictionary of filters to apply to the list of runners.
89
- page_no (int): The page number to list.
90
- per_page (int): The number of items per page.
91
-
92
- Yields:
93
- Dict: Dictionaries containing information about the runners.
94
-
95
- Example:
96
- >>> from clarifai.client.user import User
97
- >>> client = User(user_id="user_id")
98
- >>> all_runners= list(client.list_runners())
99
-
100
- Note:
101
- Defaults to 16 per page if page_no is specified and per_page is not specified.
102
- If both page_no and per_page are None, then lists all the resources.
103
- """
104
- request_data = dict(user_app_id=self.user_app_id, **filter_by)
105
- all_runners_info = self.list_pages_generator(
106
- self.STUB.ListRunners,
107
- service_pb2.ListRunnersRequest,
108
- request_data,
109
- per_page=per_page,
110
- page_no=page_no)
111
-
112
- for runner_info in all_runners_info:
113
- yield dict(auth=self.auth_helper, check_runner_exists=False, **runner_info)
114
-
115
- def list_compute_clusters(self, page_no: int = None,
116
- per_page: int = None) -> Generator[dict, None, None]:
117
- """List all compute clusters for the user
118
-
119
- Args:
120
- page_no (int): The page number to list.
121
- per_page (int): The number of items per page.
122
-
123
- Yields:
124
- Dict: Dictionaries containing information about the compute clusters.
125
-
126
- Example:
127
- >>> from clarifai.client.user import User
128
- >>> client = User(user_id="user_id")
129
- >>> all_compute_clusters= list(client.list_compute_clusters())
130
-
131
- Note:
132
- Defaults to 16 per page if page_no is specified and per_page is not specified.
133
- If both page_no and per_page are None, then lists all the resources.
134
- """
135
- request_data = dict(user_app_id=self.user_app_id)
136
- all_compute_clusters_info = self.list_pages_generator(
137
- self.STUB.ListComputeClusters,
138
- service_pb2.ListComputeClustersRequest,
139
- request_data,
140
- per_page=per_page,
141
- page_no=page_no)
142
-
143
- for compute_cluster_info in all_compute_clusters_info:
144
- yield ComputeCluster.from_auth_helper(self.auth_helper, **compute_cluster_info)
145
-
146
- def create_app(self, app_id: str, base_workflow: str = 'Empty', **kwargs) -> App:
147
- """Creates an app for the user.
148
-
149
- Args:
150
- app_id (str): The app ID for the app to create.
151
- base_workflow (str): The base workflow to use for the app.(Examples: 'Universal', 'Language-Understanding', 'General')
152
- **kwargs: Additional keyword arguments to be passed to the App.
153
-
154
- Returns:
155
- App: An App object for the specified app ID.
156
-
157
- Example:
158
- >>> from clarifai.client.user import User
159
- >>> client = User(user_id="user_id")
160
- >>> app = client.create_app(app_id="app_id",base_workflow="Universal")
161
- """
162
- workflow = resources_pb2.Workflow(id=base_workflow, app_id="main", user_id="clarifai")
163
- request = service_pb2.PostAppsRequest(
164
- user_app_id=self.user_app_id,
165
- apps=[resources_pb2.App(id=app_id, default_workflow=workflow, **kwargs)])
166
- response = self._grpc_request(self.STUB.PostApps, request)
167
- if response.status.code != status_code_pb2.SUCCESS:
168
- raise Exception(response.status)
169
- self.logger.info("\nApp created\n%s", response.status)
170
- return App.from_auth_helper(auth=self.auth_helper, app_id=app_id)
171
-
172
- def create_runner(self, runner_id: str, labels: List[str], description: str) -> dict:
173
- """Create a runner
174
-
175
- Args:
176
- runner_id (str): The Id of runner to create
177
- labels (List[str]): Labels to match runner
178
- description (str): Description of Runner
179
-
180
- Returns:
181
- Dict: A dictionary containing information about the specified Runner ID.
182
-
183
- Example:
184
- >>> from clarifai.client.user import User
185
- >>> client = User(user_id="user_id")
186
- >>> runner_info = client.create_runner(runner_id="runner_id", labels=["label to link runner"], description="laptop runner")
187
- """
188
-
189
- if not isinstance(labels, List):
190
- raise UserError("Labels must be a List of strings")
191
-
192
- request = service_pb2.PostRunnersRequest(
193
- user_app_id=self.user_app_id,
194
- runners=[resources_pb2.Runner(id=runner_id, labels=labels, description=description)])
195
- response = self._grpc_request(self.STUB.PostRunners, request)
196
-
197
- if response.status.code != status_code_pb2.SUCCESS:
198
- raise Exception(response.status)
199
- self.logger.info("\nRunner created\n%s", response.status)
200
-
201
- return dict(
202
- auth=self.auth_helper,
203
- runner_id=runner_id,
204
- user_id=self.id,
205
- labels=labels,
206
- description=description,
207
- check_runner_exists=False)
208
-
209
- def _process_compute_cluster_config(self, config_filepath: str) -> Dict[str, Any]:
210
- with open(config_filepath, "r") as file:
211
- compute_cluster_config = yaml.safe_load(file)
212
-
213
- assert "compute_cluster" in compute_cluster_config, "compute cluster info not found in the config file"
214
- compute_cluster = compute_cluster_config['compute_cluster']
215
- assert "region" in compute_cluster, "region not found in the config file"
216
- assert "managed_by" in compute_cluster, "managed_by not found in the config file"
217
- assert "cluster_type" in compute_cluster, "cluster_type not found in the config file"
218
- compute_cluster['cloud_provider'] = resources_pb2.CloudProvider(
219
- **compute_cluster['cloud_provider'])
220
- compute_cluster['key'] = resources_pb2.Key(id=self.pat)
221
- if "visibility" in compute_cluster:
222
- compute_cluster["visibility"] = resources_pb2.Visibility(**compute_cluster["visibility"])
223
- return compute_cluster
224
-
225
- def create_compute_cluster(self, config_filepath: str,
226
- compute_cluster_id: str = None) -> ComputeCluster:
227
- """Creates a compute cluster for the user.
228
-
229
- Args:
230
- config_filepath (str): The path to the compute cluster config file.
231
- compute_cluster_id (str): New compute cluster ID for the compute cluster to create.
232
-
233
- Returns:
234
- ComputeCluster: A Compute Cluster object for the specified compute cluster ID.
235
-
236
- Example:
237
- >>> from clarifai.client.user import User
238
- >>> client = User(user_id="user_id")
239
- >>> compute_cluster = client.create_compute_cluster(config_filepath="config.yml")
240
- """
241
- if not os.path.exists(config_filepath):
242
- raise UserError(f"Compute Cluster config file not found at {config_filepath}")
243
-
244
- compute_cluster_config = self._process_compute_cluster_config(config_filepath)
245
-
246
- if 'id' in compute_cluster_config:
247
- if compute_cluster_id is None:
248
- compute_cluster_id = compute_cluster_config['id']
249
- compute_cluster_config.pop('id')
250
-
251
- request = service_pb2.PostComputeClustersRequest(
252
- user_app_id=self.user_app_id,
253
- compute_clusters=[
254
- resources_pb2.ComputeCluster(id=compute_cluster_id, **compute_cluster_config)
255
- ])
256
- response = self._grpc_request(self.STUB.PostComputeClusters, request)
257
- if response.status.code != status_code_pb2.SUCCESS:
258
- raise Exception(response.status)
259
- self.logger.info("\nCompute Cluster created\n%s", response.status)
260
- return ComputeCluster.from_auth_helper(
261
- auth=self.auth_helper, compute_cluster_id=compute_cluster_id)
262
-
263
- def app(self, app_id: str, **kwargs) -> App:
264
- """Returns an App object for the specified app ID.
265
-
266
- Args:
267
- app_id (str): The app ID for the app to interact with.
268
- **kwargs: Additional keyword arguments to be passed to the App.
269
-
270
- Returns:
271
- App: An App object for the specified app ID.
272
-
273
- Example:
274
- >>> from clarifai.client.user import User
275
- >>> app = User("user_id").app("app_id")
276
- """
277
- request = service_pb2.GetAppRequest(
278
- user_app_id=resources_pb2.UserAppIDSet(user_id=self.id, app_id=app_id))
279
- response = self._grpc_request(self.STUB.GetApp, request)
280
- if response.status.code != status_code_pb2.SUCCESS:
281
- raise Exception(response.status)
282
-
283
- kwargs['user_id'] = self.id
284
- return App.from_auth_helper(auth=self.auth_helper, app_id=app_id, **kwargs)
285
-
286
- def runner(self, runner_id: str) -> dict:
287
- """Returns a Runner object if exists.
288
-
289
- Args:
290
- runner_id (str): The runner ID to interact with
291
-
292
- Returns:
293
- Dict: A dictionary containing information about the existing runner ID.
294
-
295
- Example:
296
- >>> from clarifai.client.user import User
297
- >>> client = User(user_id="user_id")
298
- >>> runner_info = client.runner(runner_id="runner_id")
299
- """
300
- request = service_pb2.GetRunnerRequest(user_app_id=self.user_app_id, runner_id=runner_id)
301
- response = self._grpc_request(self.STUB.GetRunner, request)
302
- if response.status.code != status_code_pb2.SUCCESS:
303
- raise Exception(
304
- f"""Error getting runner, are you use this is a valid runner id {runner_id} at the user_id/app_id
204
+ config_filepath: str = None,
205
+ compute_cluster_id: str = None,
206
+ compute_cluster_config: Dict[str, Any] = None,
207
+ ) -> ComputeCluster:
208
+ """Creates a compute cluster for the user.
209
+
210
+ Args:
211
+ config_filepath (str): The path to the compute cluster config file.
212
+ compute_cluster_id (str): New compute cluster ID for the compute cluster to create.
213
+ compute_cluster_config (Dict[str, Any]): Optional dictionary containing compute cluster configuration.
214
+
215
+ Returns:
216
+ ComputeCluster: A Compute Cluster object for the specified compute cluster ID.
217
+
218
+ Example:
219
+ >>> from clarifai.client.user import User
220
+ >>> client = User(user_id="user_id")
221
+ >>> compute_cluster = client.create_compute_cluster(config_filepath="config.yml")
222
+ """
223
+
224
+ if config_filepath is not None:
225
+ assert compute_cluster_config is None, (
226
+ "Either config_filepath or compute_cluster_config should be provided, not both."
227
+ )
228
+ if not os.path.exists(config_filepath):
229
+ raise UserError(f"Compute Cluster config file not found at {config_filepath}")
230
+ with open(config_filepath, "r") as f:
231
+ compute_cluster_config = yaml.safe_load(f)
232
+ elif compute_cluster_config is not None:
233
+ assert isinstance(compute_cluster_config, dict), (
234
+ "compute_cluster_config should be a dictionary if provided."
235
+ )
236
+ else:
237
+ raise AssertionError(
238
+ "Either config_filepath or compute_cluster_config should be provided."
239
+ )
240
+
241
+ compute_cluster_config = self._process_compute_cluster_config(compute_cluster_config)
242
+
243
+ if 'id' in compute_cluster_config:
244
+ if compute_cluster_id is None:
245
+ compute_cluster_id = compute_cluster_config['id']
246
+ compute_cluster_config.pop('id')
247
+
248
+ request = service_pb2.PostComputeClustersRequest(
249
+ user_app_id=self.user_app_id,
250
+ compute_clusters=[
251
+ resources_pb2.ComputeCluster(id=compute_cluster_id, **compute_cluster_config)
252
+ ],
253
+ )
254
+ response = self._grpc_request(self.STUB.PostComputeClusters, request)
255
+ if response.status.code != status_code_pb2.SUCCESS:
256
+ raise Exception(response.status)
257
+ self.logger.info("\nCompute Cluster created\n%s", response.status)
258
+ return ComputeCluster.from_auth_helper(
259
+ auth=self.auth_helper, compute_cluster_id=compute_cluster_id
260
+ )
261
+
262
+ def app(self, app_id: str, **kwargs) -> App:
263
+ """Returns an App object for the specified app ID.
264
+
265
+ Args:
266
+ app_id (str): The app ID for the app to interact with.
267
+ **kwargs: Additional keyword arguments to be passed to the App.
268
+
269
+ Returns:
270
+ App: An App object for the specified app ID.
271
+
272
+ Example:
273
+ >>> from clarifai.client.user import User
274
+ >>> app = User("user_id").app("app_id")
275
+ """
276
+ request = service_pb2.GetAppRequest(
277
+ user_app_id=resources_pb2.UserAppIDSet(user_id=self.id, app_id=app_id)
278
+ )
279
+ response = self._grpc_request(self.STUB.GetApp, request)
280
+ if response.status.code != status_code_pb2.SUCCESS:
281
+ raise Exception(response.status)
282
+
283
+ kwargs['user_id'] = self.id
284
+ return App.from_auth_helper(auth=self.auth_helper, app_id=app_id, **kwargs)
285
+
286
+ def runner(self, runner_id: str) -> dict:
287
+ """Returns a Runner object if exists.
288
+
289
+ Args:
290
+ runner_id (str): The runner ID to interact with
291
+
292
+ Returns:
293
+ Dict: A dictionary containing information about the existing runner ID.
294
+
295
+ Example:
296
+ >>> from clarifai.client.user import User
297
+ >>> client = User(user_id="user_id")
298
+ >>> runner_info = client.runner(runner_id="runner_id")
299
+ """
300
+ request = service_pb2.GetRunnerRequest(user_app_id=self.user_app_id, runner_id=runner_id)
301
+ response = self._grpc_request(self.STUB.GetRunner, request)
302
+ if response.status.code != status_code_pb2.SUCCESS:
303
+ raise Exception(
304
+ f"""Error getting runner, are you use this is a valid runner id {runner_id} at the user_id/app_id
305
305
  {self.user_app_id.user_id}/{self.user_app_id.app_id}.
306
- Error: {response.status.description}""")
307
-
308
- dict_response = MessageToDict(response, preserving_proto_field_name=True)
309
- kwargs = self.process_response_keys(dict_response[list(dict_response.keys())[1]],
310
- list(dict_response.keys())[1])
311
-
312
- return dict(self.auth_helper, check_runner_exists=False, **kwargs)
313
-
314
- def compute_cluster(self, compute_cluster_id: str) -> ComputeCluster:
315
- """Returns an Compute Cluster object for the specified compute cluster ID.
316
-
317
- Args:
318
- compute_cluster_id (str): The compute cluster ID for the compute cluster to interact with.
319
-
320
- Returns:
321
- ComputeCluster: A Compute Cluster object for the specified compute cluster ID.
322
-
323
- Example:
324
- >>> from clarifai.client.user import User
325
- >>> compute_cluster = User("user_id").compute_cluster("compute_cluster_id")
326
- """
327
- request = service_pb2.GetComputeClusterRequest(
328
- user_app_id=self.user_app_id, compute_cluster_id=compute_cluster_id)
329
- response = self._grpc_request(self.STUB.GetComputeCluster, request)
330
- if response.status.code != status_code_pb2.SUCCESS:
331
- raise Exception(response.status)
332
-
333
- dict_response = MessageToDict(response, preserving_proto_field_name=True)
334
- kwargs = self.process_response_keys(dict_response[list(dict_response.keys())[1]],
335
- list(dict_response.keys())[1])
336
-
337
- return ComputeCluster.from_auth_helper(auth=self.auth_helper, **kwargs)
338
-
339
- def patch_app(self, app_id: str, action: str = 'overwrite', **kwargs) -> App:
340
- """Patch an app for the user.
341
-
342
- Args:
343
- app_id (str): The app ID for the app to patch.
344
- action (str): The action to perform on the app (overwrite/remove).
345
- **kwargs: Additional keyword arguments to be passed to patch the App.
346
-
347
- Returns:
348
- App: Patched App object for the specified app ID.
349
- """
350
- if "base_workflow" in kwargs:
351
- kwargs["default_workflow"] = resources_pb2.Workflow(
352
- id=kwargs.pop("base_workflow"), app_id="main", user_id="clarifai")
353
- if "visibility" in kwargs:
354
- kwargs["visibility"] = resources_pb2.Visibility(gettable=kwargs["visibility"])
355
- if "image_url" in kwargs:
356
- kwargs["image"] = resources_pb2.Image(url=kwargs.pop("image_url"))
357
- if "is_template" in kwargs:
358
- kwargs["is_template"] = BoolValue(value=kwargs["is_template"])
359
- request = service_pb2.PatchAppRequest(
360
- user_app_id=resources_pb2.UserAppIDSet(user_id=self.id, app_id=app_id),
361
- app=resources_pb2.App(id=app_id, **kwargs),
362
- action=action,
363
- reindex=False)
364
- response = self._grpc_request(self.STUB.PatchApp, request)
365
- if response.status.code != status_code_pb2.SUCCESS:
366
- raise Exception(response.status)
367
- self.logger.info("\nApp patched\n%s", response.status)
368
-
369
- return App.from_auth_helper(auth=self.auth_helper, app_id=app_id)
370
-
371
- def delete_app(self, app_id: str) -> None:
372
- """Deletes an app for the user.
373
-
374
- Args:
375
- app_id (str): The app ID for the app to delete.
376
-
377
- Example:
378
- >>> from clarifai.client.user import User
379
- >>> user = User("user_id").delete_app("app_id")
380
- """
381
- request = service_pb2.DeleteAppRequest(
382
- user_app_id=resources_pb2.UserAppIDSet(user_id=self.id, app_id=app_id))
383
- response = self._grpc_request(self.STUB.DeleteApp, request)
384
- if response.status.code != status_code_pb2.SUCCESS:
385
- raise Exception(response.status)
386
- self.logger.info("\nApp Deleted\n%s", response.status)
387
-
388
- def delete_runner(self, runner_id: str) -> None:
389
- """Deletes all spectified runner ids
390
-
391
- Args:
392
- runner_ids (str): List of runners to delete
393
-
394
- Example:
395
- >>> from clarifai.client.user import User
396
- >>> client = User(user_id="user_id")
397
- >>> client.delete_runner(runner_id="runner_id")
398
- """
399
- request = service_pb2.DeleteRunnersRequest(user_app_id=self.user_app_id, ids=[runner_id])
400
- response = self._grpc_request(self.STUB.DeleteRunners, request)
401
-
402
- if response.status.code != status_code_pb2.SUCCESS:
403
- raise Exception(response.status)
404
- self.logger.info("\nRunner Deleted\n%s", response.status)
405
-
406
- def delete_compute_clusters(self, compute_cluster_ids: List[str]) -> None:
407
- """Deletes a list of compute clusters for the user.
408
-
409
- Args:
410
- compute_cluster_ids (List[str]): The compute cluster IDs of the user to delete.
411
-
412
- Example:
413
- >>> from clarifai.client.user import User
414
- >>> user = User("user_id").delete_compute_clusters(compute_cluster_ids=["compute_cluster_id1", "compute_cluster_id2"])
415
- """
416
- assert isinstance(compute_cluster_ids, list), "compute_cluster_ids param should be a list"
417
-
418
- request = service_pb2.DeleteComputeClustersRequest(
419
- user_app_id=self.user_app_id, ids=compute_cluster_ids)
420
- response = self._grpc_request(self.STUB.DeleteComputeClusters, request)
421
- if response.status.code != status_code_pb2.SUCCESS:
422
- raise Exception(response.status)
423
- self.logger.info("\nCompute Cluster Deleted\n%s", response.status)
424
-
425
- def __getattr__(self, name):
426
- return getattr(self.user_info, name)
427
-
428
- def __str__(self):
429
- init_params = [param for param in self.kwargs.keys()]
430
- attribute_strings = [
431
- f"{param}={getattr(self.user_info, param)}" for param in init_params
432
- if hasattr(self.user_info, param)
433
- ]
434
- return f"Clarifai User Details: \n{', '.join(attribute_strings)}\n"
306
+ Error: {response.status.description}"""
307
+ )
308
+
309
+ dict_response = MessageToDict(response, preserving_proto_field_name=True)
310
+ kwargs = self.process_response_keys(dict_response["runner"], "runner")
311
+
312
+ return dict(self.auth_helper, check_runner_exists=False, **kwargs)
313
+
314
+ def compute_cluster(self, compute_cluster_id: str) -> ComputeCluster:
315
+ """Returns an Compute Cluster object for the specified compute cluster ID.
316
+
317
+ Args:
318
+ compute_cluster_id (str): The compute cluster ID for the compute cluster to interact with.
319
+
320
+ Returns:
321
+ ComputeCluster: A Compute Cluster object for the specified compute cluster ID.
322
+
323
+ Example:
324
+ >>> from clarifai.client.user import User
325
+ >>> compute_cluster = User("user_id").compute_cluster("compute_cluster_id")
326
+ """
327
+ request = service_pb2.GetComputeClusterRequest(
328
+ user_app_id=self.user_app_id, compute_cluster_id=compute_cluster_id
329
+ )
330
+ response = self._grpc_request(self.STUB.GetComputeCluster, request)
331
+ if response.status.code != status_code_pb2.SUCCESS:
332
+ raise Exception(response.status)
333
+
334
+ dict_response = MessageToDict(response, preserving_proto_field_name=True)
335
+ kwargs = self.process_response_keys(dict_response["compute_cluster"], "compute_cluster")
336
+
337
+ return ComputeCluster.from_auth_helper(auth=self.auth_helper, **kwargs)
338
+
339
+ def patch_app(self, app_id: str, action: str = 'overwrite', **kwargs) -> App:
340
+ """Patch an app for the user.
341
+
342
+ Args:
343
+ app_id (str): The app ID for the app to patch.
344
+ action (str): The action to perform on the app (overwrite/remove).
345
+ **kwargs: Additional keyword arguments to be passed to patch the App.
346
+
347
+ Returns:
348
+ App: Patched App object for the specified app ID.
349
+ """
350
+ if "base_workflow" in kwargs:
351
+ kwargs["default_workflow"] = resources_pb2.Workflow(
352
+ id=kwargs.pop("base_workflow"), app_id="main", user_id="clarifai"
353
+ )
354
+ if "visibility" in kwargs:
355
+ kwargs["visibility"] = resources_pb2.Visibility(gettable=kwargs["visibility"])
356
+ if "image_url" in kwargs:
357
+ kwargs["image"] = resources_pb2.Image(url=kwargs.pop("image_url"))
358
+ if "is_template" in kwargs:
359
+ kwargs["is_template"] = BoolValue(value=kwargs["is_template"])
360
+ request = service_pb2.PatchAppRequest(
361
+ user_app_id=resources_pb2.UserAppIDSet(user_id=self.id, app_id=app_id),
362
+ app=resources_pb2.App(id=app_id, **kwargs),
363
+ action=action,
364
+ reindex=False,
365
+ )
366
+ response = self._grpc_request(self.STUB.PatchApp, request)
367
+ if response.status.code != status_code_pb2.SUCCESS:
368
+ raise Exception(response.status)
369
+ self.logger.info("\nApp patched\n%s", response.status)
370
+
371
+ return App.from_auth_helper(auth=self.auth_helper, app_id=app_id)
372
+
373
+ def delete_app(self, app_id: str) -> None:
374
+ """Deletes an app for the user.
375
+
376
+ Args:
377
+ app_id (str): The app ID for the app to delete.
378
+
379
+ Example:
380
+ >>> from clarifai.client.user import User
381
+ >>> user = User("user_id").delete_app("app_id")
382
+ """
383
+ request = service_pb2.DeleteAppRequest(
384
+ user_app_id=resources_pb2.UserAppIDSet(user_id=self.id, app_id=app_id)
385
+ )
386
+ response = self._grpc_request(self.STUB.DeleteApp, request)
387
+ if response.status.code != status_code_pb2.SUCCESS:
388
+ raise Exception(response.status)
389
+ self.logger.info("\nApp Deleted\n%s", response.status)
390
+
391
+ def delete_runner(self, runner_id: str) -> None:
392
+ """Deletes all spectified runner ids
393
+
394
+ Args:
395
+ runner_ids (str): List of runners to delete
396
+
397
+ Example:
398
+ >>> from clarifai.client.user import User
399
+ >>> client = User(user_id="user_id")
400
+ >>> client.delete_runner(runner_id="runner_id")
401
+ """
402
+ request = service_pb2.DeleteRunnersRequest(user_app_id=self.user_app_id, ids=[runner_id])
403
+ response = self._grpc_request(self.STUB.DeleteRunners, request)
404
+
405
+ if response.status.code != status_code_pb2.SUCCESS:
406
+ raise Exception(response.status)
407
+ self.logger.info("\nRunner Deleted\n%s", response.status)
408
+
409
+ def delete_compute_clusters(self, compute_cluster_ids: List[str]) -> None:
410
+ """Deletes a list of compute clusters for the user.
411
+
412
+ Args:
413
+ compute_cluster_ids (List[str]): The compute cluster IDs of the user to delete.
414
+
415
+ Example:
416
+ >>> from clarifai.client.user import User
417
+ >>> user = User("user_id").delete_compute_clusters(compute_cluster_ids=["compute_cluster_id1", "compute_cluster_id2"])
418
+ """
419
+ assert isinstance(compute_cluster_ids, list), "compute_cluster_ids param should be a list"
420
+
421
+ request = service_pb2.DeleteComputeClustersRequest(
422
+ user_app_id=self.user_app_id, ids=compute_cluster_ids
423
+ )
424
+ response = self._grpc_request(self.STUB.DeleteComputeClusters, request)
425
+ if response.status.code != status_code_pb2.SUCCESS:
426
+ raise Exception(response.status)
427
+ self.logger.info("\nCompute Cluster Deleted\n%s", response.status)
428
+
429
+ def __getattr__(self, name):
430
+ return getattr(self.user_info, name)
431
+
432
+ def __str__(self):
433
+ init_params = [param for param in self.kwargs.keys()]
434
+ attribute_strings = [
435
+ f"{param}={getattr(self.user_info, param)}"
436
+ for param in init_params
437
+ if hasattr(self.user_info, param)
438
+ ]
439
+ return f"Clarifai User Details: \n{', '.join(attribute_strings)}\n"