baml-py 0.1.7__tar.gz
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.
- baml_py-0.1.7/PKG-INFO +12 -0
- baml_py-0.1.7/README.md +1 -0
- baml_py-0.1.7/baml-lib/baml-core/Cargo.toml +39 -0
- baml_py-0.1.7/baml-lib/baml-core/README.md +0 -0
- baml_py-0.1.7/baml-lib/baml-core/askama.toml +6 -0
- baml_py-0.1.7/baml-lib/baml-core/src/common/preview_features.rs +88 -0
- baml_py-0.1.7/baml-lib/baml-core/src/common.rs +5 -0
- baml_py-0.1.7/baml-lib/baml-core/src/configuration/configuration_struct.rs +24 -0
- baml_py-0.1.7/baml-lib/baml-core/src/configuration/generator.rs +217 -0
- baml_py-0.1.7/baml-lib/baml-core/src/configuration.rs +5 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/dir_writer.rs +242 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_pipeline.rs +24 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/class.rs +105 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/client.rs +79 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/enum.rs +51 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/expression.rs +66 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/field_type.rs +295 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/function.rs +99 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/impl.rs +138 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/intermediate_repr.rs +26 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/mod.rs +37 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/python_language_features.rs +96 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/template.rs +136 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/configs/retry_policy.hbs +6 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/export/generated_baml_client.hbs +36 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/arg_list.hbs +1 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/arg_types_list.hbs +1 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/arg_values.hbs +1 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/func_def.hbs +5 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/func_params.hbs +6 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/function_py.hbs +28 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/function_pyi.hbs +136 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/impl.hbs +96 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/interface.hbs +45 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/method_def.hbs +5 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/tests/multi_arg_snippet.hbs +29 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/tests/single_arg_snippet.hbs +19 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/types/class.hbs +14 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/types/class_partial.hbs +8 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/types/client.hbs +11 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/types/enum.hbs +14 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/class.rs +113 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/client.rs +133 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/configuration.rs +177 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/enum.rs +93 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/field.rs +63 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/file.rs +301 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/function.rs +229 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/mod.rs +233 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/template.rs +181 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/configs/retry_policy.hb +6 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/export/generated_baml_client.hb +36 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/arg_list.hb +1 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/arg_types_list.hb +1 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/arg_values.hb +1 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/default_variant.hb +56 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/func_def.hb +5 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/func_params.hb +5 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/function_py.hb +28 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/function_pyi.hb +136 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/interface.hb +45 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/method_def.hb +5 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/variant.hb +96 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/tests/multi_arg_snippet.hb +29 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/tests/single_arg_snippet.hb +20 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/types/class.hb +14 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/types/class_partial.hb +8 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/types/client.hb +11 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/types/enum.hb +12 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/traits.rs +21 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/types.rs +101 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/types_partial.rs +116 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/value.rs +67 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/variants.rs +175 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/class.rs +68 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/client.rs +54 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/default_config.rs +84 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/enum.rs +34 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/expression.rs +54 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/field_type.rs +277 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/function.rs +94 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/impl.rs +106 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/intermediate_repr.rs +26 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/mod.rs +168 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/retry_policy.rs +63 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/template.rs +89 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/exports/baml_client.hbs +15 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/functions/default_impl.hbs +46 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/functions/function.hbs +107 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/functions/impl.hbs +61 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/functions/test_case.hbs +22 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/types/class.hbs +5 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/types/class_internal.hbs +44 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/types/client.hbs +5 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/types/enum.hbs +5 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/types/enum_internal.hbs +4 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/test_case.rs +59 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/ts_language_features.rs +93 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/generate.rs +26 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/ir_helpers/error_utils.rs +89 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/ir_helpers/mod.rs +175 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/ir_helpers/parse_response.rs +1 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/ir_helpers/scope_diagnostics.rs +136 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/ir_helpers/to_baml_arg.rs +188 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/json_schema.rs +295 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/mod.rs +39 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/repr.rs +1089 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/walker.rs +324 -0
- baml_py-0.1.7/baml-lib/baml-core/src/generate/mod.rs +7 -0
- baml_py-0.1.7/baml-lib/baml-core/src/lib.rs +168 -0
- baml_py-0.1.7/baml-lib/baml-core/src/lockfile.rs +236 -0
- baml_py-0.1.7/baml-lib/baml-core/src/validate/generator_loader/mod.rs +67 -0
- baml_py-0.1.7/baml-lib/baml-core/src/validate/generator_loader/v0.rs +227 -0
- baml_py-0.1.7/baml-lib/baml-core/src/validate/generator_loader/v1.rs +187 -0
- baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/context.rs +25 -0
- baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations/classes.rs +18 -0
- baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations/clients.rs +26 -0
- baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations/common.rs +26 -0
- baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations/configurations.rs +23 -0
- baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations/cycle.rs +89 -0
- baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations/enums.rs +7 -0
- baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations/functions.rs +170 -0
- baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations/variants.rs +116 -0
- baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations.rs +23 -0
- baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline.rs +23 -0
- baml_py-0.1.7/baml-lib/baml-core/src/validate.rs +5 -0
- baml_py-0.1.7/baml-lib/diagnostics/Cargo.toml +16 -0
- baml_py-0.1.7/baml-lib/diagnostics/src/collection.rs +152 -0
- baml_py-0.1.7/baml-lib/diagnostics/src/error.rs +615 -0
- baml_py-0.1.7/baml-lib/diagnostics/src/lib.rs +12 -0
- baml_py-0.1.7/baml-lib/diagnostics/src/pretty_print.rs +111 -0
- baml_py-0.1.7/baml-lib/diagnostics/src/source_file.rs +91 -0
- baml_py-0.1.7/baml-lib/diagnostics/src/span.rs +76 -0
- baml_py-0.1.7/baml-lib/diagnostics/src/warning.rs +181 -0
- baml_py-0.1.7/baml-lib/jinja/Cargo.toml +39 -0
- baml_py-0.1.7/baml-lib/jinja/src/baml_image.rs +1 -0
- baml_py-0.1.7/baml-lib/jinja/src/callable_jinja.rs +45 -0
- baml_py-0.1.7/baml-lib/jinja/src/evaluate_type/expr.rs +242 -0
- baml_py-0.1.7/baml-lib/jinja/src/evaluate_type/mod.rs +218 -0
- baml_py-0.1.7/baml-lib/jinja/src/evaluate_type/pretty_print.rs +163 -0
- baml_py-0.1.7/baml-lib/jinja/src/evaluate_type/stmt.rs +134 -0
- baml_py-0.1.7/baml-lib/jinja/src/evaluate_type/test_expr.rs +198 -0
- baml_py-0.1.7/baml-lib/jinja/src/evaluate_type/test_stmt.rs +269 -0
- baml_py-0.1.7/baml-lib/jinja/src/evaluate_type/types.rs +432 -0
- baml_py-0.1.7/baml-lib/jinja/src/get_vars.rs +484 -0
- baml_py-0.1.7/baml-lib/jinja/src/lib.rs +1171 -0
- baml_py-0.1.7/baml-lib/jinja/src/output_format.rs +83 -0
- baml_py-0.1.7/baml-lib/jinja/src/render_context.rs +106 -0
- baml_py-0.1.7/baml-lib/jsonish/Cargo.toml +21 -0
- baml_py-0.1.7/baml-lib/jsonish/README.md +19 -0
- baml_py-0.1.7/baml-lib/jsonish/src/deserializer/iterative_parser.rs +771 -0
- baml_py-0.1.7/baml-lib/jsonish/src/deserializer/mod.rs +6 -0
- baml_py-0.1.7/baml-lib/jsonish/src/deserializer/old_mod.rs +347 -0
- baml_py-0.1.7/baml-lib/jsonish/src/deserializer/parse_state.rs +201 -0
- baml_py-0.1.7/baml-lib/jsonish/src/deserializer/raw_value.rs +580 -0
- baml_py-0.1.7/baml-lib/jsonish/src/deserializer/test_iterative_parser.rs +419 -0
- baml_py-0.1.7/baml-lib/jsonish/src/deserializer/test_raw_value.rs +240 -0
- baml_py-0.1.7/baml-lib/jsonish/src/json_schema/deserialize_flags.rs +206 -0
- baml_py-0.1.7/baml-lib/jsonish/src/json_schema/mod.rs +820 -0
- baml_py-0.1.7/baml-lib/jsonish/src/lib.rs +42 -0
- baml_py-0.1.7/baml-lib/jsonish/src/tests/mod.rs +113 -0
- baml_py-0.1.7/baml-lib/parser-database/Cargo.toml +29 -0
- baml_py-0.1.7/baml-lib/parser-database/build.rs +5 -0
- baml_py-0.1.7/baml-lib/parser-database/src/attributes/alias.rs +15 -0
- baml_py-0.1.7/baml-lib/parser-database/src/attributes/description.rs +22 -0
- baml_py-0.1.7/baml-lib/parser-database/src/attributes/get.rs +38 -0
- baml_py-0.1.7/baml-lib/parser-database/src/attributes/meta.rs +38 -0
- baml_py-0.1.7/baml-lib/parser-database/src/attributes/mod.rs +122 -0
- baml_py-0.1.7/baml-lib/parser-database/src/attributes/to_string_attribute.rs +55 -0
- baml_py-0.1.7/baml-lib/parser-database/src/coerce_expression.rs +156 -0
- baml_py-0.1.7/baml-lib/parser-database/src/context/attributes.rs +29 -0
- baml_py-0.1.7/baml-lib/parser-database/src/context/mod.rs +273 -0
- baml_py-0.1.7/baml-lib/parser-database/src/interner.rs +36 -0
- baml_py-0.1.7/baml-lib/parser-database/src/lib.rs +403 -0
- baml_py-0.1.7/baml-lib/parser-database/src/names/mod.rs +242 -0
- baml_py-0.1.7/baml-lib/parser-database/src/names/validate_reserved_names.rs +145 -0
- baml_py-0.1.7/baml-lib/parser-database/src/printer/enum_printer.rs +14 -0
- baml_py-0.1.7/baml-lib/parser-database/src/printer/mod.rs +155 -0
- baml_py-0.1.7/baml-lib/parser-database/src/printer/print_enum_default.rs +57 -0
- baml_py-0.1.7/baml-lib/parser-database/src/printer/print_type_default.rs +257 -0
- baml_py-0.1.7/baml-lib/parser-database/src/printer/templates/print_enum_default.py +55 -0
- baml_py-0.1.7/baml-lib/parser-database/src/printer/templates/print_type_default.py +125 -0
- baml_py-0.1.7/baml-lib/parser-database/src/printer/type_printer.rs +19 -0
- baml_py-0.1.7/baml-lib/parser-database/src/types/configurations.rs +319 -0
- baml_py-0.1.7/baml-lib/parser-database/src/types/mod.rs +995 -0
- baml_py-0.1.7/baml-lib/parser-database/src/types/post_prompt.rs +269 -0
- baml_py-0.1.7/baml-lib/parser-database/src/types/prompt.rs +187 -0
- baml_py-0.1.7/baml-lib/parser-database/src/types/to_string_attributes.rs +74 -0
- baml_py-0.1.7/baml-lib/parser-database/src/types/types.rs +31 -0
- baml_py-0.1.7/baml-lib/parser-database/src/walkers/class.rs +214 -0
- baml_py-0.1.7/baml-lib/parser-database/src/walkers/client.rs +96 -0
- baml_py-0.1.7/baml-lib/parser-database/src/walkers/configuration.rs +59 -0
- baml_py-0.1.7/baml-lib/parser-database/src/walkers/enum.rs +157 -0
- baml_py-0.1.7/baml-lib/parser-database/src/walkers/field.rs +169 -0
- baml_py-0.1.7/baml-lib/parser-database/src/walkers/function.rs +346 -0
- baml_py-0.1.7/baml-lib/parser-database/src/walkers/mod.rs +362 -0
- baml_py-0.1.7/baml-lib/parser-database/src/walkers/template_string.rs +55 -0
- baml_py-0.1.7/baml-lib/parser-database/src/walkers/variants.rs +143 -0
- baml_py-0.1.7/baml-lib/prompt-parser/Cargo.toml +21 -0
- baml_py-0.1.7/baml-lib/prompt-parser/src/ast/code_block.rs +95 -0
- baml_py-0.1.7/baml-lib/prompt-parser/src/ast/comment_block.rs +28 -0
- baml_py-0.1.7/baml-lib/prompt-parser/src/ast/prompt_text.rs +23 -0
- baml_py-0.1.7/baml-lib/prompt-parser/src/ast/top.rs +72 -0
- baml_py-0.1.7/baml-lib/prompt-parser/src/ast/traits.rs +19 -0
- baml_py-0.1.7/baml-lib/prompt-parser/src/ast/variable.rs +41 -0
- baml_py-0.1.7/baml-lib/prompt-parser/src/ast/white_space_text.rs +23 -0
- baml_py-0.1.7/baml-lib/prompt-parser/src/ast.rs +111 -0
- baml_py-0.1.7/baml-lib/prompt-parser/src/lib.rs +8 -0
- baml_py-0.1.7/baml-lib/prompt-parser/src/parser/datamodel.pest +37 -0
- baml_py-0.1.7/baml-lib/prompt-parser/src/parser/helpers.rs +32 -0
- baml_py-0.1.7/baml-lib/prompt-parser/src/parser/parse_prompt.rs +504 -0
- baml_py-0.1.7/baml-lib/prompt-parser/src/parser.rs +10 -0
- baml_py-0.1.7/baml-lib/schema-ast/Cargo.toml +23 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/adapter.rs +18 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/argument.rs +69 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/attribute.rs +170 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/class.rs +111 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/client.rs +111 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/comment.rs +4 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/config.rs +59 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/configurations.rs +49 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/enum.rs +146 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/expression.rs +339 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/field.rs +252 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/find_at_position.rs +124 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/function.rs +232 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/generator_config.rs +99 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/identifier.rs +148 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/indentation_type.rs +32 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/newline_type.rs +26 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/printer_config.rs +101 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/retry_policy_config.rs +99 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/serializer.rs +116 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/template_string.rs +80 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/top.rs +146 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/traits.rs +42 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast/variant.rs +171 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/ast.rs +337 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/lib.rs +98 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/datamodel.pest +258 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/helpers.rs +53 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_adapter.rs +114 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_arguments.rs +28 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_attribute.rs +36 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_class.rs +71 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_comments.rs +58 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_config.rs +184 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_enum.rs +107 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_expression.rs +164 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_field.rs +59 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_function.rs +199 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_identifier.rs +65 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_old_function.rs +243 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_schema.rs +182 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_serializer.rs +111 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_template_args.rs +31 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_template_string.rs +156 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_test.rs +202 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_types.rs +167 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_variant.rs +115 -0
- baml_py-0.1.7/baml-lib/schema-ast/src/parser.rs +28 -0
- baml_py-0.1.7/baml-runtime/Cargo.toml +75 -0
- baml_py-0.1.7/baml-runtime/README.md +5 -0
- baml_py-0.1.7/baml-runtime/src/internal/ir_features.rs +60 -0
- baml_py-0.1.7/baml-runtime/src/internal/llm_client/anthropic/anthropic_client.rs +134 -0
- baml_py-0.1.7/baml-runtime/src/internal/llm_client/anthropic/mod.rs +3 -0
- baml_py-0.1.7/baml-runtime/src/internal/llm_client/expression_helper.rs +44 -0
- baml_py-0.1.7/baml-runtime/src/internal/llm_client/llm_provider.rs +73 -0
- baml_py-0.1.7/baml-runtime/src/internal/llm_client/mod.rs +151 -0
- baml_py-0.1.7/baml-runtime/src/internal/llm_client/openai/mod.rs +4 -0
- baml_py-0.1.7/baml-runtime/src/internal/llm_client/openai/openai_client.rs +347 -0
- baml_py-0.1.7/baml-runtime/src/internal/llm_client/openai/types.rs +127 -0
- baml_py-0.1.7/baml-runtime/src/internal/llm_client/retry_policy.rs +51 -0
- baml_py-0.1.7/baml-runtime/src/internal/llm_client/state.rs +9 -0
- baml_py-0.1.7/baml-runtime/src/internal/llm_client/traits/chat.rs +47 -0
- baml_py-0.1.7/baml-runtime/src/internal/llm_client/traits/completion.rs +43 -0
- baml_py-0.1.7/baml-runtime/src/internal/llm_client/traits/mod.rs +202 -0
- baml_py-0.1.7/baml-runtime/src/internal/mod.rs +3 -0
- baml_py-0.1.7/baml-runtime/src/internal/prompt_renderer.rs +94 -0
- baml_py-0.1.7/baml-runtime/src/lib.rs +91 -0
- baml_py-0.1.7/baml-runtime/src/macros.rs +9 -0
- baml_py-0.1.7/baml-runtime/src/runtime/ir_features.rs +43 -0
- baml_py-0.1.7/baml-runtime/src/runtime/mod.rs +72 -0
- baml_py-0.1.7/baml-runtime/src/runtime/runtime_interface.rs +345 -0
- baml_py-0.1.7/baml-runtime/src/runtime/tests.rs +58 -0
- baml_py-0.1.7/baml-runtime/src/runtime_interface.rs +88 -0
- baml_py-0.1.7/baml-runtime/src/types/mod.rs +5 -0
- baml_py-0.1.7/baml-runtime/src/types/response.rs +137 -0
- baml_py-0.1.7/baml-runtime/src/types/runtime_context.rs +33 -0
- baml_py-0.1.7/language-client-codegen/Cargo.toml +18 -0
- baml_py-0.1.7/language-client-codegen/README.md +5 -0
- baml_py-0.1.7/language-client-codegen/askama.toml +6 -0
- baml_py-0.1.7/language-client-codegen/src/dir_writer.rs +100 -0
- baml_py-0.1.7/language-client-codegen/src/lib.rs +35 -0
- baml_py-0.1.7/language-client-codegen/src/python/generate_types.rs +103 -0
- baml_py-0.1.7/language-client-codegen/src/python/mod.rs +157 -0
- baml_py-0.1.7/language-client-codegen/src/python/python_language_features.rs +51 -0
- baml_py-0.1.7/language-client-codegen/src/python/templates/__init__.py.j2 +15 -0
- baml_py-0.1.7/language-client-codegen/src/python/templates/client.py.j2 +82 -0
- baml_py-0.1.7/language-client-codegen/src/python/templates/types.py.j2 +18 -0
- baml_py-0.1.7/language-client-codegen/src/ruby/expression.rs +54 -0
- baml_py-0.1.7/language-client-codegen/src/ruby/field_type.rs +47 -0
- baml_py-0.1.7/language-client-codegen/src/ruby/generate_types.rs +99 -0
- baml_py-0.1.7/language-client-codegen/src/ruby/mod.rs +104 -0
- baml_py-0.1.7/language-client-codegen/src/ruby/ruby_language_features.rs +35 -0
- baml_py-0.1.7/language-client-codegen/src/ruby/templates/class.rb.j2 +24 -0
- baml_py-0.1.7/language-client-codegen/src/ruby/templates/class_forward_decl.rb.j2 +6 -0
- baml_py-0.1.7/language-client-codegen/src/ruby/templates/client.rb.j2 +91 -0
- baml_py-0.1.7/language-client-codegen/src/ruby/templates/enum.rb.j2 +12 -0
- baml_py-0.1.7/language-client-codegen/src/ruby/templates/types.rb.j2 +38 -0
- baml_py-0.1.7/language_client_python/.bumpversion.cfg +15 -0
- baml_py-0.1.7/language_client_python/.gitignore +14 -0
- baml_py-0.1.7/language_client_python/Cargo.lock +535 -0
- baml_py-0.1.7/language_client_python/Cargo.toml +45 -0
- baml_py-0.1.7/language_client_python/LICENSE +201 -0
- baml_py-0.1.7/language_client_python/README.md +1 -0
- baml_py-0.1.7/language_client_python/baml_py.pyi +50 -0
- baml_py-0.1.7/language_client_python/build.rs +3 -0
- baml_py-0.1.7/language_client_python/py.typed +0 -0
- baml_py-0.1.7/language_client_python/src/lib.rs +207 -0
- baml_py-0.1.7/language_client_python/src/parse_py_type.rs +340 -0
- baml_py-0.1.7/language_client_python/src/python_types.rs +67 -0
- baml_py-0.1.7/pyproject.toml +15 -0
baml_py-0.1.7/PKG-INFO
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: baml-py
|
|
3
|
+
Version: 0.1.7
|
|
4
|
+
License-File: LICENSE
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Summary: BAML python bindings (pyproject.toml)
|
|
7
|
+
Author: Boundary <contact@boundaryml.com>
|
|
8
|
+
Author-email: Boundary <contact@boundaryml.com>
|
|
9
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
10
|
+
|
|
11
|
+
BAML python bindings (readme.md)
|
|
12
|
+
|
baml_py-0.1.7/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
BAML python bindings (readme.md)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
edition = "2021"
|
|
3
|
+
name = "internal-baml-core"
|
|
4
|
+
version.workspace = true
|
|
5
|
+
authors.workspace = true
|
|
6
|
+
description.workspace = true
|
|
7
|
+
license-file.workspace = true
|
|
8
|
+
|
|
9
|
+
[dependencies]
|
|
10
|
+
internal-baml-jinja.workspace = true
|
|
11
|
+
internal-baml-diagnostics = { path = "../diagnostics" }
|
|
12
|
+
internal-baml-schema-ast = { path = "../schema-ast" }
|
|
13
|
+
internal-baml-parser-database = { path = "../parser-database" }
|
|
14
|
+
internal-baml-prompt-parser = { path = "../prompt-parser" }
|
|
15
|
+
anyhow.workspace = true
|
|
16
|
+
askama.workspace = true
|
|
17
|
+
indexmap.workspace = true
|
|
18
|
+
serde.workspace = true
|
|
19
|
+
serde_json.workspace = true
|
|
20
|
+
enumflags2 = "0.7"
|
|
21
|
+
rayon = "1.8.0"
|
|
22
|
+
handlebars = "4.4.0"
|
|
23
|
+
log = "0.4.20"
|
|
24
|
+
chrono = "0.4.31"
|
|
25
|
+
whoami = "1.4.1"
|
|
26
|
+
textwrap = "0.16.0"
|
|
27
|
+
either.workspace = true
|
|
28
|
+
strsim = "0.10.0"
|
|
29
|
+
semver = "1.0.20"
|
|
30
|
+
regex = "1.10.3"
|
|
31
|
+
shellwords = "1.1.0"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
[dev-dependencies]
|
|
35
|
+
base64 = "0.13.0"
|
|
36
|
+
dissimilar = "1.0.4"
|
|
37
|
+
expect-test = "1.1.0"
|
|
38
|
+
indoc.workspace = true
|
|
39
|
+
either = "1.8.1"
|
|
File without changes
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
use serde::{Serialize, Serializer};
|
|
2
|
+
use std::fmt;
|
|
3
|
+
|
|
4
|
+
/// A set of preview features.
|
|
5
|
+
pub type PreviewFeatures = enumflags2::BitFlags<PreviewFeature>;
|
|
6
|
+
|
|
7
|
+
macro_rules! features {
|
|
8
|
+
($( $variant:ident $(,)? ),*) => {
|
|
9
|
+
#[enumflags2::bitflags]
|
|
10
|
+
#[repr(u64)]
|
|
11
|
+
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
|
12
|
+
pub enum PreviewFeature {
|
|
13
|
+
$( $variant,)*
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
impl PreviewFeature {
|
|
17
|
+
pub fn parse_opt(s: &str) -> Option<Self> {
|
|
18
|
+
$(
|
|
19
|
+
if s.eq_ignore_ascii_case(stringify!($variant)) { return Some(Self::$variant) }
|
|
20
|
+
)*
|
|
21
|
+
|
|
22
|
+
None
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
impl fmt::Display for PreviewFeature {
|
|
27
|
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
28
|
+
let variant = match self { $( Self::$variant => stringify!($variant),)* };
|
|
29
|
+
let mut first_char = variant.chars().next().unwrap();
|
|
30
|
+
first_char.make_ascii_lowercase();
|
|
31
|
+
f.write_fmt(format_args!("{first_char}{rest}", rest = &variant[1..]))
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// (Usually) Append-only list of features.
|
|
38
|
+
features!(ScalarJson,);
|
|
39
|
+
|
|
40
|
+
/// Generator preview features
|
|
41
|
+
pub const ALL_PREVIEW_FEATURES: FeatureMap = FeatureMap {
|
|
42
|
+
active: enumflags2::BitFlags::EMPTY,
|
|
43
|
+
deprecated: enumflags2::BitFlags::EMPTY,
|
|
44
|
+
hidden: enumflags2::BitFlags::EMPTY,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
#[derive(Debug)]
|
|
48
|
+
pub struct FeatureMap {
|
|
49
|
+
/// Valid, visible features.
|
|
50
|
+
active: PreviewFeatures,
|
|
51
|
+
|
|
52
|
+
/// Deprecated features.
|
|
53
|
+
#[allow(dead_code)]
|
|
54
|
+
deprecated: PreviewFeatures,
|
|
55
|
+
|
|
56
|
+
/// Hidden preview features are valid features, but are not propagated into the tooling
|
|
57
|
+
/// (as autocomplete or similar) or into error messages (eg. showing a list of valid features).
|
|
58
|
+
hidden: PreviewFeatures,
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
impl FeatureMap {
|
|
62
|
+
pub const fn active_features(&self) -> PreviewFeatures {
|
|
63
|
+
self.active
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
pub const fn hidden_features(&self) -> PreviewFeatures {
|
|
67
|
+
self.hidden
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
#[allow(dead_code)]
|
|
71
|
+
pub(crate) fn is_valid(&self, flag: PreviewFeature) -> bool {
|
|
72
|
+
(self.active | self.hidden).contains(flag)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#[allow(dead_code)]
|
|
76
|
+
pub(crate) fn is_deprecated(&self, flag: PreviewFeature) -> bool {
|
|
77
|
+
self.deprecated.contains(flag)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
impl Serialize for PreviewFeature {
|
|
82
|
+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
83
|
+
where
|
|
84
|
+
S: Serializer,
|
|
85
|
+
{
|
|
86
|
+
serializer.serialize_str(&self.to_string())
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
use super::Generator;
|
|
2
|
+
use crate::{internal_baml_diagnostics::Diagnostics, lockfile::LockFileWrapper, PreviewFeature};
|
|
3
|
+
use enumflags2::BitFlags;
|
|
4
|
+
|
|
5
|
+
#[derive(Debug)]
|
|
6
|
+
pub struct Configuration {
|
|
7
|
+
pub generators: Vec<(Generator, LockFileWrapper)>,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
impl Configuration {
|
|
11
|
+
pub fn validate_that_one_datasource_is_provided(&self) -> Result<(), Diagnostics> {
|
|
12
|
+
Ok(())
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
pub fn max_identifier_length(&self) -> usize {
|
|
16
|
+
1024
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
pub fn preview_features(&self) -> BitFlags<PreviewFeature> {
|
|
20
|
+
self.generators
|
|
21
|
+
.iter()
|
|
22
|
+
.fold(BitFlags::empty(), |acc, _generator| acc)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
use crate::ast::WithName;
|
|
2
|
+
use anyhow::Result;
|
|
3
|
+
use internal_baml_parser_database::ast::Expression;
|
|
4
|
+
use regex::Regex;
|
|
5
|
+
use serde::Serialize;
|
|
6
|
+
use std::{collections::HashMap, path::PathBuf, process::Command};
|
|
7
|
+
|
|
8
|
+
#[derive(Debug, Serialize, Clone)]
|
|
9
|
+
#[serde(untagged)]
|
|
10
|
+
pub enum GeneratorConfigValue {
|
|
11
|
+
String(String),
|
|
12
|
+
Array(Vec<GeneratorConfigValue>),
|
|
13
|
+
Map(HashMap<String, GeneratorConfigValue>),
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
impl From<String> for GeneratorConfigValue {
|
|
17
|
+
fn from(value: String) -> Self {
|
|
18
|
+
Self::String(value)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
impl From<&Expression> for GeneratorConfigValue {
|
|
23
|
+
fn from(expr: &Expression) -> Self {
|
|
24
|
+
match expr {
|
|
25
|
+
Expression::BoolValue(val, _) => val.to_string().into(),
|
|
26
|
+
Expression::NumericValue(val, _) => val.clone().into(),
|
|
27
|
+
Expression::StringValue(val, _) => val.clone().into(),
|
|
28
|
+
Expression::Array(elements, _) => {
|
|
29
|
+
Self::Array(elements.iter().map(From::from).collect())
|
|
30
|
+
}
|
|
31
|
+
Expression::Map(elements, _) => Self::Map(
|
|
32
|
+
elements
|
|
33
|
+
.iter()
|
|
34
|
+
.map(|(k, v)| (k.to_string(), From::from(v)))
|
|
35
|
+
.collect(),
|
|
36
|
+
),
|
|
37
|
+
Expression::Identifier(idn) => idn.name().to_string().into(),
|
|
38
|
+
Expression::RawStringValue(val) => val.value().to_string().into(),
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
#[derive(Debug, Serialize, Clone)]
|
|
44
|
+
pub enum GeneratorLanguage {
|
|
45
|
+
#[serde(rename = "python")]
|
|
46
|
+
Python,
|
|
47
|
+
#[serde(rename = "typescript")]
|
|
48
|
+
TypeScript,
|
|
49
|
+
#[serde(rename = "Ruby")]
|
|
50
|
+
Ruby,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
impl GeneratorLanguage {
|
|
54
|
+
pub fn as_str(&self) -> &'static str {
|
|
55
|
+
match self {
|
|
56
|
+
Self::Python => "python",
|
|
57
|
+
Self::TypeScript => "typescript",
|
|
58
|
+
Self::Ruby => "ruby",
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
pub fn package_name(&self) -> &'static str {
|
|
63
|
+
match self {
|
|
64
|
+
Self::Python => "baml",
|
|
65
|
+
Self::TypeScript => "@boundaryml/baml-core",
|
|
66
|
+
Self::Ruby => "baml",
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/// This is redundant with version_command::get_client_version
|
|
71
|
+
fn client_version(&self, command: &str) -> Option<String> {
|
|
72
|
+
let cmd = format!("{} {}", command, self.package_name());
|
|
73
|
+
|
|
74
|
+
// Run the command and get the version
|
|
75
|
+
Command::new(cmd)
|
|
76
|
+
.output()
|
|
77
|
+
.map(|output| {
|
|
78
|
+
// If the command fails, return None
|
|
79
|
+
if !output.status.success() {
|
|
80
|
+
return None;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// If the command succeeds, return the version
|
|
84
|
+
String::from_utf8(output.stdout)
|
|
85
|
+
.ok()
|
|
86
|
+
.map(|v| v.trim().to_string())
|
|
87
|
+
.map(|v| self.parse_version(v.as_str()).ok())
|
|
88
|
+
.flatten()
|
|
89
|
+
})
|
|
90
|
+
.ok()
|
|
91
|
+
.flatten()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/// This is redundant with version_command::extract_client_version
|
|
95
|
+
pub fn parse_version(&self, output: &str) -> Result<String> {
|
|
96
|
+
match self {
|
|
97
|
+
Self::Python => {
|
|
98
|
+
// Split the string by lines, and take the first line that has "version" in it
|
|
99
|
+
let version_line_re = Regex::new(r#"(?i)\b(?:version)\b"#)?;
|
|
100
|
+
|
|
101
|
+
let Some(version_line) = output
|
|
102
|
+
.trim()
|
|
103
|
+
.lines()
|
|
104
|
+
.find(|line| version_line_re.is_match(line))
|
|
105
|
+
else {
|
|
106
|
+
return Err(anyhow::format_err!(
|
|
107
|
+
"Could not infer the version of the client"
|
|
108
|
+
));
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
let version_re = Regex::new("[0-9][^ ]*")?;
|
|
112
|
+
|
|
113
|
+
let Some(version) = version_re.find(version_line) else {
|
|
114
|
+
return Err(anyhow::format_err!(
|
|
115
|
+
"Could not parse the version of the client"
|
|
116
|
+
));
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
Ok(version.as_str().to_string())
|
|
120
|
+
}
|
|
121
|
+
Self::TypeScript => {
|
|
122
|
+
// Look for "<package_name>@<version>"
|
|
123
|
+
let version_re = Regex::new(&format!(r#"{}@[^ ]+"#, self.package_name()))?;
|
|
124
|
+
|
|
125
|
+
let Some(version) = version_re.find(output.trim()) else {
|
|
126
|
+
return Err(anyhow::format_err!(
|
|
127
|
+
"Could not parse the version of the client:{}\n{}",
|
|
128
|
+
self.package_name(),
|
|
129
|
+
output
|
|
130
|
+
));
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
Ok(version.as_str().split('@').last().unwrap().to_string())
|
|
134
|
+
}
|
|
135
|
+
Self::Ruby => {
|
|
136
|
+
// Look for "<package_name>@<version>"
|
|
137
|
+
let version_re = Regex::new(&format!(r#"{} ([^)]+)"#, self.package_name()))?;
|
|
138
|
+
|
|
139
|
+
let Some(version) = version_re.captures(output.trim()) else {
|
|
140
|
+
return Err(anyhow::format_err!(
|
|
141
|
+
"Could not find the version of the client: {}\n{}",
|
|
142
|
+
self.package_name(),
|
|
143
|
+
output
|
|
144
|
+
));
|
|
145
|
+
};
|
|
146
|
+
let Some(version) = version.get(1) else {
|
|
147
|
+
return Err(anyhow::format_err!(
|
|
148
|
+
"Could not parse the version of the client: {}\n{}",
|
|
149
|
+
self.package_name(),
|
|
150
|
+
output
|
|
151
|
+
));
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
Ok(version.as_str().into())
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
#[derive(Debug, Serialize, Clone)]
|
|
161
|
+
#[serde(rename_all = "camelCase")]
|
|
162
|
+
pub struct Generator {
|
|
163
|
+
pub name: String,
|
|
164
|
+
pub language: GeneratorLanguage,
|
|
165
|
+
pub test_command: String,
|
|
166
|
+
pub install_command: String,
|
|
167
|
+
pub package_version_command: String,
|
|
168
|
+
|
|
169
|
+
#[serde(skip)]
|
|
170
|
+
pub used_in_tests: bool,
|
|
171
|
+
|
|
172
|
+
// This is generated from the package_version_command
|
|
173
|
+
pub client_version: Option<String>,
|
|
174
|
+
|
|
175
|
+
/// Where the language source code is located (e.g. place where pyproject.toml is located or package.json is located)
|
|
176
|
+
pub project_root: PathBuf,
|
|
177
|
+
|
|
178
|
+
/// Where the generated code should be placed (usually a subdirectory of the project_root)
|
|
179
|
+
pub output_path: PathBuf,
|
|
180
|
+
|
|
181
|
+
#[serde(skip)]
|
|
182
|
+
pub(crate) span: crate::ast::Span,
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
impl Generator {
|
|
186
|
+
pub fn new(
|
|
187
|
+
name: String,
|
|
188
|
+
project_root: PathBuf,
|
|
189
|
+
language: GeneratorLanguage,
|
|
190
|
+
test_command: String,
|
|
191
|
+
install_command: String,
|
|
192
|
+
package_version_command: String,
|
|
193
|
+
output_path: Option<PathBuf>,
|
|
194
|
+
used_in_tests: Option<bool>,
|
|
195
|
+
span: crate::ast::Span,
|
|
196
|
+
) -> Result<Self, std::io::Error> {
|
|
197
|
+
Ok(Self {
|
|
198
|
+
name,
|
|
199
|
+
output_path: output_path
|
|
200
|
+
.as_ref()
|
|
201
|
+
.unwrap_or(&project_root)
|
|
202
|
+
.join("baml_client"),
|
|
203
|
+
project_root,
|
|
204
|
+
client_version: language.client_version(&package_version_command),
|
|
205
|
+
language,
|
|
206
|
+
test_command,
|
|
207
|
+
install_command,
|
|
208
|
+
package_version_command,
|
|
209
|
+
span,
|
|
210
|
+
used_in_tests: used_in_tests.unwrap_or(false),
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
pub fn cli_version(&self) -> &'static str {
|
|
215
|
+
env!("CARGO_PKG_VERSION")
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
use std::io::{self, ErrorKind};
|
|
2
|
+
use std::thread::sleep;
|
|
3
|
+
use std::time::Duration;
|
|
4
|
+
use std::{
|
|
5
|
+
collections::{HashMap, HashSet},
|
|
6
|
+
path::PathBuf,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
use log::info;
|
|
10
|
+
|
|
11
|
+
#[derive(PartialEq, Eq, Hash)]
|
|
12
|
+
pub(super) struct LibImport {
|
|
13
|
+
pub lib: String,
|
|
14
|
+
pub as_name: Option<String>,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
#[derive(PartialEq, Eq, Hash)]
|
|
18
|
+
pub(super) struct Import {
|
|
19
|
+
pub lib: String,
|
|
20
|
+
pub name: String,
|
|
21
|
+
pub as_name: Option<String>,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
pub(super) struct FileContent {
|
|
25
|
+
content: Vec<String>,
|
|
26
|
+
import_libs: HashSet<LibImport>,
|
|
27
|
+
imports: Vec<Import>,
|
|
28
|
+
exports: Vec<String>,
|
|
29
|
+
export_all: bool,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
impl FileContent {
|
|
33
|
+
pub fn add_import_lib(&mut self, lib: impl Into<String>, as_name: Option<&str>) {
|
|
34
|
+
self.import_libs.insert(LibImport {
|
|
35
|
+
lib: lib.into(),
|
|
36
|
+
as_name: as_name.map(|s| s.to_string()),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
pub fn add_import(
|
|
41
|
+
&mut self,
|
|
42
|
+
lib: impl Into<String>,
|
|
43
|
+
name: impl AsRef<str>,
|
|
44
|
+
as_name: Option<&str>,
|
|
45
|
+
is_export: bool,
|
|
46
|
+
) {
|
|
47
|
+
self.imports.push(Import {
|
|
48
|
+
lib: lib.into(),
|
|
49
|
+
name: name.as_ref().to_string(),
|
|
50
|
+
as_name: as_name.map(|s| s.to_string()),
|
|
51
|
+
});
|
|
52
|
+
if is_export || self.export_all {
|
|
53
|
+
self.exports
|
|
54
|
+
.push(as_name.unwrap_or(name.as_ref()).to_string());
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
pub fn add_export(&mut self, name: impl Into<String>) {
|
|
59
|
+
self.exports.push(name.into());
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
pub fn trim_append(&mut self, content: String) {
|
|
63
|
+
let content = content.trim();
|
|
64
|
+
if content.len() > 0 {
|
|
65
|
+
self.content.push(content.to_string());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
#[allow(dead_code)]
|
|
70
|
+
pub fn append(&mut self, content: String) {
|
|
71
|
+
if content.len() > 0 {
|
|
72
|
+
self.content.push(content.to_string());
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
pub(super) struct FileCollector<L: LanguageFeatures> {
|
|
78
|
+
// map of path to a an object that has the trail File
|
|
79
|
+
files: HashMap<PathBuf, FileContent>,
|
|
80
|
+
/// This is used to keep track of the last file that was written to
|
|
81
|
+
/// Useful for catching bugs to ensure that we don't write to the same file twice.
|
|
82
|
+
last_file: Option<PathBuf>,
|
|
83
|
+
|
|
84
|
+
lang: L,
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
impl<L: LanguageFeatures> FileCollector<L> {
|
|
88
|
+
pub(super) fn new(lang: L) -> Self {
|
|
89
|
+
Self {
|
|
90
|
+
files: HashMap::new(),
|
|
91
|
+
last_file: None,
|
|
92
|
+
lang,
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
pub(super) fn finish_file(&mut self) {
|
|
97
|
+
assert!(self.last_file.is_some(), "No file to finish!");
|
|
98
|
+
self.last_file = None;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
pub(super) fn start_file<T: AsRef<str>>(
|
|
102
|
+
&mut self,
|
|
103
|
+
dir: &str,
|
|
104
|
+
name: T,
|
|
105
|
+
export_all: bool,
|
|
106
|
+
) -> &mut FileContent {
|
|
107
|
+
assert!(
|
|
108
|
+
self.last_file.is_none(),
|
|
109
|
+
"Cannot start a new file before finishing the last one!"
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
let path = self.lang.to_file_path(dir, name.as_ref());
|
|
113
|
+
self.last_file = Some(path.clone());
|
|
114
|
+
self.files.entry(path).or_insert_with(|| FileContent {
|
|
115
|
+
content: vec![],
|
|
116
|
+
import_libs: HashSet::new(),
|
|
117
|
+
imports: vec![],
|
|
118
|
+
exports: vec![],
|
|
119
|
+
export_all,
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
pub(super) fn commit(&self, dir: &PathBuf) -> std::io::Result<()> {
|
|
124
|
+
let output_path = dir;
|
|
125
|
+
// info!("Writing files to {}", output_path.to_string_lossy());
|
|
126
|
+
|
|
127
|
+
let temp_path = PathBuf::from(format!("{}.tmp", output_path.to_string_lossy().to_string()));
|
|
128
|
+
|
|
129
|
+
// if the .tmp dir exists, delete it so we can get back to a working state without user intervention.
|
|
130
|
+
let delete_attempts = 3; // Number of attempts to delete the directory
|
|
131
|
+
let attempt_interval = Duration::from_millis(200); // Wait time between attempts
|
|
132
|
+
|
|
133
|
+
for attempt in 1..=delete_attempts {
|
|
134
|
+
if temp_path.exists() {
|
|
135
|
+
match std::fs::remove_dir_all(&temp_path) {
|
|
136
|
+
Ok(_) => {
|
|
137
|
+
println!("Temp directory successfully removed.");
|
|
138
|
+
break; // Exit loop after successful deletion
|
|
139
|
+
}
|
|
140
|
+
Err(e) if e.kind() == ErrorKind::Other && attempt < delete_attempts => {
|
|
141
|
+
info!(
|
|
142
|
+
"Attempt {}: Failed to delete temp directory: {}",
|
|
143
|
+
attempt, e
|
|
144
|
+
);
|
|
145
|
+
sleep(attempt_interval); // Wait before retrying
|
|
146
|
+
}
|
|
147
|
+
Err(e) => {
|
|
148
|
+
// For other errors or if it's the last attempt, fail with an error
|
|
149
|
+
return Err(io::Error::new(
|
|
150
|
+
e.kind(),
|
|
151
|
+
format!("Failed to delete temp directory: {}", e),
|
|
152
|
+
));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if temp_path.exists() {
|
|
161
|
+
// If the directory still exists after the loop, return an error
|
|
162
|
+
return Err(std::io::Error::new(
|
|
163
|
+
std::io::ErrorKind::Other,
|
|
164
|
+
"Failed to delete existing temp directory within the timeout",
|
|
165
|
+
));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Sort the files by path so that we always write to the same file
|
|
169
|
+
let mut files = self.files.iter().collect::<Vec<_>>();
|
|
170
|
+
files.sort_by(|(a, _), (b, _)| a.cmp(b));
|
|
171
|
+
|
|
172
|
+
for (relative_file_path, file) in &files {
|
|
173
|
+
let full_file_path = temp_path.join(relative_file_path);
|
|
174
|
+
std::fs::create_dir_all(full_file_path.parent().unwrap())?;
|
|
175
|
+
std::fs::write(&full_file_path, &self.format_file(file))?;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
let _ = std::fs::remove_dir_all(dir);
|
|
179
|
+
let res = std::fs::rename(&temp_path, output_path);
|
|
180
|
+
|
|
181
|
+
info!("Wrote {} files to {}", files.len(), dir.display());
|
|
182
|
+
res
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
fn format_file(&self, content: &FileContent) -> String {
|
|
186
|
+
let mut result = vec![];
|
|
187
|
+
|
|
188
|
+
let content_prefix = self.lang.content_prefix();
|
|
189
|
+
if content_prefix.len() > 0 {
|
|
190
|
+
result.push(content_prefix.to_string());
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if content.imports.len() + content.import_libs.len() > 0 {
|
|
194
|
+
result.push(
|
|
195
|
+
self.lang
|
|
196
|
+
.format_imports(&content.import_libs, &content.imports),
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if content.content.len() > 0 {
|
|
201
|
+
result.push(content.content.join("\n\n") + "\n");
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if content.exports.len() > 0 {
|
|
205
|
+
result.push(self.lang.format_exports(&content.exports));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Ensure that the file ends with newlines.
|
|
209
|
+
result.push("".into());
|
|
210
|
+
|
|
211
|
+
result.join("\n\n")
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Add a trait per language that can be used to convert an Import into a string
|
|
216
|
+
pub(super) trait LanguageFeatures {
|
|
217
|
+
fn to_file_path(&self, path: &str, name: &str) -> PathBuf;
|
|
218
|
+
fn format_imports(&self, libs: &HashSet<LibImport>, import: &Vec<Import>) -> String;
|
|
219
|
+
fn format_exports(&self, exports: &Vec<String>) -> String;
|
|
220
|
+
fn content_prefix(&self) -> &'static str;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
pub(super) trait WithFileContentTs<L: LanguageFeatures> {
|
|
224
|
+
fn file_dir(&self) -> &'static str;
|
|
225
|
+
fn file_name(&self) -> String;
|
|
226
|
+
fn write(&self, fc: &mut FileCollector<L>);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
pub(super) trait WithFileContentRuby<L: LanguageFeatures> {
|
|
230
|
+
fn file_dir(&self) -> &'static str;
|
|
231
|
+
fn file_name(&self) -> String;
|
|
232
|
+
fn write(&self, fc: &mut FileCollector<L>);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Until rust supports trait specialization, we can't implement a trait for the same type twice, even if it's generic and the generic type is different (e.g. a diff language).
|
|
236
|
+
// See https://users.rust-lang.org/t/multiple-trait-implementations-based-on-generic-type-bound/17064
|
|
237
|
+
// So to fix we have to hack around and actually have a *different* trait for Python
|
|
238
|
+
// pub(super) trait WithFileContentPy<L: LanguageFeatures> {
|
|
239
|
+
// fn file_dir(&self) -> &'static str;
|
|
240
|
+
// fn file_name(&self) -> String;
|
|
241
|
+
// fn write(&self, fc: &mut FileCollector<L>);
|
|
242
|
+
// }
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
use internal_baml_parser_database::ParserDatabase;
|
|
2
|
+
|
|
3
|
+
use crate::{
|
|
4
|
+
configuration::{Generator, GeneratorLanguage},
|
|
5
|
+
ir::IntermediateRepr,
|
|
6
|
+
lockfile::LockFileWrapper,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
use super::generate_python_client_old::generate_py;
|
|
10
|
+
use super::generate_ts_client::generate_ts;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
pub fn generate_pipeline(
|
|
14
|
+
db: &ParserDatabase,
|
|
15
|
+
gen: &Generator,
|
|
16
|
+
ir: &IntermediateRepr,
|
|
17
|
+
lock: &LockFileWrapper,
|
|
18
|
+
) -> anyhow::Result<()> {
|
|
19
|
+
match gen.language {
|
|
20
|
+
GeneratorLanguage::Python => generate_py(db, gen, lock).map_err(anyhow::Error::new),
|
|
21
|
+
GeneratorLanguage::TypeScript => generate_ts(&ir, gen).map_err(anyhow::Error::new),
|
|
22
|
+
_ => anyhow::bail!("generator v1 only supports python and TS"),
|
|
23
|
+
}
|
|
24
|
+
}
|