truss 0.10.0rc1__py3-none-any.whl → 0.60.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.

Potentially problematic release.


This version of truss might be problematic. Click here for more details.

Files changed (362) hide show
  1. truss/__init__.py +10 -3
  2. truss/api/__init__.py +123 -0
  3. truss/api/definitions.py +51 -0
  4. truss/base/constants.py +116 -0
  5. truss/base/custom_types.py +29 -0
  6. truss/{errors.py → base/errors.py} +4 -0
  7. truss/base/trt_llm_config.py +310 -0
  8. truss/{truss_config.py → base/truss_config.py} +344 -31
  9. truss/{truss_spec.py → base/truss_spec.py} +20 -6
  10. truss/{validation.py → base/validation.py} +60 -11
  11. truss/cli/cli.py +841 -88
  12. truss/{remote → cli}/remote_cli.py +2 -7
  13. truss/contexts/docker_build_setup.py +67 -0
  14. truss/contexts/image_builder/cache_warmer.py +2 -8
  15. truss/contexts/image_builder/image_builder.py +1 -1
  16. truss/contexts/image_builder/serving_image_builder.py +292 -46
  17. truss/contexts/image_builder/util.py +1 -3
  18. truss/contexts/local_loader/docker_build_emulator.py +58 -0
  19. truss/contexts/local_loader/load_model_local.py +2 -2
  20. truss/contexts/local_loader/truss_module_loader.py +1 -1
  21. truss/contexts/local_loader/utils.py +1 -1
  22. truss/local/local_config.py +2 -6
  23. truss/local/local_config_handler.py +20 -5
  24. truss/patch/__init__.py +1 -0
  25. truss/patch/hash.py +4 -70
  26. truss/patch/signature.py +4 -16
  27. truss/patch/truss_dir_patch_applier.py +3 -78
  28. truss/remote/baseten/api.py +308 -23
  29. truss/remote/baseten/auth.py +3 -3
  30. truss/remote/baseten/core.py +257 -50
  31. truss/remote/baseten/custom_types.py +44 -0
  32. truss/remote/baseten/error.py +4 -0
  33. truss/remote/baseten/remote.py +369 -118
  34. truss/remote/baseten/service.py +118 -11
  35. truss/remote/baseten/utils/status.py +29 -0
  36. truss/remote/baseten/utils/tar.py +34 -22
  37. truss/remote/baseten/utils/transfer.py +36 -23
  38. truss/remote/remote_factory.py +14 -5
  39. truss/remote/truss_remote.py +72 -45
  40. truss/templates/base.Dockerfile.jinja +18 -16
  41. truss/templates/cache.Dockerfile.jinja +3 -3
  42. truss/{server → templates/control}/control/application.py +14 -35
  43. truss/{server → templates/control}/control/endpoints.py +39 -9
  44. truss/{server/control/patch/types.py → templates/control/control/helpers/custom_types.py} +13 -52
  45. truss/{server → templates/control}/control/helpers/inference_server_controller.py +4 -8
  46. truss/{server → templates/control}/control/helpers/inference_server_process_controller.py +2 -4
  47. truss/{server → templates/control}/control/helpers/inference_server_starter.py +5 -10
  48. truss/{server/control → templates/control/control/helpers}/truss_patch/model_code_patch_applier.py +8 -6
  49. truss/{server/control/patch → templates/control/control/helpers/truss_patch}/model_container_patch_applier.py +18 -26
  50. truss/templates/control/control/helpers/truss_patch/requirement_name_identifier.py +66 -0
  51. truss/{server → templates/control}/control/server.py +11 -6
  52. truss/templates/control/requirements.txt +9 -0
  53. truss/templates/custom_python_dx/my_model.py +28 -0
  54. truss/templates/docker_server/proxy.conf.jinja +42 -0
  55. truss/templates/docker_server/supervisord.conf.jinja +27 -0
  56. truss/templates/docker_server_requirements.txt +1 -0
  57. truss/templates/server/common/errors.py +231 -0
  58. truss/{server → templates/server}/common/patches/whisper/patch.py +1 -0
  59. truss/{server/common/patches/__init__.py → templates/server/common/patches.py} +1 -3
  60. truss/{server → templates/server}/common/retry.py +1 -0
  61. truss/{server → templates/server}/common/schema.py +11 -9
  62. truss/templates/server/common/tracing.py +157 -0
  63. truss/templates/server/main.py +9 -0
  64. truss/templates/server/model_wrapper.py +961 -0
  65. truss/templates/server/requirements.txt +21 -0
  66. truss/templates/server/truss_server.py +447 -0
  67. truss/templates/server.Dockerfile.jinja +62 -14
  68. truss/templates/shared/dynamic_config_resolver.py +28 -0
  69. truss/templates/shared/lazy_data_resolver.py +164 -0
  70. truss/templates/shared/log_config.py +125 -0
  71. truss/{server → templates}/shared/secrets_resolver.py +1 -2
  72. truss/{server → templates}/shared/serialization.py +31 -9
  73. truss/{server → templates}/shared/util.py +3 -13
  74. truss/templates/trtllm-audio/model/model.py +49 -0
  75. truss/templates/trtllm-audio/packages/sigint_patch.py +14 -0
  76. truss/templates/trtllm-audio/packages/whisper_trt/__init__.py +215 -0
  77. truss/templates/trtllm-audio/packages/whisper_trt/assets.py +25 -0
  78. truss/templates/trtllm-audio/packages/whisper_trt/batching.py +52 -0
  79. truss/templates/trtllm-audio/packages/whisper_trt/custom_types.py +26 -0
  80. truss/templates/trtllm-audio/packages/whisper_trt/modeling.py +184 -0
  81. truss/templates/trtllm-audio/packages/whisper_trt/tokenizer.py +185 -0
  82. truss/templates/trtllm-audio/packages/whisper_trt/utils.py +245 -0
  83. truss/templates/trtllm-briton/src/extension.py +64 -0
  84. truss/tests/conftest.py +302 -94
  85. truss/tests/contexts/image_builder/test_serving_image_builder.py +74 -31
  86. truss/tests/contexts/local_loader/test_load_local.py +2 -2
  87. truss/tests/contexts/local_loader/test_truss_module_finder.py +1 -1
  88. truss/tests/patch/test_calc_patch.py +439 -127
  89. truss/tests/patch/test_dir_signature.py +3 -12
  90. truss/tests/patch/test_hash.py +1 -1
  91. truss/tests/patch/test_signature.py +1 -1
  92. truss/tests/patch/test_truss_dir_patch_applier.py +23 -11
  93. truss/tests/patch/test_types.py +2 -2
  94. truss/tests/remote/baseten/test_api.py +153 -58
  95. truss/tests/remote/baseten/test_auth.py +2 -1
  96. truss/tests/remote/baseten/test_core.py +160 -12
  97. truss/tests/remote/baseten/test_remote.py +489 -77
  98. truss/tests/remote/baseten/test_service.py +55 -0
  99. truss/tests/remote/test_remote_factory.py +16 -18
  100. truss/tests/remote/test_truss_remote.py +26 -17
  101. truss/tests/templates/control/control/helpers/test_context_managers.py +11 -0
  102. truss/tests/templates/control/control/helpers/test_model_container_patch_applier.py +184 -0
  103. truss/tests/templates/control/control/helpers/test_requirement_name_identifier.py +89 -0
  104. truss/tests/{server → templates/control}/control/test_server.py +79 -24
  105. truss/tests/{server → templates/control}/control/test_server_integration.py +24 -16
  106. truss/tests/templates/core/server/test_dynamic_config_resolver.py +108 -0
  107. truss/tests/templates/core/server/test_lazy_data_resolver.py +329 -0
  108. truss/tests/templates/core/server/test_lazy_data_resolver_v2.py +79 -0
  109. truss/tests/{server → templates}/core/server/test_secrets_resolver.py +1 -1
  110. truss/tests/{server → templates/server}/common/test_retry.py +3 -3
  111. truss/tests/templates/server/test_model_wrapper.py +248 -0
  112. truss/tests/{server → templates/server}/test_schema.py +3 -5
  113. truss/tests/{server/core/server/common → templates/server}/test_truss_server.py +8 -5
  114. truss/tests/test_build.py +9 -52
  115. truss/tests/test_config.py +336 -77
  116. truss/tests/test_context_builder_image.py +3 -11
  117. truss/tests/test_control_truss_patching.py +7 -12
  118. truss/tests/test_custom_server.py +38 -0
  119. truss/tests/test_data/context_builder_image_test/test.py +3 -0
  120. truss/tests/test_data/happy.ipynb +56 -0
  121. truss/tests/test_data/model_load_failure_test/config.yaml +2 -0
  122. truss/tests/test_data/model_load_failure_test/model/__init__.py +0 -0
  123. truss/tests/test_data/patch_ping_test_server/__init__.py +0 -0
  124. truss/{test_data → tests/test_data}/patch_ping_test_server/app.py +3 -9
  125. truss/{test_data → tests/test_data}/server.Dockerfile +20 -21
  126. truss/tests/test_data/server_conformance_test_truss/__init__.py +0 -0
  127. truss/tests/test_data/server_conformance_test_truss/model/__init__.py +0 -0
  128. truss/{test_data → tests/test_data}/server_conformance_test_truss/model/model.py +1 -3
  129. truss/tests/test_data/test_async_truss/__init__.py +0 -0
  130. truss/tests/test_data/test_async_truss/model/__init__.py +0 -0
  131. truss/tests/test_data/test_basic_truss/__init__.py +0 -0
  132. truss/tests/test_data/test_basic_truss/config.yaml +16 -0
  133. truss/tests/test_data/test_basic_truss/model/__init__.py +0 -0
  134. truss/tests/test_data/test_build_commands/__init__.py +0 -0
  135. truss/tests/test_data/test_build_commands/config.yaml +13 -0
  136. truss/tests/test_data/test_build_commands/model/__init__.py +0 -0
  137. truss/{test_data/test_streaming_async_generator_truss → tests/test_data/test_build_commands}/model/model.py +2 -3
  138. truss/tests/test_data/test_build_commands_failure/__init__.py +0 -0
  139. truss/tests/test_data/test_build_commands_failure/config.yaml +14 -0
  140. truss/tests/test_data/test_build_commands_failure/model/__init__.py +0 -0
  141. truss/tests/test_data/test_build_commands_failure/model/model.py +17 -0
  142. truss/tests/test_data/test_concurrency_truss/__init__.py +0 -0
  143. truss/tests/test_data/test_concurrency_truss/config.yaml +4 -0
  144. truss/tests/test_data/test_concurrency_truss/model/__init__.py +0 -0
  145. truss/tests/test_data/test_custom_server_truss/__init__.py +0 -0
  146. truss/tests/test_data/test_custom_server_truss/config.yaml +20 -0
  147. truss/tests/test_data/test_custom_server_truss/test_docker_image/Dockerfile +17 -0
  148. truss/tests/test_data/test_custom_server_truss/test_docker_image/README.md +10 -0
  149. truss/tests/test_data/test_custom_server_truss/test_docker_image/VERSION +1 -0
  150. truss/tests/test_data/test_custom_server_truss/test_docker_image/__init__.py +0 -0
  151. truss/tests/test_data/test_custom_server_truss/test_docker_image/app.py +19 -0
  152. truss/tests/test_data/test_custom_server_truss/test_docker_image/build_upload_new_image.sh +6 -0
  153. truss/tests/test_data/test_openai/__init__.py +0 -0
  154. truss/{test_data/test_basic_truss → tests/test_data/test_openai}/config.yaml +1 -2
  155. truss/tests/test_data/test_openai/model/__init__.py +0 -0
  156. truss/tests/test_data/test_openai/model/model.py +15 -0
  157. truss/tests/test_data/test_pyantic_v1/__init__.py +0 -0
  158. truss/tests/test_data/test_pyantic_v1/model/__init__.py +0 -0
  159. truss/tests/test_data/test_pyantic_v1/model/model.py +28 -0
  160. truss/tests/test_data/test_pyantic_v1/requirements.txt +1 -0
  161. truss/tests/test_data/test_pyantic_v2/__init__.py +0 -0
  162. truss/tests/test_data/test_pyantic_v2/config.yaml +13 -0
  163. truss/tests/test_data/test_pyantic_v2/model/__init__.py +0 -0
  164. truss/tests/test_data/test_pyantic_v2/model/model.py +30 -0
  165. truss/tests/test_data/test_pyantic_v2/requirements.txt +1 -0
  166. truss/tests/test_data/test_requirements_file_truss/__init__.py +0 -0
  167. truss/tests/test_data/test_requirements_file_truss/config.yaml +13 -0
  168. truss/tests/test_data/test_requirements_file_truss/model/__init__.py +0 -0
  169. truss/{test_data → tests/test_data}/test_requirements_file_truss/model/model.py +1 -0
  170. truss/tests/test_data/test_streaming_async_generator_truss/__init__.py +0 -0
  171. truss/tests/test_data/test_streaming_async_generator_truss/config.yaml +4 -0
  172. truss/tests/test_data/test_streaming_async_generator_truss/model/__init__.py +0 -0
  173. truss/tests/test_data/test_streaming_async_generator_truss/model/model.py +7 -0
  174. truss/tests/test_data/test_streaming_read_timeout/__init__.py +0 -0
  175. truss/tests/test_data/test_streaming_read_timeout/model/__init__.py +0 -0
  176. truss/tests/test_data/test_streaming_truss/__init__.py +0 -0
  177. truss/tests/test_data/test_streaming_truss/config.yaml +4 -0
  178. truss/tests/test_data/test_streaming_truss/model/__init__.py +0 -0
  179. truss/tests/test_data/test_streaming_truss_with_error/__init__.py +0 -0
  180. truss/tests/test_data/test_streaming_truss_with_error/model/__init__.py +0 -0
  181. truss/{test_data → tests/test_data}/test_streaming_truss_with_error/model/model.py +3 -11
  182. truss/tests/test_data/test_streaming_truss_with_error/packages/__init__.py +0 -0
  183. truss/tests/test_data/test_streaming_truss_with_error/packages/helpers_1.py +5 -0
  184. truss/tests/test_data/test_streaming_truss_with_error/packages/helpers_2.py +2 -0
  185. truss/tests/test_data/test_streaming_truss_with_tracing/__init__.py +0 -0
  186. truss/tests/test_data/test_streaming_truss_with_tracing/config.yaml +43 -0
  187. truss/tests/test_data/test_streaming_truss_with_tracing/model/__init__.py +0 -0
  188. truss/tests/test_data/test_streaming_truss_with_tracing/model/model.py +65 -0
  189. truss/tests/test_data/test_trt_llm_truss/__init__.py +0 -0
  190. truss/tests/test_data/test_trt_llm_truss/config.yaml +15 -0
  191. truss/tests/test_data/test_trt_llm_truss/model/__init__.py +0 -0
  192. truss/tests/test_data/test_trt_llm_truss/model/model.py +15 -0
  193. truss/tests/test_data/test_truss/__init__.py +0 -0
  194. truss/tests/test_data/test_truss/config.yaml +4 -0
  195. truss/tests/test_data/test_truss/model/__init__.py +0 -0
  196. truss/tests/test_data/test_truss/model/dummy +0 -0
  197. truss/tests/test_data/test_truss/packages/__init__.py +0 -0
  198. truss/tests/test_data/test_truss/packages/test_package/__init__.py +0 -0
  199. truss/tests/test_data/test_truss_server_caching_truss/__init__.py +0 -0
  200. truss/tests/test_data/test_truss_server_caching_truss/model/__init__.py +0 -0
  201. truss/tests/test_data/test_truss_with_error/__init__.py +0 -0
  202. truss/tests/test_data/test_truss_with_error/config.yaml +4 -0
  203. truss/tests/test_data/test_truss_with_error/model/__init__.py +0 -0
  204. truss/tests/test_data/test_truss_with_error/model/model.py +8 -0
  205. truss/tests/test_data/test_truss_with_error/packages/__init__.py +0 -0
  206. truss/tests/test_data/test_truss_with_error/packages/helpers_1.py +5 -0
  207. truss/tests/test_data/test_truss_with_error/packages/helpers_2.py +2 -0
  208. truss/tests/test_docker.py +2 -1
  209. truss/tests/test_model_inference.py +1340 -292
  210. truss/tests/test_model_schema.py +33 -26
  211. truss/tests/test_testing_utilities_for_other_tests.py +50 -5
  212. truss/tests/test_truss_gatherer.py +3 -5
  213. truss/tests/test_truss_handle.py +62 -59
  214. truss/tests/test_util.py +2 -1
  215. truss/tests/test_validation.py +15 -13
  216. truss/tests/trt_llm/test_trt_llm_config.py +41 -0
  217. truss/tests/trt_llm/test_validation.py +91 -0
  218. truss/tests/util/test_config_checks.py +40 -0
  219. truss/tests/util/test_env_vars.py +14 -0
  220. truss/tests/util/test_path.py +10 -23
  221. truss/trt_llm/config_checks.py +43 -0
  222. truss/trt_llm/validation.py +42 -0
  223. truss/truss_handle/__init__.py +0 -0
  224. truss/truss_handle/build.py +122 -0
  225. truss/{decorators.py → truss_handle/decorators.py} +1 -1
  226. truss/truss_handle/patch/__init__.py +0 -0
  227. truss/{patch → truss_handle/patch}/calc_patch.py +146 -92
  228. truss/{types.py → truss_handle/patch/custom_types.py} +35 -27
  229. truss/{patch → truss_handle/patch}/dir_signature.py +1 -1
  230. truss/truss_handle/patch/hash.py +71 -0
  231. truss/{patch → truss_handle/patch}/local_truss_patch_applier.py +6 -4
  232. truss/truss_handle/patch/signature.py +22 -0
  233. truss/truss_handle/patch/truss_dir_patch_applier.py +87 -0
  234. truss/{readme_generator.py → truss_handle/readme_generator.py} +3 -2
  235. truss/{truss_gatherer.py → truss_handle/truss_gatherer.py} +3 -2
  236. truss/{truss_handle.py → truss_handle/truss_handle.py} +174 -78
  237. truss/util/.truss_ignore +3 -0
  238. truss/{docker.py → util/docker.py} +6 -2
  239. truss/util/download.py +6 -15
  240. truss/util/env_vars.py +41 -0
  241. truss/util/log_utils.py +52 -0
  242. truss/util/path.py +20 -20
  243. truss/util/requirements.py +11 -0
  244. {truss-0.10.0rc1.dist-info → truss-0.60.0.dist-info}/METADATA +18 -16
  245. truss-0.60.0.dist-info/RECORD +324 -0
  246. {truss-0.10.0rc1.dist-info → truss-0.60.0.dist-info}/WHEEL +1 -1
  247. truss-0.60.0.dist-info/entry_points.txt +4 -0
  248. truss_chains/__init__.py +71 -0
  249. truss_chains/definitions.py +756 -0
  250. truss_chains/deployment/__init__.py +0 -0
  251. truss_chains/deployment/code_gen.py +816 -0
  252. truss_chains/deployment/deployment_client.py +871 -0
  253. truss_chains/framework.py +1480 -0
  254. truss_chains/public_api.py +231 -0
  255. truss_chains/py.typed +0 -0
  256. truss_chains/pydantic_numpy.py +131 -0
  257. truss_chains/reference_code/reference_chainlet.py +34 -0
  258. truss_chains/reference_code/reference_model.py +10 -0
  259. truss_chains/remote_chainlet/__init__.py +0 -0
  260. truss_chains/remote_chainlet/model_skeleton.py +60 -0
  261. truss_chains/remote_chainlet/stub.py +380 -0
  262. truss_chains/remote_chainlet/utils.py +332 -0
  263. truss_chains/streaming.py +378 -0
  264. truss_chains/utils.py +178 -0
  265. CODE_OF_CONDUCT.md +0 -131
  266. CONTRIBUTING.md +0 -48
  267. README.md +0 -137
  268. context_builder.Dockerfile +0 -24
  269. truss/blob/blob_backend.py +0 -10
  270. truss/blob/blob_backend_registry.py +0 -23
  271. truss/blob/http_public_blob_backend.py +0 -23
  272. truss/build/__init__.py +0 -2
  273. truss/build/build.py +0 -143
  274. truss/build/configure.py +0 -63
  275. truss/cli/__init__.py +0 -2
  276. truss/cli/console.py +0 -5
  277. truss/cli/create.py +0 -5
  278. truss/config/trt_llm.py +0 -81
  279. truss/constants.py +0 -61
  280. truss/model_inference.py +0 -123
  281. truss/patch/types.py +0 -30
  282. truss/pytest.ini +0 -7
  283. truss/server/common/errors.py +0 -100
  284. truss/server/common/termination_handler_middleware.py +0 -64
  285. truss/server/common/truss_server.py +0 -389
  286. truss/server/control/patch/model_code_patch_applier.py +0 -46
  287. truss/server/control/patch/requirement_name_identifier.py +0 -17
  288. truss/server/inference_server.py +0 -29
  289. truss/server/model_wrapper.py +0 -434
  290. truss/server/shared/logging.py +0 -81
  291. truss/templates/trtllm/model/model.py +0 -97
  292. truss/templates/trtllm/packages/build_engine_utils.py +0 -34
  293. truss/templates/trtllm/packages/constants.py +0 -11
  294. truss/templates/trtllm/packages/schema.py +0 -216
  295. truss/templates/trtllm/packages/tensorrt_llm_model_repository/ensemble/config.pbtxt +0 -246
  296. truss/templates/trtllm/packages/tensorrt_llm_model_repository/postprocessing/1/model.py +0 -181
  297. truss/templates/trtllm/packages/tensorrt_llm_model_repository/postprocessing/config.pbtxt +0 -64
  298. truss/templates/trtllm/packages/tensorrt_llm_model_repository/preprocessing/1/model.py +0 -260
  299. truss/templates/trtllm/packages/tensorrt_llm_model_repository/preprocessing/config.pbtxt +0 -99
  300. truss/templates/trtllm/packages/tensorrt_llm_model_repository/tensorrt_llm/config.pbtxt +0 -208
  301. truss/templates/trtllm/packages/triton_client.py +0 -150
  302. truss/templates/trtllm/packages/utils.py +0 -43
  303. truss/test_data/context_builder_image_test/test.py +0 -4
  304. truss/test_data/happy.ipynb +0 -54
  305. truss/test_data/model_load_failure_test/config.yaml +0 -2
  306. truss/test_data/test_concurrency_truss/config.yaml +0 -2
  307. truss/test_data/test_streaming_async_generator_truss/config.yaml +0 -2
  308. truss/test_data/test_streaming_truss/config.yaml +0 -3
  309. truss/test_data/test_truss/config.yaml +0 -2
  310. truss/tests/server/common/test_termination_handler_middleware.py +0 -93
  311. truss/tests/server/control/test_model_container_patch_applier.py +0 -203
  312. truss/tests/server/core/server/common/test_util.py +0 -19
  313. truss/tests/server/test_model_wrapper.py +0 -87
  314. truss/util/data_structures.py +0 -16
  315. truss-0.10.0rc1.dist-info/RECORD +0 -216
  316. truss-0.10.0rc1.dist-info/entry_points.txt +0 -3
  317. truss/{server/shared → base}/__init__.py +0 -0
  318. truss/{server → templates/control}/control/helpers/context_managers.py +0 -0
  319. truss/{server/control → templates/control/control/helpers}/errors.py +0 -0
  320. truss/{server/control/patch → templates/control/control/helpers/truss_patch}/__init__.py +0 -0
  321. truss/{server/control/patch → templates/control/control/helpers/truss_patch}/system_packages.py +0 -0
  322. truss/{test_data/annotated_types_truss/model → templates/server}/__init__.py +0 -0
  323. truss/{server → templates/server}/common/__init__.py +0 -0
  324. truss/{test_data/gcs_fix/model → templates/shared}/__init__.py +0 -0
  325. truss/templates/{trtllm → trtllm-briton}/README.md +0 -0
  326. truss/{test_data/server_conformance_test_truss/model → tests/test_data}/__init__.py +0 -0
  327. truss/{test_data/test_basic_truss/model → tests/test_data/annotated_types_truss}/__init__.py +0 -0
  328. truss/{test_data → tests/test_data}/annotated_types_truss/config.yaml +0 -0
  329. truss/{test_data/test_requirements_file_truss → tests/test_data/annotated_types_truss}/model/__init__.py +0 -0
  330. truss/{test_data → tests/test_data}/annotated_types_truss/model/model.py +0 -0
  331. truss/{test_data → tests/test_data}/auto-mpg.data +0 -0
  332. truss/{test_data → tests/test_data}/context_builder_image_test/Dockerfile +0 -0
  333. truss/{test_data/test_truss/model → tests/test_data/context_builder_image_test}/__init__.py +0 -0
  334. truss/{test_data/test_truss_server_caching_truss/model → tests/test_data/gcs_fix}/__init__.py +0 -0
  335. truss/{test_data → tests/test_data}/gcs_fix/config.yaml +0 -0
  336. truss/tests/{local → test_data/gcs_fix/model}/__init__.py +0 -0
  337. truss/{test_data → tests/test_data}/gcs_fix/model/model.py +0 -0
  338. truss/{test_data/test_truss/model/dummy → tests/test_data/model_load_failure_test/__init__.py} +0 -0
  339. truss/{test_data → tests/test_data}/model_load_failure_test/model/model.py +0 -0
  340. truss/{test_data → tests/test_data}/pima-indians-diabetes.csv +0 -0
  341. truss/{test_data → tests/test_data}/readme_int_example.md +0 -0
  342. truss/{test_data → tests/test_data}/readme_no_example.md +0 -0
  343. truss/{test_data → tests/test_data}/readme_str_example.md +0 -0
  344. truss/{test_data → tests/test_data}/server_conformance_test_truss/config.yaml +0 -0
  345. truss/{test_data → tests/test_data}/test_async_truss/config.yaml +0 -0
  346. truss/{test_data → tests/test_data}/test_async_truss/model/model.py +3 -3
  347. /truss/{test_data → tests/test_data}/test_basic_truss/model/model.py +0 -0
  348. /truss/{test_data → tests/test_data}/test_concurrency_truss/model/model.py +0 -0
  349. /truss/{test_data/test_requirements_file_truss → tests/test_data/test_pyantic_v1}/config.yaml +0 -0
  350. /truss/{test_data → tests/test_data}/test_requirements_file_truss/requirements.txt +0 -0
  351. /truss/{test_data → tests/test_data}/test_streaming_read_timeout/config.yaml +0 -0
  352. /truss/{test_data → tests/test_data}/test_streaming_read_timeout/model/model.py +0 -0
  353. /truss/{test_data → tests/test_data}/test_streaming_truss/model/model.py +0 -0
  354. /truss/{test_data → tests/test_data}/test_streaming_truss_with_error/config.yaml +0 -0
  355. /truss/{test_data → tests/test_data}/test_truss/examples.yaml +0 -0
  356. /truss/{test_data → tests/test_data}/test_truss/model/model.py +0 -0
  357. /truss/{test_data → tests/test_data}/test_truss/packages/test_package/test.py +0 -0
  358. /truss/{test_data → tests/test_data}/test_truss_server_caching_truss/config.yaml +0 -0
  359. /truss/{test_data → tests/test_data}/test_truss_server_caching_truss/model/model.py +0 -0
  360. /truss/{patch → truss_handle/patch}/constants.py +0 -0
  361. /truss/{notebook.py → util/notebook.py} +0 -0
  362. {truss-0.10.0rc1.dist-info → truss-0.60.0.dist-info}/LICENSE +0 -0
