Skip to content
Merged
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
8 changes: 4 additions & 4 deletions pdl-live-react/src-tauri/src/compile/beeai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use serde_json::{from_reader, json, to_string, Map, Value};
use tempfile::Builder;

use crate::pdl::ast::{
ArrayBlock, CallBlock, FunctionBlock, ListOrString, MessageBlock, Metadata, ModelBlock,
ObjectBlock, PdlBaseType, PdlBlock, PdlOptionalType, PdlParser, PdlType, PythonCodeBlock,
RepeatBlock, Role, TextBlock,
ArrayBlock, CallBlock, EvalsTo, FunctionBlock, ListOrString, MessageBlock, Metadata,
ModelBlock, ObjectBlock, PdlBaseType, PdlBlock, PdlOptionalType, PdlParser, PdlType,
PythonCodeBlock, RepeatBlock, Role, TextBlock,
};
use crate::pdl::pip::pip_install_if_needed;
use crate::pdl::requirements::BEEAI_FRAMEWORK;
Expand Down Expand Up @@ -213,7 +213,7 @@ fn call_tools(model: &String, parameters: &HashMap<String, Value>) -> PdlBlock {
&"${ tool.function.arguments }",
),
}),
call: "${ pdl__tools[tool.function.name] }".to_string(), // look up tool in tool_declarations def (see below)
call: EvalsTo::Jinja("${ pdl__tools[tool.function.name] }".to_string()), // look up tool in tool_declarations def (see below)
args: Some("${ args }".into()), // invoke with arguments as specified by the model
})),
})],
Expand Down
6 changes: 3 additions & 3 deletions pdl-live-react/src-tauri/src/pdl/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Default for Metadata {
#[serde(tag = "kind", rename = "call")]
pub struct CallBlock {
/// Function to call
pub call: String,
pub call: EvalsTo<String, Box<PdlResult>>,

/// Arguments of the function with their values
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -88,7 +88,7 @@ pub struct CallBlock {
impl CallBlock {
pub fn new(call: String) -> Self {
CallBlock {
call: call,
call: EvalsTo::Jinja(call),
args: None,
metadata: None,
}
Expand Down Expand Up @@ -531,8 +531,8 @@ pub struct Expr<S, T> {
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(untagged)]
pub enum EvalsTo<S, T> {
Const(T),
Jinja(String),
Const(T),
Expr(Expr<S, T>),
}

Expand Down
15 changes: 14 additions & 1 deletion pdl-live-react/src-tauri/src/pdl/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ impl<'a> Interpreter<'a> {
}))
}

fn eval_string(
&self,
expr: &EvalsTo<String, Box<PdlResult>>,
state: &State,
) -> Result<PdlResult, PdlError> {
match expr {
EvalsTo::Const(t) => Ok(*t.clone()),
EvalsTo::Jinja(s) => self.eval(s, state),
EvalsTo::Expr(e) => self.eval(&e.pdl_expr, state),
}
}

/// Evaluate an Expr to a bool
fn eval_to_bool(
&self,
Expand Down Expand Up @@ -414,7 +426,7 @@ impl<'a> Interpreter<'a> {
eprintln!("Call scope {:?}", state.scope);
}

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

run(&program, cwd, options, initial_scope).await
}
Expand Down