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.
- truss/__init__.py +10 -3
- truss/api/__init__.py +123 -0
- truss/api/definitions.py +51 -0
- truss/base/constants.py +116 -0
- truss/base/custom_types.py +29 -0
- truss/{errors.py → base/errors.py} +4 -0
- truss/base/trt_llm_config.py +310 -0
- truss/{truss_config.py → base/truss_config.py} +344 -31
- truss/{truss_spec.py → base/truss_spec.py} +20 -6
- truss/{validation.py → base/validation.py} +60 -11
- truss/cli/cli.py +841 -88
- truss/{remote → cli}/remote_cli.py +2 -7
- truss/contexts/docker_build_setup.py +67 -0
- truss/contexts/image_builder/cache_warmer.py +2 -8
- truss/contexts/image_builder/image_builder.py +1 -1
- truss/contexts/image_builder/serving_image_builder.py +292 -46
- truss/contexts/image_builder/util.py +1 -3
- truss/contexts/local_loader/docker_build_emulator.py +58 -0
- truss/contexts/local_loader/load_model_local.py +2 -2
- truss/contexts/local_loader/truss_module_loader.py +1 -1
- truss/contexts/local_loader/utils.py +1 -1
- truss/local/local_config.py +2 -6
- truss/local/local_config_handler.py +20 -5
- truss/patch/__init__.py +1 -0
- truss/patch/hash.py +4 -70
- truss/patch/signature.py +4 -16
- truss/patch/truss_dir_patch_applier.py +3 -78
- truss/remote/baseten/api.py +308 -23
- truss/remote/baseten/auth.py +3 -3
- truss/remote/baseten/core.py +257 -50
- truss/remote/baseten/custom_types.py +44 -0
- truss/remote/baseten/error.py +4 -0
- truss/remote/baseten/remote.py +369 -118
- truss/remote/baseten/service.py +118 -11
- truss/remote/baseten/utils/status.py +29 -0
- truss/remote/baseten/utils/tar.py +34 -22
- truss/remote/baseten/utils/transfer.py +36 -23
- truss/remote/remote_factory.py +14 -5
- truss/remote/truss_remote.py +72 -45
- truss/templates/base.Dockerfile.jinja +18 -16
- truss/templates/cache.Dockerfile.jinja +3 -3
- truss/{server → templates/control}/control/application.py +14 -35
- truss/{server → templates/control}/control/endpoints.py +39 -9
- truss/{server/control/patch/types.py → templates/control/control/helpers/custom_types.py} +13 -52
- truss/{server → templates/control}/control/helpers/inference_server_controller.py +4 -8
- truss/{server → templates/control}/control/helpers/inference_server_process_controller.py +2 -4
- truss/{server → templates/control}/control/helpers/inference_server_starter.py +5 -10
- truss/{server/control → templates/control/control/helpers}/truss_patch/model_code_patch_applier.py +8 -6
- truss/{server/control/patch → templates/control/control/helpers/truss_patch}/model_container_patch_applier.py +18 -26
- truss/templates/control/control/helpers/truss_patch/requirement_name_identifier.py +66 -0
- truss/{server → templates/control}/control/server.py +11 -6
- truss/templates/control/requirements.txt +9 -0
- truss/templates/custom_python_dx/my_model.py +28 -0
- truss/templates/docker_server/proxy.conf.jinja +42 -0
- truss/templates/docker_server/supervisord.conf.jinja +27 -0
- truss/templates/docker_server_requirements.txt +1 -0
- truss/templates/server/common/errors.py +231 -0
- truss/{server → templates/server}/common/patches/whisper/patch.py +1 -0
- truss/{server/common/patches/__init__.py → templates/server/common/patches.py} +1 -3
- truss/{server → templates/server}/common/retry.py +1 -0
- truss/{server → templates/server}/common/schema.py +11 -9
- truss/templates/server/common/tracing.py +157 -0
- truss/templates/server/main.py +9 -0
- truss/templates/server/model_wrapper.py +961 -0
- truss/templates/server/requirements.txt +21 -0
- truss/templates/server/truss_server.py +447 -0
- truss/templates/server.Dockerfile.jinja +62 -14
- truss/templates/shared/dynamic_config_resolver.py +28 -0
- truss/templates/shared/lazy_data_resolver.py +164 -0
- truss/templates/shared/log_config.py +125 -0
- truss/{server → templates}/shared/secrets_resolver.py +1 -2
- truss/{server → templates}/shared/serialization.py +31 -9
- truss/{server → templates}/shared/util.py +3 -13
- truss/templates/trtllm-audio/model/model.py +49 -0
- truss/templates/trtllm-audio/packages/sigint_patch.py +14 -0
- truss/templates/trtllm-audio/packages/whisper_trt/__init__.py +215 -0
- truss/templates/trtllm-audio/packages/whisper_trt/assets.py +25 -0
- truss/templates/trtllm-audio/packages/whisper_trt/batching.py +52 -0
- truss/templates/trtllm-audio/packages/whisper_trt/custom_types.py +26 -0
- truss/templates/trtllm-audio/packages/whisper_trt/modeling.py +184 -0
- truss/templates/trtllm-audio/packages/whisper_trt/tokenizer.py +185 -0
- truss/templates/trtllm-audio/packages/whisper_trt/utils.py +245 -0
- truss/templates/trtllm-briton/src/extension.py +64 -0
- truss/tests/conftest.py +302 -94
- truss/tests/contexts/image_builder/test_serving_image_builder.py +74 -31
- truss/tests/contexts/local_loader/test_load_local.py +2 -2
- truss/tests/contexts/local_loader/test_truss_module_finder.py +1 -1
- truss/tests/patch/test_calc_patch.py +439 -127
- truss/tests/patch/test_dir_signature.py +3 -12
- truss/tests/patch/test_hash.py +1 -1
- truss/tests/patch/test_signature.py +1 -1
- truss/tests/patch/test_truss_dir_patch_applier.py +23 -11
- truss/tests/patch/test_types.py +2 -2
- truss/tests/remote/baseten/test_api.py +153 -58
- truss/tests/remote/baseten/test_auth.py +2 -1
- truss/tests/remote/baseten/test_core.py +160 -12
- truss/tests/remote/baseten/test_remote.py +489 -77
- truss/tests/remote/baseten/test_service.py +55 -0
- truss/tests/remote/test_remote_factory.py +16 -18
- truss/tests/remote/test_truss_remote.py +26 -17
- truss/tests/templates/control/control/helpers/test_context_managers.py +11 -0
- truss/tests/templates/control/control/helpers/test_model_container_patch_applier.py +184 -0
- truss/tests/templates/control/control/helpers/test_requirement_name_identifier.py +89 -0
- truss/tests/{server → templates/control}/control/test_server.py +79 -24
- truss/tests/{server → templates/control}/control/test_server_integration.py +24 -16
- truss/tests/templates/core/server/test_dynamic_config_resolver.py +108 -0
- truss/tests/templates/core/server/test_lazy_data_resolver.py +329 -0
- truss/tests/templates/core/server/test_lazy_data_resolver_v2.py +79 -0
- truss/tests/{server → templates}/core/server/test_secrets_resolver.py +1 -1
- truss/tests/{server → templates/server}/common/test_retry.py +3 -3
- truss/tests/templates/server/test_model_wrapper.py +248 -0
- truss/tests/{server → templates/server}/test_schema.py +3 -5
- truss/tests/{server/core/server/common → templates/server}/test_truss_server.py +8 -5
- truss/tests/test_build.py +9 -52
- truss/tests/test_config.py +336 -77
- truss/tests/test_context_builder_image.py +3 -11
- truss/tests/test_control_truss_patching.py +7 -12
- truss/tests/test_custom_server.py +38 -0
- truss/tests/test_data/context_builder_image_test/test.py +3 -0
- truss/tests/test_data/happy.ipynb +56 -0
- truss/tests/test_data/model_load_failure_test/config.yaml +2 -0
- truss/tests/test_data/model_load_failure_test/model/__init__.py +0 -0
- truss/tests/test_data/patch_ping_test_server/__init__.py +0 -0
- truss/{test_data → tests/test_data}/patch_ping_test_server/app.py +3 -9
- truss/{test_data → tests/test_data}/server.Dockerfile +20 -21
- truss/tests/test_data/server_conformance_test_truss/__init__.py +0 -0
- truss/tests/test_data/server_conformance_test_truss/model/__init__.py +0 -0
- truss/{test_data → tests/test_data}/server_conformance_test_truss/model/model.py +1 -3
- truss/tests/test_data/test_async_truss/__init__.py +0 -0
- truss/tests/test_data/test_async_truss/model/__init__.py +0 -0
- truss/tests/test_data/test_basic_truss/__init__.py +0 -0
- truss/tests/test_data/test_basic_truss/config.yaml +16 -0
- truss/tests/test_data/test_basic_truss/model/__init__.py +0 -0
- truss/tests/test_data/test_build_commands/__init__.py +0 -0
- truss/tests/test_data/test_build_commands/config.yaml +13 -0
- truss/tests/test_data/test_build_commands/model/__init__.py +0 -0
- truss/{test_data/test_streaming_async_generator_truss → tests/test_data/test_build_commands}/model/model.py +2 -3
- truss/tests/test_data/test_build_commands_failure/__init__.py +0 -0
- truss/tests/test_data/test_build_commands_failure/config.yaml +14 -0
- truss/tests/test_data/test_build_commands_failure/model/__init__.py +0 -0
- truss/tests/test_data/test_build_commands_failure/model/model.py +17 -0
- truss/tests/test_data/test_concurrency_truss/__init__.py +0 -0
- truss/tests/test_data/test_concurrency_truss/config.yaml +4 -0
- truss/tests/test_data/test_concurrency_truss/model/__init__.py +0 -0
- truss/tests/test_data/test_custom_server_truss/__init__.py +0 -0
- truss/tests/test_data/test_custom_server_truss/config.yaml +20 -0
- truss/tests/test_data/test_custom_server_truss/test_docker_image/Dockerfile +17 -0
- truss/tests/test_data/test_custom_server_truss/test_docker_image/README.md +10 -0
- truss/tests/test_data/test_custom_server_truss/test_docker_image/VERSION +1 -0
- truss/tests/test_data/test_custom_server_truss/test_docker_image/__init__.py +0 -0
- truss/tests/test_data/test_custom_server_truss/test_docker_image/app.py +19 -0
- truss/tests/test_data/test_custom_server_truss/test_docker_image/build_upload_new_image.sh +6 -0
- truss/tests/test_data/test_openai/__init__.py +0 -0
- truss/{test_data/test_basic_truss → tests/test_data/test_openai}/config.yaml +1 -2
- truss/tests/test_data/test_openai/model/__init__.py +0 -0
- truss/tests/test_data/test_openai/model/model.py +15 -0
- truss/tests/test_data/test_pyantic_v1/__init__.py +0 -0
- truss/tests/test_data/test_pyantic_v1/model/__init__.py +0 -0
- truss/tests/test_data/test_pyantic_v1/model/model.py +28 -0
- truss/tests/test_data/test_pyantic_v1/requirements.txt +1 -0
- truss/tests/test_data/test_pyantic_v2/__init__.py +0 -0
- truss/tests/test_data/test_pyantic_v2/config.yaml +13 -0
- truss/tests/test_data/test_pyantic_v2/model/__init__.py +0 -0
- truss/tests/test_data/test_pyantic_v2/model/model.py +30 -0
- truss/tests/test_data/test_pyantic_v2/requirements.txt +1 -0
- truss/tests/test_data/test_requirements_file_truss/__init__.py +0 -0
- truss/tests/test_data/test_requirements_file_truss/config.yaml +13 -0
- truss/tests/test_data/test_requirements_file_truss/model/__init__.py +0 -0
- truss/{test_data → tests/test_data}/test_requirements_file_truss/model/model.py +1 -0
- truss/tests/test_data/test_streaming_async_generator_truss/__init__.py +0 -0
- truss/tests/test_data/test_streaming_async_generator_truss/config.yaml +4 -0
- truss/tests/test_data/test_streaming_async_generator_truss/model/__init__.py +0 -0
- truss/tests/test_data/test_streaming_async_generator_truss/model/model.py +7 -0
- truss/tests/test_data/test_streaming_read_timeout/__init__.py +0 -0
- truss/tests/test_data/test_streaming_read_timeout/model/__init__.py +0 -0
- truss/tests/test_data/test_streaming_truss/__init__.py +0 -0
- truss/tests/test_data/test_streaming_truss/config.yaml +4 -0
- truss/tests/test_data/test_streaming_truss/model/__init__.py +0 -0
- truss/tests/test_data/test_streaming_truss_with_error/__init__.py +0 -0
- truss/tests/test_data/test_streaming_truss_with_error/model/__init__.py +0 -0
- truss/{test_data → tests/test_data}/test_streaming_truss_with_error/model/model.py +3 -11
- truss/tests/test_data/test_streaming_truss_with_error/packages/__init__.py +0 -0
- truss/tests/test_data/test_streaming_truss_with_error/packages/helpers_1.py +5 -0
- truss/tests/test_data/test_streaming_truss_with_error/packages/helpers_2.py +2 -0
- truss/tests/test_data/test_streaming_truss_with_tracing/__init__.py +0 -0
- truss/tests/test_data/test_streaming_truss_with_tracing/config.yaml +43 -0
- truss/tests/test_data/test_streaming_truss_with_tracing/model/__init__.py +0 -0
- truss/tests/test_data/test_streaming_truss_with_tracing/model/model.py +65 -0
- truss/tests/test_data/test_trt_llm_truss/__init__.py +0 -0
- truss/tests/test_data/test_trt_llm_truss/config.yaml +15 -0
- truss/tests/test_data/test_trt_llm_truss/model/__init__.py +0 -0
- truss/tests/test_data/test_trt_llm_truss/model/model.py +15 -0
- truss/tests/test_data/test_truss/__init__.py +0 -0
- truss/tests/test_data/test_truss/config.yaml +4 -0
- truss/tests/test_data/test_truss/model/__init__.py +0 -0
- truss/tests/test_data/test_truss/model/dummy +0 -0
- truss/tests/test_data/test_truss/packages/__init__.py +0 -0
- truss/tests/test_data/test_truss/packages/test_package/__init__.py +0 -0
- truss/tests/test_data/test_truss_server_caching_truss/__init__.py +0 -0
- truss/tests/test_data/test_truss_server_caching_truss/model/__init__.py +0 -0
- truss/tests/test_data/test_truss_with_error/__init__.py +0 -0
- truss/tests/test_data/test_truss_with_error/config.yaml +4 -0
- truss/tests/test_data/test_truss_with_error/model/__init__.py +0 -0
- truss/tests/test_data/test_truss_with_error/model/model.py +8 -0
- truss/tests/test_data/test_truss_with_error/packages/__init__.py +0 -0
- truss/tests/test_data/test_truss_with_error/packages/helpers_1.py +5 -0
- truss/tests/test_data/test_truss_with_error/packages/helpers_2.py +2 -0
- truss/tests/test_docker.py +2 -1
- truss/tests/test_model_inference.py +1340 -292
- truss/tests/test_model_schema.py +33 -26
- truss/tests/test_testing_utilities_for_other_tests.py +50 -5
- truss/tests/test_truss_gatherer.py +3 -5
- truss/tests/test_truss_handle.py +62 -59
- truss/tests/test_util.py +2 -1
- truss/tests/test_validation.py +15 -13
- truss/tests/trt_llm/test_trt_llm_config.py +41 -0
- truss/tests/trt_llm/test_validation.py +91 -0
- truss/tests/util/test_config_checks.py +40 -0
- truss/tests/util/test_env_vars.py +14 -0
- truss/tests/util/test_path.py +10 -23
- truss/trt_llm/config_checks.py +43 -0
- truss/trt_llm/validation.py +42 -0
- truss/truss_handle/__init__.py +0 -0
- truss/truss_handle/build.py +122 -0
- truss/{decorators.py → truss_handle/decorators.py} +1 -1
- truss/truss_handle/patch/__init__.py +0 -0
- truss/{patch → truss_handle/patch}/calc_patch.py +146 -92
- truss/{types.py → truss_handle/patch/custom_types.py} +35 -27
- truss/{patch → truss_handle/patch}/dir_signature.py +1 -1
- truss/truss_handle/patch/hash.py +71 -0
- truss/{patch → truss_handle/patch}/local_truss_patch_applier.py +6 -4
- truss/truss_handle/patch/signature.py +22 -0
- truss/truss_handle/patch/truss_dir_patch_applier.py +87 -0
- truss/{readme_generator.py → truss_handle/readme_generator.py} +3 -2
- truss/{truss_gatherer.py → truss_handle/truss_gatherer.py} +3 -2
- truss/{truss_handle.py → truss_handle/truss_handle.py} +174 -78
- truss/util/.truss_ignore +3 -0
- truss/{docker.py → util/docker.py} +6 -2
- truss/util/download.py +6 -15
- truss/util/env_vars.py +41 -0
- truss/util/log_utils.py +52 -0
- truss/util/path.py +20 -20
- truss/util/requirements.py +11 -0
- {truss-0.10.0rc1.dist-info → truss-0.60.0.dist-info}/METADATA +18 -16
- truss-0.60.0.dist-info/RECORD +324 -0
- {truss-0.10.0rc1.dist-info → truss-0.60.0.dist-info}/WHEEL +1 -1
- truss-0.60.0.dist-info/entry_points.txt +4 -0
- truss_chains/__init__.py +71 -0
- truss_chains/definitions.py +756 -0
- truss_chains/deployment/__init__.py +0 -0
- truss_chains/deployment/code_gen.py +816 -0
- truss_chains/deployment/deployment_client.py +871 -0
- truss_chains/framework.py +1480 -0
- truss_chains/public_api.py +231 -0
- truss_chains/py.typed +0 -0
- truss_chains/pydantic_numpy.py +131 -0
- truss_chains/reference_code/reference_chainlet.py +34 -0
- truss_chains/reference_code/reference_model.py +10 -0
- truss_chains/remote_chainlet/__init__.py +0 -0
- truss_chains/remote_chainlet/model_skeleton.py +60 -0
- truss_chains/remote_chainlet/stub.py +380 -0
- truss_chains/remote_chainlet/utils.py +332 -0
- truss_chains/streaming.py +378 -0
- truss_chains/utils.py +178 -0
- CODE_OF_CONDUCT.md +0 -131
- CONTRIBUTING.md +0 -48
- README.md +0 -137
- context_builder.Dockerfile +0 -24
- truss/blob/blob_backend.py +0 -10
- truss/blob/blob_backend_registry.py +0 -23
- truss/blob/http_public_blob_backend.py +0 -23
- truss/build/__init__.py +0 -2
- truss/build/build.py +0 -143
- truss/build/configure.py +0 -63
- truss/cli/__init__.py +0 -2
- truss/cli/console.py +0 -5
- truss/cli/create.py +0 -5
- truss/config/trt_llm.py +0 -81
- truss/constants.py +0 -61
- truss/model_inference.py +0 -123
- truss/patch/types.py +0 -30
- truss/pytest.ini +0 -7
- truss/server/common/errors.py +0 -100
- truss/server/common/termination_handler_middleware.py +0 -64
- truss/server/common/truss_server.py +0 -389
- truss/server/control/patch/model_code_patch_applier.py +0 -46
- truss/server/control/patch/requirement_name_identifier.py +0 -17
- truss/server/inference_server.py +0 -29
- truss/server/model_wrapper.py +0 -434
- truss/server/shared/logging.py +0 -81
- truss/templates/trtllm/model/model.py +0 -97
- truss/templates/trtllm/packages/build_engine_utils.py +0 -34
- truss/templates/trtllm/packages/constants.py +0 -11
- truss/templates/trtllm/packages/schema.py +0 -216
- truss/templates/trtllm/packages/tensorrt_llm_model_repository/ensemble/config.pbtxt +0 -246
- truss/templates/trtllm/packages/tensorrt_llm_model_repository/postprocessing/1/model.py +0 -181
- truss/templates/trtllm/packages/tensorrt_llm_model_repository/postprocessing/config.pbtxt +0 -64
- truss/templates/trtllm/packages/tensorrt_llm_model_repository/preprocessing/1/model.py +0 -260
- truss/templates/trtllm/packages/tensorrt_llm_model_repository/preprocessing/config.pbtxt +0 -99
- truss/templates/trtllm/packages/tensorrt_llm_model_repository/tensorrt_llm/config.pbtxt +0 -208
- truss/templates/trtllm/packages/triton_client.py +0 -150
- truss/templates/trtllm/packages/utils.py +0 -43
- truss/test_data/context_builder_image_test/test.py +0 -4
- truss/test_data/happy.ipynb +0 -54
- truss/test_data/model_load_failure_test/config.yaml +0 -2
- truss/test_data/test_concurrency_truss/config.yaml +0 -2
- truss/test_data/test_streaming_async_generator_truss/config.yaml +0 -2
- truss/test_data/test_streaming_truss/config.yaml +0 -3
- truss/test_data/test_truss/config.yaml +0 -2
- truss/tests/server/common/test_termination_handler_middleware.py +0 -93
- truss/tests/server/control/test_model_container_patch_applier.py +0 -203
- truss/tests/server/core/server/common/test_util.py +0 -19
- truss/tests/server/test_model_wrapper.py +0 -87
- truss/util/data_structures.py +0 -16
- truss-0.10.0rc1.dist-info/RECORD +0 -216
- truss-0.10.0rc1.dist-info/entry_points.txt +0 -3
- truss/{server/shared → base}/__init__.py +0 -0
- truss/{server → templates/control}/control/helpers/context_managers.py +0 -0
- truss/{server/control → templates/control/control/helpers}/errors.py +0 -0
- truss/{server/control/patch → templates/control/control/helpers/truss_patch}/__init__.py +0 -0
- truss/{server/control/patch → templates/control/control/helpers/truss_patch}/system_packages.py +0 -0
- truss/{test_data/annotated_types_truss/model → templates/server}/__init__.py +0 -0
- truss/{server → templates/server}/common/__init__.py +0 -0
- truss/{test_data/gcs_fix/model → templates/shared}/__init__.py +0 -0
- truss/templates/{trtllm → trtllm-briton}/README.md +0 -0
- truss/{test_data/server_conformance_test_truss/model → tests/test_data}/__init__.py +0 -0
- truss/{test_data/test_basic_truss/model → tests/test_data/annotated_types_truss}/__init__.py +0 -0
- truss/{test_data → tests/test_data}/annotated_types_truss/config.yaml +0 -0
- truss/{test_data/test_requirements_file_truss → tests/test_data/annotated_types_truss}/model/__init__.py +0 -0
- truss/{test_data → tests/test_data}/annotated_types_truss/model/model.py +0 -0
- truss/{test_data → tests/test_data}/auto-mpg.data +0 -0
- truss/{test_data → tests/test_data}/context_builder_image_test/Dockerfile +0 -0
- truss/{test_data/test_truss/model → tests/test_data/context_builder_image_test}/__init__.py +0 -0
- truss/{test_data/test_truss_server_caching_truss/model → tests/test_data/gcs_fix}/__init__.py +0 -0
- truss/{test_data → tests/test_data}/gcs_fix/config.yaml +0 -0
- truss/tests/{local → test_data/gcs_fix/model}/__init__.py +0 -0
- truss/{test_data → tests/test_data}/gcs_fix/model/model.py +0 -0
- truss/{test_data/test_truss/model/dummy → tests/test_data/model_load_failure_test/__init__.py} +0 -0
- truss/{test_data → tests/test_data}/model_load_failure_test/model/model.py +0 -0
- truss/{test_data → tests/test_data}/pima-indians-diabetes.csv +0 -0
- truss/{test_data → tests/test_data}/readme_int_example.md +0 -0
- truss/{test_data → tests/test_data}/readme_no_example.md +0 -0
- truss/{test_data → tests/test_data}/readme_str_example.md +0 -0
- truss/{test_data → tests/test_data}/server_conformance_test_truss/config.yaml +0 -0
- truss/{test_data → tests/test_data}/test_async_truss/config.yaml +0 -0
- truss/{test_data → tests/test_data}/test_async_truss/model/model.py +3 -3
- /truss/{test_data → tests/test_data}/test_basic_truss/model/model.py +0 -0
- /truss/{test_data → tests/test_data}/test_concurrency_truss/model/model.py +0 -0
- /truss/{test_data/test_requirements_file_truss → tests/test_data/test_pyantic_v1}/config.yaml +0 -0
- /truss/{test_data → tests/test_data}/test_requirements_file_truss/requirements.txt +0 -0
- /truss/{test_data → tests/test_data}/test_streaming_read_timeout/config.yaml +0 -0
- /truss/{test_data → tests/test_data}/test_streaming_read_timeout/model/model.py +0 -0
- /truss/{test_data → tests/test_data}/test_streaming_truss/model/model.py +0 -0
- /truss/{test_data → tests/test_data}/test_streaming_truss_with_error/config.yaml +0 -0
- /truss/{test_data → tests/test_data}/test_truss/examples.yaml +0 -0
- /truss/{test_data → tests/test_data}/test_truss/model/model.py +0 -0
- /truss/{test_data → tests/test_data}/test_truss/packages/test_package/test.py +0 -0
- /truss/{test_data → tests/test_data}/test_truss_server_caching_truss/config.yaml +0 -0
- /truss/{test_data → tests/test_data}/test_truss_server_caching_truss/model/model.py +0 -0
- /truss/{patch → truss_handle/patch}/constants.py +0 -0
- /truss/{notebook.py → util/notebook.py} +0 -0
- {truss-0.10.0rc1.dist-info → truss-0.60.0.dist-info}/LICENSE +0 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
from typing import (
|
|
3
|
+
TYPE_CHECKING,
|
|
4
|
+
Callable,
|
|
5
|
+
ContextManager,
|
|
6
|
+
Mapping,
|
|
7
|
+
Optional,
|
|
8
|
+
Type,
|
|
9
|
+
Union,
|
|
10
|
+
overload,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
from truss_chains import definitions, framework
|
|
14
|
+
from truss_chains.deployment import deployment_client
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from rich import progress
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def depends_context() -> definitions.DeploymentContext:
|
|
21
|
+
"""Sets a "symbolic marker" for injecting a context object at runtime.
|
|
22
|
+
|
|
23
|
+
Refer to `the docs <https://docs.baseten.co/chains/getting-started>`_ and this
|
|
24
|
+
`example chainlet <https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/example_chainlet.py>`_
|
|
25
|
+
for more guidance on the ``__init__``-signature of chainlets.
|
|
26
|
+
|
|
27
|
+
Warning:
|
|
28
|
+
Despite the type annotation, this does *not* immediately provide a
|
|
29
|
+
context instance. Only when deploying remotely or using ``run_local`` a
|
|
30
|
+
context instance is provided.
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
A "symbolic marker" to be used as a default argument in a chainlet's
|
|
34
|
+
initializer.
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
"""
|
|
38
|
+
# The type error is silenced to because chains framework will at runtime inject
|
|
39
|
+
# a corresponding instance. Nonetheless, we want to use a type annotation here,
|
|
40
|
+
# to facilitate type inference, code-completion and type checking within the code
|
|
41
|
+
# of chainlets that depend on the other chainlet.
|
|
42
|
+
return framework.ContextDependencyMarker() # type: ignore
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def depends(
|
|
46
|
+
chainlet_cls: Type[framework.ChainletT],
|
|
47
|
+
retries: int = 1,
|
|
48
|
+
timeout_sec: float = definitions.DEFAULT_TIMEOUT_SEC,
|
|
49
|
+
use_binary: bool = False,
|
|
50
|
+
) -> framework.ChainletT:
|
|
51
|
+
"""Sets a "symbolic marker" to indicate to the framework that a chainlet is a
|
|
52
|
+
dependency of another chainlet. The return value of ``depends`` is intended to be
|
|
53
|
+
used as a default argument in a chainlet's ``__init__``-method.
|
|
54
|
+
When deploying a chain remotely, a corresponding stub to the remote is injected in
|
|
55
|
+
its place. In ``run_local`` mode an instance of a local chainlet is injected.
|
|
56
|
+
|
|
57
|
+
Refer to `the docs <https://docs.baseten.co/chains/getting-started>`_ and this
|
|
58
|
+
`example chainlet <https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/example_chainlet.py>`_
|
|
59
|
+
for more guidance on how make one chainlet depend on another chainlet.
|
|
60
|
+
|
|
61
|
+
Warning:
|
|
62
|
+
Despite the type annotation, this does *not* immediately provide a
|
|
63
|
+
chainlet instance. Only when deploying remotely or using ``run_local`` a
|
|
64
|
+
chainlet instance is provided.
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
chainlet_cls: The chainlet class of the dependency.
|
|
69
|
+
retries: The number of times to retry the remote chainlet in case of failures
|
|
70
|
+
(e.g. due to transient network issues). For streaming, retries are only made
|
|
71
|
+
if the request fails before streaming any results back. Failures mid-stream
|
|
72
|
+
not retried.
|
|
73
|
+
timeout_sec: Timeout for the HTTP request to this chainlet.
|
|
74
|
+
use_binary: Whether to send data in binary format. This can give a parsing
|
|
75
|
+
speedup and message size reduction (~25%) for numpy arrays. Use
|
|
76
|
+
``NumpyArrayField`` as a field type on pydantic models for integration and set
|
|
77
|
+
this option to ``True``. For simple text data, there is no significant benefit.
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
A "symbolic marker" to be used as a default argument in a chainlet's
|
|
81
|
+
initializer.
|
|
82
|
+
"""
|
|
83
|
+
options = definitions.RPCOptions(
|
|
84
|
+
retries=retries, timeout_sec=timeout_sec, use_binary=use_binary
|
|
85
|
+
)
|
|
86
|
+
# The type error is silenced to because chains framework will at runtime inject
|
|
87
|
+
# a corresponding instance. Nonetheless, we want to use a type annotation here,
|
|
88
|
+
# to facilitate type inference, code-completion and type checking within the code
|
|
89
|
+
# of chainlets that depend on the other chainlet.
|
|
90
|
+
return framework.ChainletDependencyMarker(chainlet_cls, options) # type: ignore
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@overload
|
|
94
|
+
def mark_entrypoint(
|
|
95
|
+
cls_or_chain_name: Type[framework.ChainletT],
|
|
96
|
+
) -> Type[framework.ChainletT]: ...
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@overload
|
|
100
|
+
def mark_entrypoint(
|
|
101
|
+
cls_or_chain_name: str,
|
|
102
|
+
) -> Callable[[Type[framework.ChainletT]], Type[framework.ChainletT]]: ...
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def mark_entrypoint(
|
|
106
|
+
cls_or_chain_name: Union[str, Type[framework.ChainletT]],
|
|
107
|
+
) -> Union[
|
|
108
|
+
Type[framework.ChainletT],
|
|
109
|
+
Callable[[Type[framework.ChainletT]], Type[framework.ChainletT]],
|
|
110
|
+
]:
|
|
111
|
+
"""Decorator to mark a chainlet as the entrypoint of a chain.
|
|
112
|
+
|
|
113
|
+
This decorator can be applied to *one* chainlet in a source file and then the
|
|
114
|
+
CLI push command simplifies: only the file, not the class within, must be specified.
|
|
115
|
+
|
|
116
|
+
Optionally a display name for the Chain (not the Chainlet) can be set (effectively
|
|
117
|
+
giving a custom default value for the `--name` arg of the CLI push command).
|
|
118
|
+
|
|
119
|
+
Example usage::
|
|
120
|
+
|
|
121
|
+
import truss_chains as chains
|
|
122
|
+
|
|
123
|
+
@chains.mark_entrypoint
|
|
124
|
+
class MyChainlet(ChainletBase):
|
|
125
|
+
...
|
|
126
|
+
|
|
127
|
+
# OR with custom Chain name.
|
|
128
|
+
@chains.mark_entrypoint("My Chain Name")
|
|
129
|
+
class MyChainlet(ChainletBase):
|
|
130
|
+
...
|
|
131
|
+
"""
|
|
132
|
+
return framework.entrypoint(cls_or_chain_name)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def push(
|
|
136
|
+
entrypoint: Type[definitions.ABCChainlet],
|
|
137
|
+
chain_name: str,
|
|
138
|
+
publish: bool = True,
|
|
139
|
+
promote: bool = True,
|
|
140
|
+
only_generate_trusses: bool = False,
|
|
141
|
+
remote: str = "baseten",
|
|
142
|
+
environment: Optional[str] = None,
|
|
143
|
+
progress_bar: Optional[Type["progress.Progress"]] = None,
|
|
144
|
+
) -> deployment_client.BasetenChainService:
|
|
145
|
+
"""
|
|
146
|
+
Deploys a chain remotely (with all dependent chainlets).
|
|
147
|
+
|
|
148
|
+
Args:
|
|
149
|
+
entrypoint: The chainlet class that serves as the entrypoint to the chain.
|
|
150
|
+
chain_name: The name of the chain.
|
|
151
|
+
publish: Whether to publish the chain as a published deployment (it is a
|
|
152
|
+
draft deployment otherwise)
|
|
153
|
+
promote: Whether to promote the chain to be the production deployment (this
|
|
154
|
+
implies publishing as well).
|
|
155
|
+
only_generate_trusses: Used for debugging purposes. If set to True, only the
|
|
156
|
+
the underlying truss models for the chainlets are generated in
|
|
157
|
+
``/tmp/.chains_generated``.
|
|
158
|
+
remote: name of a remote config in `.trussrc`. If not provided, it will be
|
|
159
|
+
inquired.
|
|
160
|
+
environment: The name of an environment to promote deployment into.
|
|
161
|
+
progress_bar: Optional `rich.progress.Progress` if output is desired.
|
|
162
|
+
|
|
163
|
+
Returns:
|
|
164
|
+
A chain service handle to the deployed chain.
|
|
165
|
+
|
|
166
|
+
"""
|
|
167
|
+
options = definitions.PushOptionsBaseten.create(
|
|
168
|
+
chain_name=chain_name,
|
|
169
|
+
publish=publish,
|
|
170
|
+
promote=promote,
|
|
171
|
+
only_generate_trusses=only_generate_trusses,
|
|
172
|
+
remote=remote,
|
|
173
|
+
environment=environment,
|
|
174
|
+
)
|
|
175
|
+
service = deployment_client.push(entrypoint, options, progress_bar=progress_bar)
|
|
176
|
+
assert isinstance(
|
|
177
|
+
service, deployment_client.BasetenChainService
|
|
178
|
+
) # Per options above.
|
|
179
|
+
return service
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def run_local(
|
|
183
|
+
secrets: Optional[Mapping[str, str]] = None,
|
|
184
|
+
data_dir: Optional[Union[pathlib.Path, str]] = None,
|
|
185
|
+
chainlet_to_service: Optional[
|
|
186
|
+
Mapping[str, definitions.DeployedServiceDescriptor]
|
|
187
|
+
] = None,
|
|
188
|
+
) -> ContextManager[None]:
|
|
189
|
+
"""Context manager local debug execution of a chain.
|
|
190
|
+
|
|
191
|
+
The arguments only need to be provided if the chainlets explicitly access any the
|
|
192
|
+
corresponding fields of ``DeploymentContext``.
|
|
193
|
+
|
|
194
|
+
Args:
|
|
195
|
+
secrets: A dict of secrets keys and values to provide to the chainlets.
|
|
196
|
+
data_dir: Path to a directory with data files.
|
|
197
|
+
chainlet_to_service: A dict of chainlet names to service descriptors.
|
|
198
|
+
|
|
199
|
+
Example usage (as trailing main section in a chain file)::
|
|
200
|
+
|
|
201
|
+
import os
|
|
202
|
+
import truss_chains as chains
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class HelloWorld(chains.ChainletBase):
|
|
206
|
+
...
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
if __name__ == "__main__":
|
|
210
|
+
with chains.run_local(
|
|
211
|
+
secrets={"some_token": os.environ["SOME_TOKEN"]},
|
|
212
|
+
chainlet_to_service={
|
|
213
|
+
"SomeChainlet": chains.DeployedServiceDescriptor(
|
|
214
|
+
name="SomeChainlet",
|
|
215
|
+
display_name="SomeChainlet",
|
|
216
|
+
predict_url="https://...",
|
|
217
|
+
options=chains.RPCOptions(),
|
|
218
|
+
)
|
|
219
|
+
},
|
|
220
|
+
):
|
|
221
|
+
hello_world_chain = HelloWorld()
|
|
222
|
+
result = hello_world_chain.run_remote(max_value=5)
|
|
223
|
+
|
|
224
|
+
print(result)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
Refer to the `local debugging guide <https://docs.baseten.co/chains/guide#test-a-chain-locally>`_
|
|
228
|
+
for more details.
|
|
229
|
+
"""
|
|
230
|
+
data_dir = pathlib.Path(data_dir) if data_dir else None
|
|
231
|
+
return framework.run_local(secrets or {}, data_dir, chainlet_to_service or {})
|
truss_chains/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
from typing import TYPE_CHECKING, Any, ClassVar
|
|
3
|
+
|
|
4
|
+
import pydantic
|
|
5
|
+
from pydantic.json_schema import JsonSchemaValue
|
|
6
|
+
from pydantic_core import core_schema
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from numpy.typing import NDArray
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class NumpyArrayField:
|
|
13
|
+
"""Wrapper class to support numpy arrays as fields on pydantic models and provide
|
|
14
|
+
JSON or binary serialization implementations.
|
|
15
|
+
|
|
16
|
+
The JSON serialization exposes (data, shape, dtype), and the data is base-64
|
|
17
|
+
encoded which leads to ~33% overhead. A more compact serialization can be achieved
|
|
18
|
+
using ``msgpack_numpy`` (integrated in chains, if RPC-option ``use_binary`` is
|
|
19
|
+
enabled).
|
|
20
|
+
|
|
21
|
+
Usage example:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
import numpy as np
|
|
25
|
+
|
|
26
|
+
class MyModel(pydantic.BaseModel):
|
|
27
|
+
my_array: NumpyArrayField
|
|
28
|
+
|
|
29
|
+
m = MyModel(my_array=np.arange(4).reshape((2, 2)))
|
|
30
|
+
m.my_array.array += 10 # Work with the numpy array.
|
|
31
|
+
print(m)
|
|
32
|
+
# my_array=NumpyArrayField(
|
|
33
|
+
# shape=(2, 2),
|
|
34
|
+
# dtype=int64,
|
|
35
|
+
# data=[[10 11] [12 13]])
|
|
36
|
+
m_json = m.model_dump_json() # Serialize.
|
|
37
|
+
print(m_json)
|
|
38
|
+
# {"my_array":{"data_b64":"CgAAAAAAAAALAAAAAAAAAAwAAAAAAAAADQAAAAAAAAA=","shape":[2,2],"dtype":"int64"}}
|
|
39
|
+
m2 = MyModel.model_validate_json(m_json) # De-serialize.
|
|
40
|
+
```
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
data_key: ClassVar[str] = "data_b64"
|
|
44
|
+
shape_key: ClassVar[str] = "shape"
|
|
45
|
+
dtype_key: ClassVar[str] = "dtype"
|
|
46
|
+
array: "NDArray"
|
|
47
|
+
|
|
48
|
+
def __init__(self, array: "NDArray"):
|
|
49
|
+
self.array = array
|
|
50
|
+
|
|
51
|
+
def __repr__(self) -> str:
|
|
52
|
+
return (
|
|
53
|
+
f"{self.__class__.__name__}(shape={self.array.shape}, "
|
|
54
|
+
f"dtype={self.array.dtype}, data={self.array})"
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
def __get_pydantic_core_schema__(
|
|
59
|
+
cls, source_type: Any, handler: pydantic.GetCoreSchemaHandler
|
|
60
|
+
) -> core_schema.CoreSchema:
|
|
61
|
+
return core_schema.no_info_after_validator_function(
|
|
62
|
+
cls.validate_numpy_array,
|
|
63
|
+
core_schema.any_schema(),
|
|
64
|
+
serialization=core_schema.plain_serializer_function_ser_schema(
|
|
65
|
+
cls.serialize_numpy_array, info_arg=True
|
|
66
|
+
),
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
@classmethod
|
|
70
|
+
def validate_numpy_array(cls, value: Any):
|
|
71
|
+
import numpy as np
|
|
72
|
+
|
|
73
|
+
keys = {cls.data_key, cls.shape_key, cls.dtype_key}
|
|
74
|
+
if isinstance(value, dict) and keys.issubset(value):
|
|
75
|
+
try:
|
|
76
|
+
data = base64.b64decode(value[cls.data_key])
|
|
77
|
+
array = np.frombuffer(data, dtype=value[cls.dtype_key]).reshape(
|
|
78
|
+
value[cls.shape_key]
|
|
79
|
+
)
|
|
80
|
+
return cls(array)
|
|
81
|
+
except (ValueError, TypeError) as e:
|
|
82
|
+
raise TypeError(
|
|
83
|
+
"numpy_array_validation"
|
|
84
|
+
f"Invalid data, shape, or dtype for NumPy array: {str(e)}"
|
|
85
|
+
)
|
|
86
|
+
if isinstance(value, np.ndarray):
|
|
87
|
+
return cls(value)
|
|
88
|
+
if isinstance(value, cls):
|
|
89
|
+
return value
|
|
90
|
+
|
|
91
|
+
raise TypeError(
|
|
92
|
+
"numpy_array_validation\n"
|
|
93
|
+
f"Expected a NumPy array or a dictionary with keys {keys}.\n"
|
|
94
|
+
f"Got:\n{value}"
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
@classmethod
|
|
98
|
+
def serialize_numpy_array(
|
|
99
|
+
cls, obj: "NumpyArrayField", info: core_schema.SerializationInfo
|
|
100
|
+
):
|
|
101
|
+
if info.mode == "json":
|
|
102
|
+
return {
|
|
103
|
+
cls.data_key: base64.b64encode(obj.array.tobytes()).decode("utf-8"),
|
|
104
|
+
cls.shape_key: obj.array.shape,
|
|
105
|
+
cls.dtype_key: str(obj.array.dtype),
|
|
106
|
+
}
|
|
107
|
+
return obj.array
|
|
108
|
+
|
|
109
|
+
@classmethod
|
|
110
|
+
def __get_pydantic_json_schema__(
|
|
111
|
+
cls,
|
|
112
|
+
_core_schema: core_schema.CoreSchema,
|
|
113
|
+
handler: pydantic.GetJsonSchemaHandler,
|
|
114
|
+
) -> JsonSchemaValue:
|
|
115
|
+
json_schema = handler(_core_schema)
|
|
116
|
+
json_schema.update(
|
|
117
|
+
{
|
|
118
|
+
"type": "object",
|
|
119
|
+
"properties": {
|
|
120
|
+
"data": {"type": "string", "format": "byte"},
|
|
121
|
+
"shape": {
|
|
122
|
+
"type": "array",
|
|
123
|
+
"items": {"type": "integer"},
|
|
124
|
+
"minItems": 1,
|
|
125
|
+
},
|
|
126
|
+
"dtype": {"type": "string"},
|
|
127
|
+
},
|
|
128
|
+
"required": ["data", "shape", "dtype"],
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
return json_schema
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import random
|
|
2
|
+
|
|
3
|
+
# For more on chains, check out https://docs.baseten.co/chains/overview.
|
|
4
|
+
import truss_chains as chains
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# By inhereting chains.ChainletBase, the chains framework will know to create a chainlet that hosts the RandInt class.
|
|
8
|
+
class RandInt(chains.ChainletBase):
|
|
9
|
+
# run_remote must be implemented by all chainlets. This is the code that will be executed at inference time.
|
|
10
|
+
def run_remote(self, max_value: int) -> int:
|
|
11
|
+
return random.randint(1, max_value)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# The @chains.mark_entrypoint decorator indicates that this Chainlet is the entrypoint.
|
|
15
|
+
# Each chain must have exactly one entrypoint.
|
|
16
|
+
@chains.mark_entrypoint
|
|
17
|
+
class HelloWorld(chains.ChainletBase):
|
|
18
|
+
# chains.depends indicates that the HelloWorld chainlet depends on the RandInt Chainlet
|
|
19
|
+
# this enables the HelloWorld chainlet to call the RandInt chainlet
|
|
20
|
+
def __init__(self, rand_int=chains.depends(RandInt, retries=3)) -> None:
|
|
21
|
+
self._rand_int = rand_int
|
|
22
|
+
|
|
23
|
+
def run_remote(self, max_value: int) -> str:
|
|
24
|
+
num_repetitions = self._rand_int.run_remote(max_value)
|
|
25
|
+
return "Hello World! " * num_repetitions
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
if __name__ == "__main__":
|
|
29
|
+
with chains.run_local():
|
|
30
|
+
hello_world_chain = HelloWorld()
|
|
31
|
+
result = hello_world_chain.run_remote(max_value=5)
|
|
32
|
+
|
|
33
|
+
print(result)
|
|
34
|
+
# Hello World! Hello World! Hello World!
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import truss_chains as chains
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class HelloWorld(chains.ModelBase):
|
|
5
|
+
def __init__(self, context: chains.DeploymentContext = chains.depends_context()):
|
|
6
|
+
self._call_count = 0
|
|
7
|
+
|
|
8
|
+
def predict(self, call_count_increment: int) -> int:
|
|
9
|
+
self._call_count += call_count_increment
|
|
10
|
+
return self._call_count
|
|
File without changes
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
from truss.templates.shared import secrets_resolver
|
|
5
|
+
|
|
6
|
+
from truss_chains import definitions
|
|
7
|
+
from truss_chains.remote_chainlet import utils
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TrussChainletModel:
|
|
11
|
+
_context: definitions.DeploymentContext
|
|
12
|
+
_chainlet: definitions.ABCChainlet
|
|
13
|
+
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
config: dict,
|
|
17
|
+
data_dir: pathlib.Path,
|
|
18
|
+
secrets: secrets_resolver.Secrets,
|
|
19
|
+
# TODO: Remove the default value once all truss versions are synced up.
|
|
20
|
+
environment: Optional[dict] = None,
|
|
21
|
+
) -> None:
|
|
22
|
+
truss_metadata: definitions.TrussMetadata = (
|
|
23
|
+
definitions.TrussMetadata.model_validate(
|
|
24
|
+
config["model_metadata"][definitions.TRUSS_CONFIG_CHAINS_KEY]
|
|
25
|
+
)
|
|
26
|
+
)
|
|
27
|
+
deployment_environment: Optional[definitions.Environment] = (
|
|
28
|
+
definitions.Environment.model_validate(environment) if environment else None
|
|
29
|
+
)
|
|
30
|
+
chainlet_to_deployed_service = utils.populate_chainlet_service_predict_urls(
|
|
31
|
+
truss_metadata.chainlet_to_service
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
self._context = definitions.DeploymentContext(
|
|
35
|
+
chainlet_to_service=chainlet_to_deployed_service,
|
|
36
|
+
secrets=secrets,
|
|
37
|
+
data_dir=data_dir,
|
|
38
|
+
environment=deployment_environment,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# Below illustrated code will be added by code generation.
|
|
42
|
+
|
|
43
|
+
# def load(self) -> None:
|
|
44
|
+
# logging.info(f"Loading Chainlet `TextToNum`.")
|
|
45
|
+
# self._chainlet = itest_chain.TextToNum(
|
|
46
|
+
# replicator=stub.factory(TextReplicator, self._context),
|
|
47
|
+
# side_effect=stub.factory(SideEffectOnlySubclass, self._context),
|
|
48
|
+
# )
|
|
49
|
+
#
|
|
50
|
+
# If chainlet implements is_healthy:
|
|
51
|
+
# def is_healthy(self) -> Optional[bool]:
|
|
52
|
+
# if hasattr(self, "_chainlet"):
|
|
53
|
+
# return self._chainlet.is_healthy()
|
|
54
|
+
#
|
|
55
|
+
# def predict(
|
|
56
|
+
# self, inputs: TextToNumInput, request: starlette.requests.Request
|
|
57
|
+
# ) -> TextToNumOutput:
|
|
58
|
+
# with utils.predict_context(request):
|
|
59
|
+
# result = self._chainlet.run_remote(**utils.pydantic_set_field_dict(inputs))
|
|
60
|
+
# return TextToNumOutput(result)
|