@@ -1,43 +1,103 @@
1
1
  import logging
2
2
  from enum import Enum
3
- from typing import Optional
3
+ from typing import Any, List, Optional
4
4
 
5
5
  import requests
6
- from truss.remote.baseten.auth import AuthService
6
+ import truss
7
+ from truss.remote.baseten import custom_types as b10_types
8
+ from truss.remote.baseten.auth import ApiKey, AuthService
7
9
  from truss.remote.baseten.error import ApiError
8
10
  from truss.remote.baseten.utils.transfer import base64_encoded_json_str
9
11
 
10
12
  logger = logging.getLogger(__name__)
11
13
 
14
+ API_URL_MAPPING = {
15
+ "https://app.baseten.co": "https://api.baseten.co",
16
+ "https://app.staging.baseten.co": "https://api.staging.baseten.co",
17
+ "https://app.dev.baseten.co": "https://api.mc-dev.baseten.co",
18
+ # For local development, this is how we map URLs
19
+ "http://localhost:8000": "http://api.localhost:8000",
20
+ }
21
+
22
+ # If a non-standard domain is used with the baseten remote, default to
23
+ # using the production api routes
24
+ DEFAULT_API_DOMAIN = "https://api.baseten.co"
25
+
26
+
27
+ def _oracle_data_to_graphql_mutation(oracle: b10_types.OracleData) -> str:
28
+ args = [
29
+ f'model_name: "{oracle.model_name}"',
30
+ f's3_key: "{oracle.s3_key}"',
31
+ f'encoded_config_str: "{oracle.encoded_config_str}"',
32
+ f"is_trusted: {str(oracle.is_trusted).lower()}",
33
+ ]
34
+
35
+ if oracle.semver_bump:
36
+ args.append(f'semver_bump: "{oracle.semver_bump}"')
37
+
38
+ if oracle.version_name:
39
+ args.append(f'version_name: "{oracle.version_name}"')
40
+
41
+ args_str = ",\n".join(args)
42
+
43
+ return f"""{{
44
+ {args_str}
45
+ }}"""
12
46
 
