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
@@ -1,23 +1,23 @@
1
1
  import abc
2
- import grpc
3
2
 
3
+ import grpc
4
4
  from clarifai_grpc.grpc.api import service_pb2_grpc
5
5
 
6
6
 
7
7
  class V2Stub(abc.ABC):
8
- """Abstract base class of clarifai api rpc client stubs"""
8
+ """Abstract base class of clarifai api rpc client stubs"""
9
9
 
10
10
 
11
11
  class RpcCallable(abc.ABC):
12
- """Abstract base class of clarifai api rpc callables"""
12
+ """Abstract base class of clarifai api rpc callables"""
13
13
 
14
14
 
15
15
  # add grpc classes as subclasses of the abcs, so they also succeed in isinstance calls
16
16
  def _register_classes():
17
- V2Stub.register(service_pb2_grpc.V2Stub)
18
- for name in dir(grpc):
19
- if name.endswith('Callable'):
20
- RpcCallable.register(getattr(grpc, name))
17
+ V2Stub.register(service_pb2_grpc.V2Stub)
18
+ for name in dir(grpc):
19
+ if name.endswith('Callable'):
20
+ RpcCallable.register(getattr(grpc, name))
21
21
 
22
22
 
23
23
  _register_classes()
@@ -8,6 +8,7 @@ from clarifai_grpc.grpc.api.status import status_code_pb2
8
8
  from clarifai.client.auth.helper import ClarifaiAuthHelper
9
9
  from clarifai.client.auth.register import RpcCallable, V2Stub
10
10
  from clarifai.utils.logging import logger
