Skip to content

Commit 7a74707

Browse files
committed
feat: update rust Call AST to use Expr for condition attr
Signed-off-by: Nick Mitchell <[email protected]>
1 parent 82ae542 commit 7a74707

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

pdl-live-react/src-tauri/src/compile/beeai.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use serde_json::{from_reader, json, to_string, Map, Value};
1212
use tempfile::Builder;
1313

1414
use crate::pdl::ast::{
15-
ArrayBlock, CallBlock, FunctionBlock, ListOrString, MessageBlock, Metadata, ModelBlock,
16-
ObjectBlock, PdlBaseType, PdlBlock, PdlOptionalType, PdlParser, PdlType, PythonCodeBlock,
17-
RepeatBlock, Role, TextBlock,
15+
ArrayBlock, CallBlock, EvalsTo, FunctionBlock, ListOrString, MessageBlock, Metadata,
16+
ModelBlock, ObjectBlock, PdlBaseType, PdlBlock, PdlOptionalType, PdlParser, PdlType,
17+
PythonCodeBlock, RepeatBlock, Role, TextBlock,
1818
};
1919
use crate::pdl::pip::pip_install_if_needed;
2020
use crate::pdl::requirements::BEEAI_FRAMEWORK;
@@ -213,7 +213,7 @@ fn call_tools(model: &String, parameters: &HashMap<String, Value>) -> PdlBlock {
213213
&"${ tool.function.arguments }",
214214
),
215215
}),
216-
call: "${ pdl__tools[tool.function.name] }".to_string(), // look up tool in tool_declarations def (see below)
216+
call: EvalsTo::Jinja("${ pdl__tools[tool.function.name] }".to_string()), // look up tool in tool_declarations def (see below)
217217
args: Some("${ args }".into()), // invoke with arguments as specified by the model
218218
})),
219219
})],

pdl-live-react/src-tauri/src/pdl/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl Default for Metadata {
7474
#[serde(tag = "kind", rename = "call")]
7575
pub struct CallBlock {
7676
/// Function to call
77-
pub call: String,
77+
pub call: EvalsTo<String, Box<PdlResult>>,
7878

7979
/// Arguments of the function with their values
8080
#[serde(skip_serializing_if = "Option::is_none")]
@@ -88,7 +88,7 @@ pub struct CallBlock {
8888
impl CallBlock {
8989
pub fn new(call: String) -> Self {
9090
CallBlock {
91-
call: call,
91+
call: EvalsTo::Jinja(call),
9292
args: None,
9393
metadata: None,
9494
}
@@ -531,8 +531,8 @@ pub struct Expr<S, T> {
531531
#[derive(Serialize, Deserialize, Debug, Clone)]
532532
#[serde(untagged)]
533533
pub enum EvalsTo<S, T> {
534-
Const(T),
535534
Jinja(String),
535+
Const(T),
536536
Expr(Expr<S, T>),
537537
}
538538

pdl-live-react/src-tauri/src/pdl/interpreter.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,18 @@ impl<'a> Interpreter<'a> {
207207
}))
208208
}
209209

210+
fn eval_string(
211+
&self,
212+
expr: &EvalsTo<String, Box<PdlResult>>,
213+
state: &State,
214+
) -> Result<PdlResult, PdlError> {
215+
match expr {
216+
EvalsTo::Const(t) => Ok(*t.clone()),
217+
EvalsTo::Jinja(s) => self.eval(s, state),
218+
EvalsTo::Expr(e) => self.eval(&e.pdl_expr, state),
219+
}
220+
}
221+
210222
/// Evaluate an Expr to a bool
211223
fn eval_to_bool(
212224
&self,
@@ -414,7 +426,7 @@ impl<'a> Interpreter<'a> {
414426
eprintln!("Call scope {:?}", state.scope);
415427
}
416428

417-
match self.eval(&block.call, state)? {
429+
match self.eval_string(&block.call, state)? {
418430
PdlResult::Closure(c) => {
419431
let mut new_state = match &block.args {
420432
None => Ok(state.clone()),
@@ -1060,6 +1072,7 @@ pub async fn run_file<'a>(
10601072
let path = PathBuf::from(source_file_path);
10611073
let cwd = path.parent().and_then(|cwd| Some(cwd.to_path_buf()));
10621074
let program = parse_file(&path)?;
1075+
// println!("{}", serde_json::to_string_pretty(&program)?);
10631076

10641077
run(&program, cwd, options, initial_scope).await
10651078
}

0 commit comments

Comments
 (0)