13
- class BasetenApi:
14
- """
15
- A client for the Baseten API.
16
47
 
17
- Args:
18
- api_url: The URL of the Baseten API.
19
- auth_service: An AuthService instance.
20
- """
48
+ def _chainlet_data_atomic_to_graphql_mutation(
49
+ chainlet: b10_types.ChainletDataAtomic,
50
+ ) -> str:
51
+ oracle_data_string = _oracle_data_to_graphql_mutation(chainlet.oracle)
21
52
 
53
+ args = [f'name: "{chainlet.name}"', f"oracle: {oracle_data_string}"]
54
+
55
+ args_str = ",\n".join(args)
56
+
57
+ return f"""{{
58
+ {args_str}
59
+ }}"""
60
+
61
+
62
+ class BasetenApi:
22
63
  class GraphQLErrorCodes(Enum):
23
64
  RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND"
24
65
 
25
- def __init__(self, api_url: str, auth_service: AuthService):
26
- self._api_url = api_url
66
+ def __init__(self, remote_url: str, auth_service: AuthService) -> None:
67
+ graphql_api_url = f"{remote_url}/graphql/"
68
+ # Ensure we strip off trailing '/' to denormalize URLs.
69
+ rest_api_url = API_URL_MAPPING.get(remote_url.strip("/"), DEFAULT_API_DOMAIN)
70
+
71
+ self._remote_url = remote_url
72
+ self._graphql_api_url = graphql_api_url
73
+ self._rest_api_url = rest_api_url
27
74
  self._auth_service = auth_service