11
+
11
12
  throttle_status_codes = {
12
13
  status_code_pb2.CONN_THROTTLED,
13
14
  status_code_pb2.CONN_EXCEED_HOURLY_LIMIT,
@@ -21,134 +22,134 @@ _threadpool = ThreadPoolExecutor(100)
21
22
 
22
23
 
23
24
  def validate_response(response, attempt, max_attempts):
24
- # Helper function to handle simple response validation
25
- def handle_simple_response(response):
26
- if hasattr(response, 'status') and hasattr(response.status, 'code'):
27
- if (response.status.code in throttle_status_codes) and attempt < max_attempts:
28
- logger.debug('Retrying with status %s' % str(response.status))
29
- return None # Indicates a retry is needed
30
- else:
31
- return response
32
-
33
- # Check if the response is an instance of a gRPC streaming call
34
- if isinstance(response, grpc._channel._MultiThreadedRendezvous):
35
- try:
36
- # Check just the first response in the stream for validation
37
- first_res = next(response)
38
- validated_response = handle_simple_response(first_res)
39
- if validated_response is not None:
40
- # Have to return that first response and the rest of the stream.
41
- return itertools.chain([validated_response], response)
42
- return None # Indicates a retry is needed
43
- except grpc.RpcError as e:
44
- logger.error('Error processing streaming response: %s' % str(e))
45
- return None # Indicates an error
46
- else:
47
- # Handle simple response validation
48
- return handle_simple_response(response)
25
+ # Helper function to handle simple response validation
26
+ def handle_simple_response(response):
27
+ if hasattr(response, 'status') and hasattr(response.status, 'code'):
28
+ if (response.status.code in throttle_status_codes) and attempt < max_attempts:
29
+ logger.debug('Retrying with status %s' % str(response.status))
30
+ return None # Indicates a retry is needed
31
+ else:
32
+ return response
33
+
34
+ # Check if the response is an instance of a gRPC streaming call
35
+ if isinstance(response, grpc._channel._MultiThreadedRendezvous):
36
+ try:
37
+ # Check just the first response in the stream for validation
38
+ first_res = next(response)
39
+ validated_response = handle_simple_response(first_res)
40
+ if validated_response is not None:
41
+ # Have to return that first response and the rest of the stream.
42
+ return itertools.chain([validated_response], response)
43
+ return None # Indicates a retry is needed
44
+ except grpc.RpcError as e:
45
+ logger.error('Error processing streaming response: %s' % str(e))
46
+ return None # Indicates an error
47
+ else:
48
+ # Handle simple response validation
49
+ return handle_simple_response(response)
49
50
 
50
51
 
51
52
  def create_stub(auth_helper: ClarifaiAuthHelper = None, max_retry_attempts: int = 10) -> V2Stub:
52
- """
53
- Create client stub that handles authorization and basic retries for
54
- unavailable or throttled connections.
53
+ """
54
+ Create client stub that handles authorization and basic retries for
55
+ unavailable or throttled connections.
55
56
 
56
- Args:
57
- auth_helper: ClarifaiAuthHelper to use for auth metadata (default: from env)
58
- max_retry_attempts: max attempts to retry rpcs with retryable failures
59
- """
60
- stub = AuthorizedStub(auth_helper)
61
- if max_retry_attempts > 0:
62
- return RetryStub(stub, max_retry_attempts)
63
- return stub
57
+ Args:
58
+ auth_helper: ClarifaiAuthHelper to use for auth metadata (default: from env)
59
+ max_retry_attempts: max attempts to retry rpcs with retryable failures
60
+ """
61
+ stub = AuthorizedStub(auth_helper)
62
+ if max_retry_attempts > 0:
63
+ return RetryStub(stub, max_retry_attempts)
64
+ return stub
64
65
 
65
66
 
66
67
  class AuthorizedStub(V2Stub):
67
- """V2Stub proxy that inserts metadata authorization in rpc calls."""
68
+ """V2Stub proxy that inserts metadata authorization in rpc calls."""
68
69
 
69
- def __init__(self, auth_helper: ClarifaiAuthHelper = None):
70
- if auth_helper is None:
71
- auth_helper = ClarifaiAuthHelper.from_env()
72
- self.stub = auth_helper.get_stub()
73
- self.metadata = auth_helper.metadata
70
+ def __init__(self, auth_helper: ClarifaiAuthHelper = None):
71
+ if auth_helper is None:
72
+ auth_helper = ClarifaiAuthHelper.from_env()
73
+ self.stub = auth_helper.get_stub()
74
+ self.metadata = auth_helper.metadata
74
75
 
75
- def __getattr__(self, name):
76
- value = getattr(self.stub, name)
77
- if isinstance(value, RpcCallable):
78
- value = _AuthorizedRpcCallable(value, self.metadata)
79
- return value
76
+ def __getattr__(self, name):
77
+ value = getattr(self.stub, name)
78
+ if isinstance(value, RpcCallable):
79
+ value = _AuthorizedRpcCallable(value, self.metadata)
80
+ return value
80
81
 
81
82
 
82
83
  class _AuthorizedRpcCallable(RpcCallable):
83
- """Adds metadata(authorization header) to rpc calls"""
84
+ """Adds metadata(authorization header) to rpc calls"""
84
85
 
85
- def __init__(self, func, metadata):
86
- self.f = func
87
- self.metadata = metadata
86
+ def __init__(self, func, metadata):
87
+ self.f = func
88
+ self.metadata = metadata
88
89
 
89
- def __repr__(self):
90
- return repr(self.f)
90
+ def __repr__(self):
91
+ return repr(self.f)
91
92
 
92
- def __call__(self, *args, **kwargs):
93
- metadata = kwargs.pop('metadata', self.metadata)
94
- return self.f(*args, **kwargs, metadata=metadata)
93
+ def __call__(self, *args, **kwargs):
94
+ metadata = kwargs.pop('metadata', self.metadata)
95
+ return self.f(*args, **kwargs, metadata=metadata)
95
96
 
96
- def future(self, *args, **kwargs):
97
- metadata = kwargs.pop('metadata', self.metadata)
98
- return self.f.future(*args, **kwargs, metadata=metadata)
97
+ def future(self, *args, **kwargs):
98
+ metadata = kwargs.pop('metadata', self.metadata)
99
+ return self.f.future(*args, **kwargs, metadata=metadata)
99
100
 
100
- def __getattr__(self, name):
101
- return getattr(self.f, name)
101
+ def __getattr__(self, name):
102
+ return getattr(self.f, name)
102
103
 
103
104
 
104
105
  class RetryStub(V2Stub):
105
- """
106
- V2Stub proxy that retries requests (currently on unavailable server or throttle codes)
107
- """
106
+ """
107
+ V2Stub proxy that retries requests (currently on unavailable server or throttle codes)
108
+ """
108
109
 
109
- def __init__(self, stub, max_attempts=10, backoff_time=5):
110
- self.stub = stub
111
- self.max_attempts = max_attempts
112
- self.backoff_time = backoff_time
110
+ def __init__(self, stub, max_attempts=10, backoff_time=5):
111
+ self.stub = stub
112
+ self.max_attempts = max_attempts
113
+ self.backoff_time = backoff_time
113
114
 
114
- def __getattr__(self, name):
115
- value = getattr(self.stub, name)
116
- if isinstance(value, RpcCallable):
117
- value = _RetryRpcCallable(value, self.max_attempts, self.backoff_time)
118
- return value
115
+ def __getattr__(self, name):
116
+ value = getattr(self.stub, name)
117
+ if isinstance(value, RpcCallable):
118
+ value = _RetryRpcCallable(value, self.max_attempts, self.backoff_time)
119
+ return value
119
120
 
120
121
 
121
122
  class _RetryRpcCallable(RpcCallable):
122
- """Retries rpc calls on unavailable server or throttle codes"""
123
-
124
- def __init__(self, func, max_attempts, backoff_time):
125
- self.f = func
126
- self.max_attempts = max_attempts
127
- self.backoff_time = backoff_time
128
-
129
- def __repr__(self):
130
- return repr(self.f)
131
-
132
- def __call__(self, *args, **kwargs):
133
- attempt = 0
134
- while attempt < self.max_attempts:
135
- attempt += 1
136
- if attempt != 1:
137
- time.sleep(self.backoff_time) # TODO better backoff between attempts
138
- try:
139
- response = self.f(*args, **kwargs)
140
- v = validate_response(response, attempt, self.max_attempts)
141
- if v is not None:
142
- return v
143
- except grpc.RpcError as e:
144
- if (e.code() in retry_codes_grpc) and attempt < self.max_attempts:
145
- logger.debug('Retrying with status %s' % e.code())
146
- else:
147
- raise
148
-
149
- def future(self, *args, **kwargs):
150
- # TODO use single result event loop thread with asyncio
151
- return _threadpool.submit(self, *args, **kwargs)
152
-
153
- def __getattr__(self, name):
154
- return getattr(self.f, name)
123
+ """Retries rpc calls on unavailable server or throttle codes"""
124
+
125
+ def __init__(self, func, max_attempts, backoff_time):
126
+ self.f = func
127
+ self.max_attempts = max_attempts
128
+ self.backoff_time = backoff_time
129
+
130
+ def __repr__(self):
131
+ return repr(self.f)
132
+
133
+ def __call__(self, *args, **kwargs):
134
+ attempt = 0
135
+ while attempt < self.max_attempts:
136
+ attempt += 1
137
+ if attempt != 1:
138
+ time.sleep(self.backoff_time) # TODO better backoff between attempts
139
+ try:
140
+ response = self.f(*args, **kwargs)
141
+ v = validate_response(response, attempt, self.max_attempts)
142
+ if v is not None:
143
+ return v
144
+ except grpc.RpcError as e:
145
+ if (e.code() in retry_codes_grpc) and attempt < self.max_attempts:
146
+ logger.debug('Retrying with status %s' % e.code())
147
+ else:
148
+ raise
149
+
150
+ def future(self, *args, **kwargs):
151
+ # TODO use single result event loop thread with asyncio
152
+ return _threadpool.submit(self, *args, **kwargs)
153
+
154
+ def __getattr__(self, name):
155
+ return getattr(self.f, name)
clarifai/client/base.py CHANGED
@@ -15,186 +15,193 @@ from clarifai.utils.misc import get_from_dict_or_env
15
15
 
16
16
 
17
17
  class BaseClient:
18
- """BaseClient is the base class for all the classes interacting with Clarifai endpoints.
19
-
20
- Args:
21
- **kwargs: Additional keyword arguments to be passed to the ClarifaiAuthHelper.
22
- - user_id (str): A user ID for authentication.
23
- - app_id (str): An app ID for the application to interact with.
24
- - pat (str): A personal access token for authentication.
25
- - token (str): A session token for authentication. Accepts either a session token or a pat.
26
- - base (str): The base URL for the API endpoint. Defaults to 'https://api.clarifai.com'.
27
- - ui (str): The URL for the UI. Defaults to 'https://clarifai.com'.
28
- - root_certificates_path (str): Path to the SSL root certificates file, used to establish secure gRPC connections.
29
-
30
-
31
- Attributes:
32
- auth_helper (ClarifaiAuthHelper): An instance of ClarifaiAuthHelper for authentication.
33
- STUB (Stub): The gRPC Stub object for API interaction.
34
- metadata (tuple): The gRPC metadata containing the personal access token.
35
- userDataObject (UserAppIDSet): The protobuf object representing user and app IDs.
36
- base (str): The base URL for the API endpoint.
37
- """
38
-
39
- def __init__(self, **kwargs):
40
- token, pat = "", ""
41
- try:
42
- pat = get_from_dict_or_env(key="pat", env_key=CLARIFAI_PAT_ENV_VAR, **kwargs)
43
- except UserError:
44
- token = get_from_dict_or_env(key="token", env_key=CLARIFAI_SESSION_TOKEN_ENV_VAR, **kwargs)
45
- finally:
46
- assert token or pat, Exception(
47
- "Need 'pat' or 'token' in args or use one of the CLARIFAI_PAT or CLARIFAI_SESSION_TOKEN env vars"
48
- )
49
- kwargs.update({'token': token, 'pat': pat})
50
-
51
- self.auth_helper = ClarifaiAuthHelper(**kwargs, validate=False)
52
- self.STUB = create_stub(self.auth_helper)
53
- self.metadata = self.auth_helper.metadata
54
- self.pat = self.auth_helper.pat
55
- self.token = self.auth_helper._token
56
- self.user_app_id = self.auth_helper.get_user_app_id_proto()
57
- self.base = self.auth_helper.base
58
- self.root_certificates_path = self.auth_helper._root_certificates_path
59
-
60
- @classmethod
61
- def from_env(cls, validate: bool = False):
62
- auth = ClarifaiAuthHelper.from_env(validate=validate)
63
- return cls.from_auth_helper(auth)
64
-
65
- @classmethod
66
- def from_auth_helper(cls, auth: ClarifaiAuthHelper, **kwargs):
67
- default_kwargs = {
68
- "user_id":
69
- kwargs.get("user_id", None) or auth.user_id,
70
- "app_id":
71
- kwargs.get("app_id", None) or auth.app_id,
72
- "pat":
73
- kwargs.get("pat", None) or auth.pat,
74
- "token":
75
- kwargs.get("token", None) or auth._token,
76
- "root_certificates_path":
77
- kwargs.get("root_certificates_path", None) or auth._root_certificates_path
78
- }
79
- _base = kwargs.get("base", None) or auth.base
80
- _clss = cls.__mro__[0]
81
- if _clss == BaseClient:
82
- kwargs = {
83
- **default_kwargs,
84
- "base": _base, # Baseclient uses `base`
85
- "ui": kwargs.get("ui", None) or auth.ui
86
- }
87
- else:
88
- # Remove user_id and app_id if a custom URL is provided
89
- if kwargs.get("url"):
90
- default_kwargs.pop("user_id", "")
91
- default_kwargs.pop("app_id", "")
92
- # Remove app_id if the class name is a compute orchestration resource
93
- if any(co_resource in _clss.__name__ for co_resource in COMPUTE_ORCHESTRATION_RESOURCES):
94
- default_kwargs.pop("app_id", "")
95
- kwargs.update({**default_kwargs, "base_url": _base})
96
-
97
- return cls(**kwargs)
98
-
99
- def _grpc_request(self, method: Callable, argument: Any):
100
- """Makes a gRPC request to the API.
18
+ """BaseClient is the base class for all the classes interacting with Clarifai endpoints.
101
19
 
102
20
  Args:
103
- method (Callable): The gRPC method to call.
104
- argument (Any): The argument to pass to the gRPC method.
105
-
106
- Returns:
107
- res (Any): The result of the gRPC method call.
108
- """
109
-
110
- try:
111
- res = method(argument, metadata=self.auth_helper.metadata)
112
- # MessageToDict(res) TODO global debug logger
113
- return res
114
- except ApiError:
115
- raise Exception("ApiError")
116
-
117
- def convert_string_to_timestamp(self, date_str) -> Timestamp:
118
- """Converts a string to a Timestamp object.
119
-
120
- Args:
121
- date_str (str): The string to convert.
122
-
123
- Returns:
124
- Timestamp: The converted Timestamp object.
21
+ **kwargs: Additional keyword arguments to be passed to the ClarifaiAuthHelper.
22
+ - user_id (str): A user ID for authentication.
23
+ - app_id (str): An app ID for the application to interact with.
24
+ - pat (str): A personal access token for authentication.
25
+ - token (str): A session token for authentication. Accepts either a session token or a pat.
26
+ - base (str): The base URL for the API endpoint. Defaults to 'https://api.clarifai.com'.
27
+ - ui (str): The URL for the UI. Defaults to 'https://clarifai.com'.
28
+ - root_certificates_path (str): Path to the SSL root certificates file, used to establish secure gRPC connections.
29
+
30
+
31
+ Attributes:
32
+ auth_helper (ClarifaiAuthHelper): An instance of ClarifaiAuthHelper for authentication.
33
+ STUB (Stub): The gRPC Stub object for API interaction.
34
+ metadata (tuple): The gRPC metadata containing the personal access token.
35
+ userDataObject (UserAppIDSet): The protobuf object representing user and app IDs.
36
+ base (str): The base URL for the API endpoint.
125
37
  """
126
- # Parse the string into a Python datetime object
127
- try:
128
- datetime_obj = datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%fZ')
129
- except ValueError:
130
- try:
131
- datetime_obj = datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%SZ')
132
- except ValueError:
133
- return Timestamp()
134
38
 
135
- # Convert the datetime object to a Timestamp object
136
- timestamp_obj = Timestamp()
137
- timestamp_obj.FromDatetime(datetime_obj)
138
-
139
- return timestamp_obj
140
-
141
- def process_response_keys(self, old_dict, listing_resource=None):
142
- """Converts keys in a response dictionary to resource proto format.
143
-
144
- Args:
145
- old_dict (dict): The dictionary to convert.
146
-
147
- Returns:
148
- new_dict (dict): The dictionary with processed keys.
149
- """
150
- if listing_resource:
151
- old_dict[f'{listing_resource}_id'] = old_dict['id']
152
- old_dict.pop('id')
153
-
154
- def convert_recursive(item):
155
- if isinstance(item, dict):
156
- new_item = {}
157
- for key, value in item.items():
158
- if key == 'default_value':
159
- # Map infer param value to proto value
160
- value_map = dict(number_value=None, string_value=None, bool_value=None)
161
-
162
- def map_fn(v):
163
- return 'number_value' if isinstance(v, float) or isinstance(v, int) else \
164
- 'string_value' if isinstance(v, str) else \
165
- 'bool_value' if isinstance(v, bool) else None
166
-
167
- value_map[map_fn(value)] = value
168
- value = struct_pb2.Value(**value_map)
169
- if key in ['created_at', 'modified_at', 'completed_at']:
170
- value = self.convert_string_to_timestamp(value)
171
- elif key in ['workflow_recommended', 'is_template']:
172
- value = BoolValue(value=True)
173
- elif key in ['fields_map', 'params']:
174
- value_s = struct_pb2.Struct()
175
- value_s.update(value)
176
- value = value_s
177
- elif key == 'metrics':
178
- continue
179
- elif key == 'size':
180
- value = int(value)
181
- elif key == 'image_info':
182
- value = resources_pb2.ImageInfo(**value)
183
- elif key == 'hosted_image_info':
184
- continue
185
- elif key in ['metadata', 'presets']:
186
- if isinstance(value, dict) and value != {}:
187
- value_s = struct_pb2.Struct()
188
- value_s.update(value)
189
- value = value_s
39
+ def __init__(self, **kwargs):
40
+ token, pat = "", ""
41
+ try:
42
+ pat = get_from_dict_or_env(key="pat", env_key=CLARIFAI_PAT_ENV_VAR, **kwargs)
43
+ except UserError:
44
+ token = get_from_dict_or_env(
45
+ key="token", env_key=CLARIFAI_SESSION_TOKEN_ENV_VAR, **kwargs
46
+ )
47
+ finally:
48
+ assert token or pat, Exception(
49
+ "Need 'pat' or 'token' in args or use one of the CLARIFAI_PAT or CLARIFAI_SESSION_TOKEN env vars"
50
+ )
51
+ kwargs.update({'token': token, 'pat': pat})
52
+
53
+ self.auth_helper = ClarifaiAuthHelper(**kwargs, validate=False)
54
+ self.STUB = create_stub(self.auth_helper)
55
+ self.metadata = self.auth_helper.metadata
56
+ self.pat = self.auth_helper.pat
57
+ self.token = self.auth_helper._token
58
+ self.user_app_id = self.auth_helper.get_user_app_id_proto()
59
+ self.base = self.auth_helper.base
60
+ self.root_certificates_path = self.auth_helper._root_certificates_path
61
+
62
+ @classmethod
63
+ def from_env(cls, validate: bool = False):
64
+ auth = ClarifaiAuthHelper.from_env(validate=validate)
65
+ return cls.from_auth_helper(auth)
66
+
67
+ @classmethod
68
+ def from_auth_helper(cls, auth: ClarifaiAuthHelper, **kwargs):
69
+ default_kwargs = {
70
+ "user_id": kwargs.get("user_id", None) or auth.user_id,
71
+ "app_id": kwargs.get("app_id", None) or auth.app_id,
72
+ "pat": kwargs.get("pat", None) or auth.pat,
73
+ "token": kwargs.get("token", None) or auth._token,
74
+ "root_certificates_path": kwargs.get("root_certificates_path", None)
75
+ or auth._root_certificates_path,
76
+ }
77
+ _base = kwargs.get("base", None) or auth.base
78
+ _clss = cls.__mro__[0]
79
+ if _clss == BaseClient:
80
+ kwargs = {
81
+ **default_kwargs,
82
+ "base": _base, # Baseclient uses `base`
83
+ "ui": kwargs.get("ui", None) or auth.ui,
84
+ }
85
+ else:
86
+ # Remove user_id and app_id if a custom URL is provided
87
+ if kwargs.get("url"):
88
+ default_kwargs.pop("user_id", "")
89
+ default_kwargs.pop("app_id", "")
90
+ # Remove app_id if the class name is a compute orchestration resource
91
+ if any(
92
+ co_resource in _clss.__name__ for co_resource in COMPUTE_ORCHESTRATION_RESOURCES
93
+ ):
94
+ default_kwargs.pop("app_id", "")
95
+ kwargs.update({**default_kwargs, "base_url": _base})
96
+
97
+ return cls(**kwargs)
98
+
99
+ def _grpc_request(self, method: Callable, argument: Any):
100
+ """Makes a gRPC request to the API.
101
+
102
+ Args:
103
+ method (Callable): The gRPC method to call.
104
+ argument (Any): The argument to pass to the gRPC method.
105
+
106
+ Returns:
107
+ res (Any): The result of the gRPC method call.
108
+ """
109
+
110
+ try:
111
+ res = method(argument, metadata=self.auth_helper.metadata)
112
+ # MessageToDict(res) TODO global debug logger
113
+ return res
114
+ except ApiError:
115
+ raise Exception("ApiError")
116
+
117
+ def convert_string_to_timestamp(self, date_str) -> Timestamp:
118
+ """Converts a string to a Timestamp object.
119
+
120
+ Args:
121
+ date_str (str): The string to convert.
122
+
123
+ Returns:
124
+ Timestamp: The converted Timestamp object.
125
+ """
126
+ # Parse the string into a Python datetime object
127
+ try:
128
+ datetime_obj = datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%fZ')
129
+ except ValueError:
130
+ try:
131
+ datetime_obj = datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%SZ')
132
+ except ValueError:
133
+ return Timestamp()
134
+
135
+ # Convert the datetime object to a Timestamp object
136
+ timestamp_obj = Timestamp()
137
+ timestamp_obj.FromDatetime(datetime_obj)
138
+
139
+ return timestamp_obj
140
+
141
+ def process_response_keys(self, old_dict, listing_resource=None):
142
+ """Converts keys in a response dictionary to resource proto format.
143
+
144
+ Args:
145
+ old_dict (dict): The dictionary to convert.
146
+ listing_resource (str, optional): The resource type for which the keys are being processed.
147
+
148
+ Returns:
149
+ new_dict (dict): The dictionary with processed keys.
150
+ """
151
+ if listing_resource:
152
+ old_dict[f'{listing_resource}_id'] = old_dict['id']
153
+ old_dict.pop('id')
154
+
155
+ def convert_recursive(item):
156
+ if isinstance(item, dict):
157
+ new_item = {}
158
+ for key, value in item.items():
159
+ if key == 'default_value':
160
+ # Map infer param value to proto value
161
+ value_map = dict(number_value=None, string_value=None, bool_value=None)
162
+
163
+ def map_fn(v):
164
+ return (
165
+ 'number_value'
166
+ if isinstance(v, float) or isinstance(v, int)
167
+ else 'string_value'
168
+ if isinstance(v, str)
169
+ else 'bool_value'
170
+ if isinstance(v, bool)
171
+ else None
172
+ )
173
+
174
+ value_map[map_fn(value)] = value
175
+ value = struct_pb2.Value(**value_map)
176
+ if key in ['created_at', 'modified_at', 'completed_at']:
177
+ value = self.convert_string_to_timestamp(value)
178
+ elif key in ['workflow_recommended', 'is_template']:
179
+ value = BoolValue(value=True)
180
+ elif key in ['fields_map', 'params']:
181
+ value_s = struct_pb2.Struct()
182
+ value_s.update(value)
183
+ value = value_s
184
+ elif key == 'metrics':
185
+ continue
186
+ elif key == 'size':
187
+ value = int(value)
188
+ elif key == 'image_info':
189
+ value = resources_pb2.ImageInfo(**value)
190
+ elif key == 'hosted_image_info':
191
+ continue
192
+ elif key in ['metadata', 'presets']:
193
+ if isinstance(value, dict) and value != {}:
194
+ value_s = struct_pb2.Struct()
195
+ value_s.update(value)
196
+ value = value_s
197
+ else:
198
+ continue
199
+ new_item[key] = convert_recursive(value)
200
+ return new_item
201
+ elif isinstance(item, list):
202
+ return [convert_recursive(element) for element in item]
190
203
  else:
191
- continue
192
- new_item[key] = convert_recursive(value)
193
- return new_item
194
- elif isinstance(item, list):
195
- return [convert_recursive(element) for element in item]
196
- else:
197
- return item
198
-
199
- new_dict = convert_recursive(old_dict)
200
- return new_dict
204
+ return item
205
+
206
+ new_dict = convert_recursive(old_dict)
207
+ return new_dict