Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: attempt minijinja v2 upgrade #854

Draft
wants to merge 1 commit into
base: canary
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions engine/Cargo.lock

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

6 changes: 3 additions & 3 deletions engine/baml-lib/baml-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ workspace = true
optional = true

[dependencies.minijinja]
optional = true
version = "1.0.16"
#optional = true
version = "2.1.1"
default-features = false
features = [
"macros",
Expand All @@ -39,4 +39,4 @@ features = [
[features]
default = ["stable_sort"]
stable_sort = ["indexmap"]
mini-jinja = ["minijinja"]
mini-jinja = []
16 changes: 15 additions & 1 deletion engine/baml-lib/baml-types/src/minijinja.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;

use crate::{BamlMedia, BamlValue};

impl From<BamlValue> for minijinja::Value {
Expand Down Expand Up @@ -56,8 +58,12 @@ impl std::fmt::Display for MinijinjaBamlImage {
}

impl minijinja::value::Object for MinijinjaBamlImage {
fn repr(self: &Arc<Self>) -> minijinja::value::ObjectRepr {
minijinja::value::ObjectRepr::Plain
}

fn call(
&self,
self: &Arc<Self>,
_state: &minijinja::State<'_, '_>,
args: &[minijinja::value::Value],
) -> Result<minijinja::value::Value, minijinja::Error> {
Expand All @@ -66,4 +72,12 @@ impl minijinja::value::Object for MinijinjaBamlImage {
format!("BamlImage has no callable attribute '{:#?}'", args),
))
}

fn render(self: &Arc<Self>, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
"{MAGIC_IMAGE_DELIMITER}:baml-start-image:{}:baml-end-image:{MAGIC_IMAGE_DELIMITER}",
serde_json::json!(self.image)
)
}
}
2 changes: 1 addition & 1 deletion engine/baml-lib/jinja/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ pub fn render_prompt(
anyhow::bail!("args must be a map");
}

let minijinja_args: Value = args.clone().into();
let minijinja_args: minijinja::Value = args.clone().into();
let default_role = ctx.client.default_role.clone();
let rendered = render_minijinja(
template,
Expand Down
Loading