28
75
  self._auth_token = self._auth_service.authenticate()
29
76
 
77
+ @property
78
+ def app_url(self) -> str:
79
+ return self._remote_url
80
+
81
+ @property
82
+ def rest_api_url(self) -> str:
83
+ return self._rest_api_url
84
+
85
+ @property
86
+ def auth_token(self) -> ApiKey:
87
+ return self._auth_token
88
+
30
89
  def _post_graphql_query(self, query_string: str) -> dict:
31
90
  headers = self._auth_token.header()
91
+
32
92
  resp = requests.post(
33
- self._api_url,
93
+ self._graphql_api_url,
34
94
  data={"query": query_string},
35
95
  headers=headers,
36
96
  timeout=120,
37
97
  )
38
98
 
39
99
  if not resp.ok:
40
- logger.error(f"GraphQL endpoint failed with error: {resp.content}") # type: ignore
100
+ logger.error(f"GraphQL endpoint failed with error: {str(resp.content)}")
41
101
  resp.raise_for_status()
42
102
 
43
103
  resp_dict = resp.json()
@@ -73,7 +133,9 @@ class BasetenApi:
73
133
  semver_bump: str,
74
134
  client_version: str,
75
135
  is_trusted: bool,
136
+ allow_truss_download: bool = True,
76
137
  deployment_name: Optional[str] = None,
