Skip to content

Commit

Permalink
Support aliased input class keys (#1045)
Browse files Browse the repository at this point in the history
<!-- ELLIPSIS_HIDDEN -->


> [!IMPORTANT]
> This PR adds support for aliased input class keys and enum values,
refactors the Jinja crate, and updates tests to verify aliasing
behavior.
> 
>   - **Behavior**:
>     - Support for aliased input class keys and enum values.
> - Updates to `PromptRenderer` in `prompt_renderer/mod.rs` to handle
aliasing.
>   - **Crate Refactor**:
> - Split Jinja into `internal-baml-jinja-types` and
`internal-baml-jinja`.
>     - Update `Cargo.toml` files for new crate structure.
>   - **Code Changes**:
> - Modify imports in `enums.rs`, `functions.rs`,
`baml_value_to_jinja_value.rs` to use `internal_baml_jinja_types`.
> - Implement `IntoMiniJinjaValue` trait in
`baml_value_to_jinja_value.rs`.
>   - **Testing**:
> - Add integration tests in `integ-tests.test.ts` for aliasing
behavior.
> - Test cases for aliased input classes and enums in
`aliased-inputs.baml`.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup>
for 2c8240a. It will automatically
update as commits are pushed.</sup>


<!-- ELLIPSIS_HIDDEN -->
  • Loading branch information
aaronvg authored Oct 16, 2024
1 parent 3ee81d5 commit 3824cda
Show file tree
Hide file tree
Showing 47 changed files with 4,036 additions and 2,677 deletions.
26 changes: 23 additions & 3 deletions engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion engine/baml-lib/baml-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enumflags2 = "0.7"
log = "0.4.20"
indexmap.workspace = true
internal-baml-diagnostics = { path = "../diagnostics" }
internal-baml-jinja.workspace = true
internal-baml-jinja-types = { path = "../jinja" }
internal-baml-parser-database = { path = "../parser-database" }
internal-baml-prompt-parser = { path = "../prompt-parser" }
internal-baml-schema-ast = { path = "../schema-ast" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::validate::validation_pipeline::context::Context;
use internal_baml_diagnostics::DatamodelError;

pub(super) fn validate(ctx: &mut Context<'_>) {
let mut defined_types = internal_baml_jinja::PredefinedTypes::default();
let mut defined_types = internal_baml_jinja_types::PredefinedTypes::default();

for cls in ctx.db.walk_classes() {
for c in cls.static_fields() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use internal_baml_diagnostics::DatamodelError;
use internal_baml_schema_ast::ast::{WithName, WithSpan};

pub(super) fn validate(ctx: &mut Context<'_>) {
let mut defined_types = internal_baml_jinja::PredefinedTypes::default();
let mut defined_types = internal_baml_jinja_types::PredefinedTypes::default();
for enm in ctx.db.walk_enums() {
for args in enm.walk_input_args() {
let arg = args.ast_arg();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(super) fn validate(ctx: &mut Context<'_>) {
.map(|c| c.name().to_string())
.collect::<Vec<_>>();

let mut defined_types = internal_baml_jinja::PredefinedTypes::default();
let mut defined_types = internal_baml_jinja_types::PredefinedTypes::default();
ctx.db.walk_classes().for_each(|t| {
t.add_to_types(&mut defined_types);
});
Expand All @@ -40,7 +40,7 @@ pub(super) fn validate(ctx: &mut Context<'_>) {
defined_types.add_variable(name.name(), ctx.db.to_jinja_type(&t.field_type))
});
}
match internal_baml_jinja::validate_template(
match internal_baml_jinja_types::validate_template(
template.name(),
prompt.raw_value(),
&mut defined_types,
Expand Down Expand Up @@ -128,7 +128,7 @@ pub(super) fn validate(ctx: &mut Context<'_>) {

defined_types.add_variable(&name, field_type);
});
match internal_baml_jinja::validate_template(
match internal_baml_jinja_types::validate_template(
func.name(),
prompt.raw_value(),
&mut defined_types,
Expand Down
2 changes: 0 additions & 2 deletions engine/baml-lib/baml-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mod map;
mod media;
#[cfg(feature = "mini-jinja")]
mod minijinja;

mod baml_value;
mod field_type;
Expand Down
76 changes: 0 additions & 76 deletions engine/baml-lib/baml-types/src/minijinja.rs

This file was deleted.

46 changes: 46 additions & 0 deletions engine/baml-lib/jinja-runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[package]
name = "internal-baml-jinja"
edition = "2021"
version.workspace = true
authors.workspace = true
description.workspace = true
license-file.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
baml-types = { path = "../baml-types", features = ["mini-jinja"] }
internal-baml-jinja-types = { path = "../jinja" }
internal-baml-core = { path = "../baml-core" }
internal-baml-diagnostics = { path = "../diagnostics" }
# TODO: disable imports, etc
minijinja = { version = "1.0.16", default-features = false, features = [
"macros",
"builtins",
"debug",
"preserve_order",
"adjacent_loop_items",
"unicode",
"json",
"unstable_machinery",
"unstable_machinery_serde",
"custom_syntax",
"internal_debug",
"deserialization",
# We don't want to use these features:
# multi_template
# loader
#
] }
askama.workspace = true
anyhow.workspace = true
indexmap.workspace = true
log.workspace = true
serde.workspace = true
serde_json.workspace = true
strum.workspace = true
strsim = "0.11.1"
colored = "2.1.0"

[dev-dependencies]
env_logger = "0.11.3"
Loading

0 comments on commit 3824cda

Please sign in to comment.