Skip to content

Commit

Permalink
Add patch to support passthrough params for clients
Browse files Browse the repository at this point in the history
For example, safetey mode and response_type for gemini
  • Loading branch information
hellovai committed Jun 13, 2024
1 parent 71d04fe commit 7f77a51
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
14 changes: 13 additions & 1 deletion engine/baml-runtime/src/types/expression_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,19 @@ pub fn to_value(ctx: &RuntimeContext, expr: &Expression) -> Result<serde_json::V
.map(|(k, v)| {
let k = match k {
Expression::String(s) => s.clone(),
_ => anyhow::bail!("invalid key type"),
Expression::Identifier(internal_baml_core::ir::repr::Identifier::ENV(
key,
)) => match ctx.env.get(key) {
None => anyhow::bail!("unset env variable '{}'", key),
Some(val) => val.to_string(),
},
Expression::Identifier(
internal_baml_core::ir::repr::Identifier::Local(key),
) => key.clone(),
Expression::Identifier(internal_baml_core::ir::repr::Identifier::Ref(
key,
)) => key.join("."),
_ => anyhow::bail!("invalid key {:#?}", k),
};
let v = to_value(ctx, v)?;
Ok((k, v))
Expand Down
6 changes: 5 additions & 1 deletion engine/baml-runtime/src/types/runtime_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ impl RuntimeContext {
&self,
expr: &Expression,
) -> Result<T> {
serde_json::from_value::<T>(super::expression_helper::to_value(self, expr)?).map_err(|e| {
match super::expression_helper::to_value(self, expr) {
Ok(v) => serde_json::from_value(v).map_err(|e| e.into()),
Err(e) => Err(e),
}
.map_err(|e| {
anyhow::anyhow!(
"Failed to resolve expression {:?} with error: {:?}",
expr,
Expand Down
2 changes: 1 addition & 1 deletion engine/baml-schema-wasm/src/runtime_wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ impl WasmFunction {
.render_prompt(&self.name, &ctx, &params, None)
.as_ref()
.map(|(p, scope)| (p, scope).into())
.map_err(|e| wasm_bindgen::JsError::new(&e.to_string()))
.map_err(|e| wasm_bindgen::JsError::new(format!("{e:?}").as_str()))
}

#[wasm_bindgen]
Expand Down

0 comments on commit 7f77a51

Please sign in to comment.