138
+ origin: Optional[b10_types.ModelOrigin] = None,
77
139
  ):
78
140
  query_string = f"""
79
141
  mutation {{
@@ -83,8 +145,10 @@ class BasetenApi:
83
145
  config: "{config}",
84
146
  semver_bump: "{semver_bump}",
85
147
  client_version: "{client_version}",
86
- is_trusted: {'true' if is_trusted else 'false'},
148
+ is_trusted: {"true" if is_trusted else "false"},
149
+ allow_truss_download: {"true" if allow_truss_download else "false"},
87
150
  {f'version_name: "{deployment_name}"' if deployment_name else ""}
151
+ {f"model_origin: {origin.value}" if origin else ""}
88
152
  ) {{
89
153
  id,
90
154
  name,
@@ -92,6 +156,7 @@ class BasetenApi:
92
156
  }}
93
157
  }}
94
158
  """
159
+
95
160
  resp = self._post_graphql_query(query_string)
96
161
  return resp["data"]["create_model_from_truss"]
97
162
 
@@ -103,9 +168,9 @@ class BasetenApi:
103
168
  semver_bump: str,
104
169
  client_version: str,
105
170
  is_trusted: bool,
106
- promote: bool = False,
107
171
  preserve_previous_prod_deployment: bool = False,
108
172
  deployment_name: Optional[str] = None,
173
+ environment: Optional[str] = None,
109
174
  ):
110
175
  query_string = f"""
111
176
  mutation {{
@@ -115,15 +180,16 @@ class BasetenApi:
115
180
  config: "{config}",
116
181
  semver_bump: "{semver_bump}",
117
182
  client_version: "{client_version}",
118
- is_trusted: {'true' if is_trusted else 'false'},
119
- promote_after_deploy: {'true' if promote else 'false'},
120
- scale_down_old_production: {'false' if preserve_previous_prod_deployment else 'true'},
183
+ is_trusted: {"true" if is_trusted else "false"},
184
+ scale_down_old_production: {"false" if preserve_previous_prod_deployment else "true"},
121
185
  {f'name: "{deployment_name}"' if deployment_name else ""}
186
+ {f'environment_name: "{environment}"' if environment else ""}
122
187
  ) {{
123
188
  id
124
189
  }}
125
190
  }}
126
191
  """
192
+
127
193
  resp = self._post_graphql_query(query_string)
128
194
  return resp["data"]["create_model_version_from_truss"]
129
195
 
@@ -134,6 +200,8 @@ class BasetenApi:
134
200
  config,
135
201
  client_version,
136
202
  is_trusted=False,
203
+ allow_truss_download=True,
204
+ origin: Optional[b10_types.ModelOrigin] = None,
137
205
  ):
138
206
  query_string = f"""
139
207
  mutation {{
@@ -141,7 +209,9 @@ class BasetenApi:
141
209
  s3_key: "{s3_key}",
142
210
  config: "{config}",
143
211
  client_version: "{client_version}",
144
- is_trusted: {'true' if is_trusted else 'false'}
212
+ is_trusted: {"true" if is_trusted else "false"},
213
+ allow_truss_download: {"true" if allow_truss_download else "false"},
214
+ {f"model_origin: {origin.value}" if origin else ""}
145
215
  ) {{
146
216
  id,
147
217
  name,
@@ -152,6 +222,127 @@ class BasetenApi:
152
222
  resp = self._post_graphql_query(query_string)
153
223
  return resp["data"]["deploy_draft_truss"]
154
224
 
225
+ def deploy_chain_atomic(
226
+ self,
227
+ entrypoint: b10_types.ChainletDataAtomic,
228
+ dependencies: List[b10_types.ChainletDataAtomic],
229
+ chain_id: Optional[str] = None,
230
+ chain_name: Optional[str] = None,
231
+ environment: Optional[str] = None,
232
+ is_draft: bool = False,
233
+ ):
234
+ entrypoint_str = _chainlet_data_atomic_to_graphql_mutation(entrypoint)
235
+
236
+ dependencies_str = ", ".join(
237
+ [
238
+ _chainlet_data_atomic_to_graphql_mutation(dependency)
239
+ for dependency in dependencies
240
+ ]
241
+ )
242
+
243
+ query_string = f"""
244
+ mutation {{
245
+ deploy_chain_atomic(
246
+ {f'chain_id: "{chain_id}"' if chain_id else ""}
247
+ {f'chain_name: "{chain_name}"' if chain_name else ""}
248
+ {f'environment: "{environment}"' if environment else ""}
249
+ is_draft: {str(is_draft).lower()}
250
+ entrypoint: {entrypoint_str}
251
+ dependencies: [{dependencies_str}]
252
+ client_version: "{truss.version()}"
253
+ ) {{
254
+ chain_id
255
+ chain_deployment_id
256
+ entrypoint_model_id
257
+ entrypoint_model_version_id
258
+ }}
259
+ }}
260
+ """
261
+
262
+ resp = self._post_graphql_query(query_string)
263
+
264
+ return resp["data"]["deploy_chain_atomic"]
265
+
266
+ def get_chains(self):
267
+ query_string = """
268
+ {
269
+ chains {
270
+ id
271
+ name
272
+ }
273
+ }
274
+ """
275
+
276
+ resp = self._post_graphql_query(query_string)
277
+ return resp["data"]["chains"]
278
+
279
+ def get_chain_deployments(self, chain_id: str):
280
+ query_string = f"""
281
+ {{
282
+ chain(id: "{chain_id}") {{
283
+ deployments {{
284
+ id
285
+ created
286
+ is_draft
287
+ }}
288
+ }}
289
+ }}
290
+ """
291
+ resp = self._post_graphql_query(query_string)
292
+ return resp["data"]["chain"]["deployments"]
293
+
294
+ def get_chainlets_by_deployment_id(self, chain_deployment_id: str):
295
+ query_string = f"""
296
+ {{
297
+ chain_deployment(id:"{chain_deployment_id}") {{
298
+ chainlets {{
299
+ name
300
+ id
301
+ is_entrypoint
302
+ oracle {{
303
+ id
304
+ name
305
+ }}
306
+ oracle_version {{
307
+ id
308
+ is_draft
309
+ current_model_deployment_status {{
310
+ status
311
+ }}
312
+ }}
313
+ }}
314
+ chain {{
315
+ id
316
+ }}
317
+ }}
318
+ }}
319
+ """
320
+ resp = self._post_graphql_query(query_string)
321
+ chainlets = resp["data"]["chain_deployment"]["chainlets"]
322
+ for chainlet in chainlets:
323
+ chainlet["chain"] = {"id": resp["data"]["chain_deployment"]["chain"]["id"]}
324
+ return chainlets
325
+
326
+ def delete_chain(self, chain_id: str) -> Any:
327
+ url = f"{self._rest_api_url}/v1/chains/{chain_id}"
328
+ headers = self._auth_token.header()
329
+ resp = requests.delete(url, headers=headers)
330
+ if not resp.ok:
331
+ resp.raise_for_status()
332
+
333
+ deployment = resp.json()
334
+ return deployment
335
+
336
+ def delete_chain_deployment(self, chain_id: str, chain_deployment_id: str) -> Any:
337
+ url = f"{self._rest_api_url}/v1/chains/{chain_id}/deployments/{chain_deployment_id}"
338
+ headers = self._auth_token.header()
339
+ resp = requests.delete(url, headers=headers)
340
+ if not resp.ok:
341
+ resp.raise_for_status()
342
+
343
+ deployment = resp.json()
344
+ return deployment
345
+
155
346
  def models(self):
156
347
  query_string = """
157
348
  {
@@ -171,6 +362,25 @@ class BasetenApi:
171
362
  resp = self._post_graphql_query(query_string)
172
363
  return resp["data"]
173
364
 
365
+ def get_truss_watch_state(self, model_name: str):
366
+ query_string = f"""
367
+ {{
368
+ truss_watch_state(name: "{model_name}") {{
369
+ is_container_built_from_push
370
+ django_patch_state {{
371
+ current_hash
372
+ current_signature
373
+ }}
374
+ container_patch_state {{
375
+ current_hash
376
+ current_signature
377
+ }}
378
+ }}
379
+ }}
380
+ """
381
+ resp = self._post_graphql_query(query_string)
382
+ return resp["data"]
383
+
174
384
  def get_model(self, model_name):
175
385
  query_string = f"""
176
386
  {{
@@ -221,8 +431,12 @@ class BasetenApi:
221
431
  {{
222
432
  model_version(id: "{model_version_id}") {{
223
433
  id
434
+ is_draft
435
+ truss_hash
436
+ truss_signature
224
437
  oracle{{
225
438
  id
439
+ name
226
440
  }}
227
441
  }}
228
442
  }}
@@ -230,12 +444,12 @@ class BasetenApi:
230
444
  resp = self._post_graphql_query(query_string)
231
445
  return resp["data"]
232
446
 
233
- def patch_draft_truss(self, model_name, patch_request):
447
+ def patch_draft_truss_two_step(self, model_name, patch_request):
234
448
  patch = base64_encoded_json_str(patch_request.to_dict())
235
449
  query_string = f"""
236
450
  mutation {{
237
- patch_draft_truss(name: "{model_name}",
238
- client_version: "TRUSS",
451
+ stage_patch_for_draft_truss(name: "{model_name}",
452
+ client_version: "{truss.version()}",
239
453
  patch: "{patch}",
240
454
  ) {{
241
455
  id,
@@ -248,4 +462,75 @@ class BasetenApi:
248
462
  }}
249
463
  """
250
464
  resp = self._post_graphql_query(query_string)
251
- return resp["data"]["patch_draft_truss"]
465
+ result = resp["data"]["stage_patch_for_draft_truss"]
466
+ if not result["succeeded"]:
467
+ logging.debug(f"Failed to stage patch: {result}")
468
+ return result
469
+ logging.debug("Succesfully staged patch. Syncing patch to truss...")
470
+
471
+ return self.sync_draft_truss(model_name)
472
+
473
+ def sync_draft_truss(self, model_name):
474
+ query_string = f"""
475
+ mutation {{
476
+ sync_draft_truss(name: "{model_name}",
477
+ client_version: "{truss.version()}",
478
+ ) {{
479
+ id,
480
+ name,
481
+ version_id
482
+ succeeded
483
+ needs_full_deploy
484
+ error
485
+ }}
486
+ }}
487
+ """
488
+ resp = self._post_graphql_query(query_string)
489
+ result = resp["data"]["sync_draft_truss"]
490
+ if not result["succeeded"]:
491
+ logging.debug(f"Failed to sync patch: {result}")
492
+ return result
493
+
494
+ def validate_truss(self, client_version: str, config: str):
495
+ query_string = f"""{{
496
+ truss_validation(client_version: "{client_version}", config: "{config}") {{
497
+ success
498
+ details
499
+ }}
500
+ }}
501
+ """
502
+ resp = self._post_graphql_query(query_string)
503
+ return resp["data"]["truss_validation"]
504
+
505
+ def get_deployment(self, model_id: str, deployment_id: str) -> Any:
506
+ headers = self._auth_token.header()
507
+ resp = requests.get(
508
+ f"{self._rest_api_url}/v1/models/{model_id}/deployments/{deployment_id}",
509
+ headers=headers,
510
+ )
511
+ if not resp.ok:
512
+ resp.raise_for_status()
513
+
514
+ deployment = resp.json()
515
+ return deployment
516
+
517
+ def upsert_secret(self, name: str, value: str) -> Any:
518
+ headers = self._auth_token.header()
519
+ data = {"name": name, "value": value}
520
+ resp = requests.post(
521
+ f"{self._rest_api_url}/v1/secrets", headers=headers, json=data
522
+ )
523
+ if not resp.ok:
524
+ resp.raise_for_status()
525
+
526
+ secret_info = resp.json()
527
+ return secret_info
528
+
529
+ def get_all_secrets(self) -> Any:
530
+ headers = self._auth_token.header()
531
+ resp = requests.get(f"{self._rest_api_url}/v1/secrets", headers=headers)
532
+ if not resp.ok:
533
+ resp.raise_for_status()
534
+
535
+ secrets_info = resp.json()
536
+ return secrets_info
@@ -10,7 +10,7 @@ logger = logging.getLogger(__name__)
10
10
  class ApiKey:
11
11
  value: str
12
12
 
13
- def __init__(self, value: str):
13
+ def __init__(self, value: str) -> None:
14
14
  self.value = value
15
15
 
16
16
  def header(self):
@@ -18,12 +18,12 @@ class ApiKey:
18
18
 
19
19
 
20
20
  class AuthService:
21
- def __init__(self, api_key: Optional[str] = None):
21
+ def __init__(self, api_key: Optional[str] = None) -> None:
22
22
  if not api_key:
23
23
  api_key = os.environ.get("BASETEN_API_KEY", None)
24
24
  self._api_key = api_key
25
25
 
26
- def validate(self):
26
+ def validate(self) -> None:
27
27
  if not self._api_key:
28
28
  raise AuthorizationError("No API key provided.")
29
29