diff --git a/pdl-live-react/src-tauri/src/compile/beeai.rs b/pdl-live-react/src-tauri/src/compile/beeai.rs index bd589fc94..c6807332e 100644 --- a/pdl-live-react/src-tauri/src/compile/beeai.rs +++ b/pdl-live-react/src-tauri/src/compile/beeai.rs @@ -13,8 +13,8 @@ use tempfile::Builder; use crate::pdl::ast::{ ArrayBlock, CallBlock, FunctionBlock, ListOrString, MessageBlock, ModelBlock, ObjectBlock, - PdlBaseType, PdlBlock, PdlOptionalType, PdlParser, PdlType, PythonCodeBlock, RepeatBlock, Role, - TextBlock, + PdlAdvancedBlock, PdlBaseType, PdlBlock, PdlOptionalType, PdlParser, PdlType, PythonCodeBlock, + RepeatBlock, Role, TextBlock, }; use crate::pdl::pip::pip_install_if_needed; use crate::pdl::requirements::BEEAI_FRAMEWORK; @@ -190,35 +190,39 @@ fn with_tools( } fn call_tools(model: &String, parameters: &HashMap) -> PdlBlock { - let repeat = PdlBlock::Text(TextBlock { + let repeat = PdlBlock::Advanced(PdlAdvancedBlock::Text(TextBlock { def: None, defs: None, role: None, parser: None, description: Some("Calling tool ${ tool.function.name }".to_string()), - text: vec![PdlBlock::Model( + text: vec![PdlBlock::Advanced(PdlAdvancedBlock::Model( ModelBlock::new(model.as_str()) .parameters(&strip_nulls(parameters)) - .input(PdlBlock::Array(ArrayBlock { - array: vec![PdlBlock::Message(MessageBlock { - role: Role::Tool, - description: None, - name: Some("${ tool.function.name }".to_string()), - tool_call_id: Some("${ tool.id }".to_string()), - content: Box::new(PdlBlock::Call(CallBlock { - defs: json_loads( - &"args", - &"pdl__args", - &"${ tool.function.arguments }", - ), - call: "${ 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 - })), - })], - })) + .input(PdlBlock::Advanced(PdlAdvancedBlock::Array(ArrayBlock { + array: vec![PdlBlock::Advanced(PdlAdvancedBlock::Message( + MessageBlock { + role: Role::Tool, + description: None, + name: Some("${ tool.function.name }".to_string()), + tool_call_id: Some("${ tool.id }".to_string()), + content: Box::new(PdlBlock::Advanced(PdlAdvancedBlock::Call( + CallBlock { + defs: json_loads( + &"args", + &"pdl__args", + &"${ tool.function.arguments }", + ), + call: "${ 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 + }, + ))), + }, + ))], + }))) .build(), - )], - }); + ))], + })); let mut for_ = HashMap::new(); for_.insert( @@ -227,10 +231,10 @@ fn call_tools(model: &String, parameters: &HashMap) -> PdlBlock { ); // response.choices[0].message.tool_calls - PdlBlock::Repeat(RepeatBlock { + PdlBlock::Advanced(PdlAdvancedBlock::Repeat(RepeatBlock { for_: for_, repeat: Box::new(repeat), - }) + })) } fn json_loads( @@ -241,7 +245,7 @@ fn json_loads( let mut m = indexmap::IndexMap::new(); m.insert( outer_name.to_owned(), - PdlBlock::Text( + PdlBlock::Advanced(PdlAdvancedBlock::Text( TextBlock::new(vec![PdlBlock::String(format!( "{{\"{}\": {}}}", inner_name, value @@ -249,7 +253,7 @@ fn json_loads( .description(format!("Parsing json for {}={}", inner_name, value)) .parser(PdlParser::Json) .build(), - ), + )), ); Some(m) } @@ -396,13 +400,14 @@ pub fn compile(source_file_path: &str, debug: bool) -> Result 0 { @@ -500,29 +506,28 @@ asyncio.run(invoke()) let mut defs = indexmap::IndexMap::new(); defs.insert( closure_name.clone(), - PdlBlock::Function(FunctionBlock { + PdlBlock::Advanced(PdlAdvancedBlock::Function(FunctionBlock { function: HashMap::new(), - return_: Box::new(PdlBlock::Text(TextBlock { + return_: Box::new(PdlBlock::Advanced(PdlAdvancedBlock::Text(TextBlock { def: None, defs: None, role: None, parser: None, description: Some(format!("Model call {}", &model)), text: model_call, - })), - }), + }))), + })), ); - PdlBlock::Text(TextBlock { + PdlBlock::Advanced(PdlAdvancedBlock::Text(TextBlock { def: None, defs: Some(defs), role: None, parser: None, description: Some("Model call wrapper".to_string()), - text: vec![PdlBlock::Call(CallBlock::new(format!( - "${{ {} }}", - closure_name + text: vec![PdlBlock::Advanced(PdlAdvancedBlock::Call(CallBlock::new( + format!("${{ {} }}", closure_name), )))], - }) + })) }, ) .collect::>(); @@ -531,7 +536,7 @@ asyncio.run(invoke()) .flat_map(|(a, b)| [a, b]) .collect::>(); - let pdl: PdlBlock = PdlBlock::Text(TextBlock { + let pdl: PdlBlock = PdlBlock::Advanced(PdlAdvancedBlock::Text(TextBlock { def: None, defs: if tool_declarations.len() == 0 { None @@ -539,9 +544,9 @@ asyncio.run(invoke()) let mut m = indexmap::IndexMap::new(); m.insert( "pdl__tools".to_string(), - PdlBlock::Object(ObjectBlock { + PdlBlock::Advanced(PdlAdvancedBlock::Object(ObjectBlock { object: tool_declarations, - }), + })), ); Some(m) }, @@ -549,7 +554,7 @@ asyncio.run(invoke()) role: None, parser: None, text: body, - }); + })); Ok(pdl) } diff --git a/pdl-live-react/src-tauri/src/pdl/ast.rs b/pdl-live-react/src-tauri/src/pdl/ast.rs index 5fd8d24ad..c3041657b 100644 --- a/pdl-live-react/src-tauri/src/pdl/ast.rs +++ b/pdl-live-react/src-tauri/src/pdl/ast.rs @@ -53,6 +53,7 @@ pub enum PdlType { /// Call a function #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "kind", rename = "call")] pub struct CallBlock { /// Function to call pub call: String, @@ -91,6 +92,7 @@ pub trait SequencingBlock { /// Return the value of the last block if the list of blocks #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "kind", rename = "lastOf")] pub struct LastOfBlock { /// Sequence of blocks to execute #[serde(rename = "lastOf")] @@ -139,7 +141,7 @@ impl SequencingBlock for LastOfBlock { &self.parser } fn to_block(&self) -> PdlBlock { - PdlBlock::LastOf(self.clone()) + PdlBlock::Advanced(PdlAdvancedBlock::LastOf(self.clone())) } fn result_for(&self, output_results: Vec) -> PdlResult { match output_results.last() { @@ -158,6 +160,7 @@ impl SequencingBlock for LastOfBlock { /// Create the concatenation of the stringify version of the result of /// each block of the list of blocks. #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "kind", rename = "text")] pub struct TextBlock { /// Body of the text pub text: Vec, @@ -205,7 +208,7 @@ impl SequencingBlock for TextBlock { &self.parser } fn to_block(&self) -> PdlBlock { - PdlBlock::Text(self.clone()) + PdlBlock::Advanced(PdlAdvancedBlock::Text(self.clone())) } fn result_for(&self, output_results: Vec) -> PdlResult { PdlResult::String( @@ -260,6 +263,7 @@ impl From> for TextBlock { } #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "kind", rename = "function")] pub struct FunctionBlock { pub function: HashMap, #[serde(rename = "return")] @@ -279,6 +283,7 @@ pub struct PdlUsage { } #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "kind", rename = "model")] pub struct ModelBlock { #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, @@ -352,6 +357,7 @@ pub enum ListOrString { /// "${ name }'s number is ${ number }\\n" /// ``` #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "kind", rename = "repeat")] pub struct RepeatBlock { /// Arrays to iterate over #[serde(rename = "for")] @@ -363,6 +369,7 @@ pub struct RepeatBlock { /// Create a message #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "kind", rename = "message")] pub struct MessageBlock { /// Role of associated to the message, e.g. User or Assistant pub role: Role, @@ -386,6 +393,7 @@ pub struct MessageBlock { /// block. If the body of the object is an array, the resulting object /// is the union of the objects computed by each element of the array. #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "kind", rename = "object")] pub struct ObjectBlock { pub object: HashMap, } @@ -413,6 +421,7 @@ pub struct ObjectBlock { /// def: EXTRACTED_GROUND_TRUTH /// ``` #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "kind")] pub struct DataBlock { pub data: Value, @@ -438,6 +447,7 @@ pub struct DataBlock { /// result = random.randint(1, 20) /// ``` #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "kind", rename = "code")] pub struct PythonCodeBlock { pub lang: String, pub code: String, @@ -464,6 +474,7 @@ pub enum StringOrNull { /// parser: yaml /// ``` #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "kind", rename = "read")] pub struct ReadBlock { /// Name of the file to read. If `None`, read the standard input. pub read: StringOrNull, @@ -500,6 +511,7 @@ pub enum StringOrBoolean { /// then: You won! /// ``` #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "kind", rename = "if")] pub struct IfBlock { /// The condition to check #[serde(rename = "if")] @@ -519,6 +531,7 @@ pub struct IfBlock { /// Return the array of values computed by each block of the list of blocks #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "kind", rename = "array")] pub struct ArrayBlock { /// Elements of the array pub array: Vec, @@ -526,6 +539,7 @@ pub struct ArrayBlock { /// Include a PDL file #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "kind", rename = "include")] pub struct IncludeBlock { /// Name of the file to include. pub include: String, @@ -533,6 +547,7 @@ pub struct IncludeBlock { /// Import a PDL file #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "kind", rename = "import")] pub struct ImportBlock { /// Name of the file to include. pub import: String, @@ -540,16 +555,25 @@ pub struct ImportBlock { /// Block containing only defs #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "kind", rename = "empty")] pub struct EmptyBlock { pub defs: IndexMap, } +/// A PDL program/sub-program consists of either a literal (string, number, boolean) or some kind of structured/"Advanced" block #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(untagged)] pub enum PdlBlock { Bool(bool), Number(Number), String(String), + Advanced(PdlAdvancedBlock), +} + +/// Some kind of non-literal block, i.e. a block with some structure +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(untagged)] +pub enum PdlAdvancedBlock { If(IfBlock), Import(ImportBlock), Include(IncludeBlock), @@ -570,6 +594,12 @@ pub enum PdlBlock { Empty(EmptyBlock), } +impl From for PdlBlock { + fn from(b: bool) -> Self { + PdlBlock::Bool(b) + } +} + impl From<&str> for PdlBlock { fn from(s: &str) -> Self { PdlBlock::String(s.into()) diff --git a/pdl-live-react/src-tauri/src/pdl/extract.rs b/pdl-live-react/src-tauri/src/pdl/extract.rs index a33416288..ec2823780 100644 --- a/pdl-live-react/src-tauri/src/pdl/extract.rs +++ b/pdl-live-react/src-tauri/src/pdl/extract.rs @@ -1,4 +1,4 @@ -use crate::pdl::ast::PdlBlock; +use crate::pdl::ast::{PdlAdvancedBlock, PdlBlock}; /// Extract models referenced by the programs pub fn extract_models(program: &PdlBlock) -> Vec { @@ -20,35 +20,39 @@ pub fn extract_values(program: &PdlBlock, field: &str) -> Vec { /// Take one Yaml fragment and produce a vector of the string-valued entries of the given field fn extract_values_iter(program: &PdlBlock, field: &str, values: &mut Vec) { match program { - PdlBlock::Model(b) => values.push(b.model.clone()), - PdlBlock::Repeat(b) => { - extract_values_iter(&b.repeat, field, values); - } - PdlBlock::Message(b) => { - extract_values_iter(&b.content, field, values); - } - PdlBlock::Array(b) => b - .array - .iter() - .for_each(|p| extract_values_iter(p, field, values)), - PdlBlock::Text(b) => b - .text - .iter() - .for_each(|p| extract_values_iter(p, field, values)), - PdlBlock::LastOf(b) => b - .last_of - .iter() - .for_each(|p| extract_values_iter(p, field, values)), - PdlBlock::If(b) => { - extract_values_iter(&b.then, field, values); - if let Some(else_) = &b.else_ { - extract_values_iter(else_, field, values); + PdlBlock::Advanced(b) => match b { + PdlAdvancedBlock::Model(b) => values.push(b.model.clone()), + PdlAdvancedBlock::Repeat(b) => { + extract_values_iter(&b.repeat, field, values); } - } - PdlBlock::Object(b) => b - .object - .values() - .for_each(|p| extract_values_iter(p, field, values)), + PdlAdvancedBlock::Message(b) => { + extract_values_iter(&b.content, field, values); + } + PdlAdvancedBlock::Array(b) => b + .array + .iter() + .for_each(|p| extract_values_iter(p, field, values)), + PdlAdvancedBlock::Text(b) => b + .text + .iter() + .for_each(|p| extract_values_iter(p, field, values)), + PdlAdvancedBlock::LastOf(b) => b + .last_of + .iter() + .for_each(|p| extract_values_iter(p, field, values)), + PdlAdvancedBlock::If(b) => { + extract_values_iter(&b.then, field, values); + if let Some(else_) = &b.else_ { + extract_values_iter(else_, field, values); + } + } + PdlAdvancedBlock::Object(b) => b + .object + .values() + .for_each(|p| extract_values_iter(p, field, values)), + + _ => {} + }, _ => {} } } diff --git a/pdl-live-react/src-tauri/src/pdl/interpreter.rs b/pdl-live-react/src-tauri/src/pdl/interpreter.rs index 21dbb96ea..9fd3bea3e 100644 --- a/pdl-live-react/src-tauri/src/pdl/interpreter.rs +++ b/pdl-live-react/src-tauri/src/pdl/interpreter.rs @@ -23,9 +23,9 @@ use serde_norway::{from_reader, from_str as from_yaml_str}; use crate::pdl::ast::{ ArrayBlock, CallBlock, Closure, DataBlock, EmptyBlock, FunctionBlock, IfBlock, ImportBlock, - IncludeBlock, ListOrString, MessageBlock, ModelBlock, ObjectBlock, PdlBlock, PdlParser, - PdlResult, PdlUsage, PythonCodeBlock, ReadBlock, RepeatBlock, Role, Scope, SequencingBlock, - StringOrBoolean, StringOrNull, + IncludeBlock, ListOrString, MessageBlock, ModelBlock, ObjectBlock, PdlAdvancedBlock, PdlBlock, + PdlParser, PdlResult, PdlUsage, PythonCodeBlock, ReadBlock, RepeatBlock, Role, Scope, + SequencingBlock, StringOrBoolean, StringOrNull, }; type Context = Vec; @@ -87,39 +87,46 @@ impl<'a> Interpreter<'a> { self.emit = emit; let (result, messages, trace) = match program { + PdlBlock::Bool(b) => Ok(( + b.into(), + vec![ChatMessage::user(format!("{b}"))], + PdlBlock::Bool(b.clone()), + )), PdlBlock::Number(n) => Ok(( n.clone().into(), vec![ChatMessage::user(format!("{n}"))], PdlBlock::Number(n.clone()), )), - PdlBlock::Function(f) => Ok(( - PdlResult::Closure(self.closure(&f)), - vec![], - PdlBlock::Function(f.clone()), - )), PdlBlock::String(s) => self.run_string(s, context).await, - PdlBlock::Call(block) => self.run_call(block, context).await, - PdlBlock::Empty(block) => self.run_empty(block, context).await, - PdlBlock::If(block) => self.run_if(block, context).await, - PdlBlock::Import(block) => self.run_import(block, context).await, - PdlBlock::Include(block) => self.run_include(block, context).await, - PdlBlock::Model(block) => self.run_model(block, context).await, - PdlBlock::Data(block) => self.run_data(block, context).await, - PdlBlock::Object(block) => self.run_object(block, context).await, - PdlBlock::PythonCode(block) => self.run_python_code(block, context).await, - PdlBlock::Read(block) => self.run_read(block, context).await, - PdlBlock::Repeat(block) => self.run_repeat(block, context).await, - PdlBlock::LastOf(block) => self.run_sequence(block, context).await, - PdlBlock::Text(block) => self.run_sequence(block, context).await, - PdlBlock::Array(block) => self.run_array(block, context).await, - PdlBlock::Message(block) => self.run_message(block, context).await, - _ => Err(Box::from(format!("Unsupported block {:?}", program))), + PdlBlock::Advanced(b) => match b { + PdlAdvancedBlock::Function(f) => Ok(( + PdlResult::Closure(self.closure(&f)), + vec![], + PdlBlock::Advanced(PdlAdvancedBlock::Function(f.clone())), + )), + PdlAdvancedBlock::Call(block) => self.run_call(block, context).await, + PdlAdvancedBlock::Empty(block) => self.run_empty(block, context).await, + PdlAdvancedBlock::If(block) => self.run_if(block, context).await, + PdlAdvancedBlock::Import(block) => self.run_import(block, context).await, + PdlAdvancedBlock::Include(block) => self.run_include(block, context).await, + PdlAdvancedBlock::Model(block) => self.run_model(block, context).await, + PdlAdvancedBlock::Data(block) => self.run_data(block, context).await, + PdlAdvancedBlock::Object(block) => self.run_object(block, context).await, + PdlAdvancedBlock::PythonCode(block) => self.run_python_code(block, context).await, + PdlAdvancedBlock::Read(block) => self.run_read(block, context).await, + PdlAdvancedBlock::Repeat(block) => self.run_repeat(block, context).await, + PdlAdvancedBlock::LastOf(block) => self.run_sequence(block, context).await, + PdlAdvancedBlock::Text(block) => self.run_sequence(block, context).await, + PdlAdvancedBlock::Array(block) => self.run_array(block, context).await, + PdlAdvancedBlock::Message(block) => self.run_message(block, context).await, + }, }?; if match program { - PdlBlock::Text(_) | PdlBlock::LastOf(_) | PdlBlock::Call(_) | PdlBlock::Model(_) => { - false - } + PdlBlock::Advanced(PdlAdvancedBlock::Text(_)) + | PdlBlock::Advanced(PdlAdvancedBlock::LastOf(_)) + | PdlBlock::Advanced(PdlAdvancedBlock::Call(_)) + | PdlBlock::Advanced(PdlAdvancedBlock::Model(_)) => false, _ => self.emit, } { println!("{}", pretty_print(&messages)); @@ -305,7 +312,7 @@ impl<'a> Interpreter<'a> { Ok(( result, vec![ChatMessage::user(buffer)], - PdlBlock::Read(trace), + PdlBlock::Advanced(PdlAdvancedBlock::Read(trace)), )) } @@ -324,10 +331,7 @@ impl<'a> Interpreter<'a> { self.push_and_extend_scope_with(m, c.scope); Ok(()) } - x => Err(PdlError::from(format!( - "Call arguments not a map: {:?}", - x - ))), + x => Err(PdlError::from(format!("Call arguments not a map: {:?}", x))), }?; } @@ -357,7 +361,7 @@ impl<'a> Interpreter<'a> { Ok(( PdlResult::Dict(self.scope.last().unwrap_or(&HashMap::new()).clone()), vec![], - PdlBlock::Empty(trace), + PdlBlock::Advanced(PdlAdvancedBlock::Empty(trace)), )) } @@ -377,7 +381,11 @@ impl<'a> Interpreter<'a> { PdlResult::Bool(true) => self.run_quiet(&block.then, context).await, PdlResult::Bool(false) => match &block.else_ { Some(else_block) => self.run_quiet(&else_block, context).await, - None => Ok(("".into(), vec![], PdlBlock::If(block.clone()))), + None => Ok(( + "".into(), + vec![], + PdlBlock::Advanced(PdlAdvancedBlock::If(block.clone())), + )), }, x => Err(Box::from(format!( "if block condition evaluated to non-boolean value: {:?}", @@ -513,9 +521,7 @@ impl<'a> Interpreter<'a> { Ok(_) => Ok(()), Err(exc) => { vm.print_exception(exc); - Err(PdlError::from( - "Error executing Python code", - )) + Err(PdlError::from("Error executing Python code")) } }?; @@ -525,13 +531,11 @@ impl<'a> Interpreter<'a> { Ok(x) => Ok(x), Err(exc) => { vm.print_exception(exc); - Err(PdlError::from( - "Unable to stringify Python 'result' value", - )) + Err(PdlError::from("Unable to stringify Python 'result' value")) } }?; let messages = vec![ChatMessage::user(result_string.as_str().to_string())]; - let trace = PdlBlock::PythonCode(block.clone()); + let trace = PdlBlock::Advanced(PdlAdvancedBlock::PythonCode(block.clone())); Ok((messages[0].content.clone().into(), messages, trace)) } Err(_) => Err(Box::from( @@ -664,11 +668,15 @@ impl<'a> Interpreter<'a> { Ok(( res.message.content.into(), output_messages, - PdlBlock::Model(trace), + PdlBlock::Advanced(PdlAdvancedBlock::Model(trace)), )) } else { // nothing came out of the model - Ok(("".into(), vec![], PdlBlock::Model(trace))) + Ok(( + "".into(), + vec![], + PdlBlock::Advanced(PdlAdvancedBlock::Model(trace)), + )) } // dbg!(history); } @@ -712,11 +720,19 @@ impl<'a> Interpreter<'a> { let mut trace = block.clone(); if let Some(true) = block.raw { let result = self.def(&block.def, &self.resultify(&block.data), &block.parser)?; - Ok((result, vec![], PdlBlock::Data(trace))) + Ok(( + result, + vec![], + PdlBlock::Advanced(PdlAdvancedBlock::Data(trace)), + )) } else { let result = self.def(&block.def, &self.eval_json(&block.data)?, &block.parser)?; trace.data = from_str(to_string(&result)?.as_str())?; - Ok((result, vec![], PdlBlock::Data(trace))) + Ok(( + result, + vec![], + PdlBlock::Advanced(PdlAdvancedBlock::Data(trace)), + )) } } @@ -741,7 +757,7 @@ impl<'a> Interpreter<'a> { Ok(( PdlResult::Dict(result_map), messages, - PdlBlock::Object(ObjectBlock { object: trace_map }), + PdlBlock::Advanced(PdlAdvancedBlock::Object(ObjectBlock { object: trace_map })), )) } @@ -785,7 +801,7 @@ impl<'a> Interpreter<'a> { Ok(( PdlResult::List(results), messages, - PdlBlock::Repeat(block.clone()), + PdlBlock::Advanced(PdlAdvancedBlock::Repeat(block.clone())), )) } @@ -919,7 +935,7 @@ impl<'a> Interpreter<'a> { Ok(( PdlResult::List(result_items), all_messages, - PdlBlock::Array(ArrayBlock { array: trace_items }), + PdlBlock::Advanced(PdlAdvancedBlock::Array(ArrayBlock { array: trace_items })), )) } @@ -957,13 +973,13 @@ impl<'a> Interpreter<'a> { .into_iter() .map(|m| ChatMessage::new(self.to_ollama_role(&block.role), m.content)) .collect(), - PdlBlock::Message(MessageBlock { + PdlBlock::Advanced(PdlAdvancedBlock::Message(MessageBlock { role: block.role.clone(), content: Box::new(content_trace), description: block.description.clone(), name: name, tool_call_id: tool_call_id, - }), + })), )) } } @@ -998,8 +1014,7 @@ pub fn run_sync( /// Read in a file from disk and parse it as a PDL program pub fn parse_file(path: &PathBuf) -> Result { - from_reader(::std::fs::File::open(path)?) - .map_err(|err| PdlError::from(err.to_string())) + from_reader(::std::fs::File::open(path)?).map_err(|err| PdlError::from(err.to_string())) } pub async fn run_file(source_file_path: &str, debug: bool, stream: bool) -> Interpretation { diff --git a/pdl-live-react/src-tauri/src/pdl/interpreter_tests.rs b/pdl-live-react/src-tauri/src/pdl/interpreter_tests.rs index 436aef3cc..c8cd6f20f 100644 --- a/pdl-live-react/src-tauri/src/pdl/interpreter_tests.rs +++ b/pdl-live-react/src-tauri/src/pdl/interpreter_tests.rs @@ -5,7 +5,7 @@ mod tests { use serde_json::json; use crate::pdl::{ - ast::{ModelBlock, PdlBlock}, + ast::{ModelBlock, PdlAdvancedBlock, PdlBlock}, interpreter::{run_json_sync as run_json, run_sync as run}, }; @@ -25,7 +25,9 @@ mod tests { #[test] fn single_model_via_input_string() -> Result<(), Box> { let (_, messages, _) = run( - &PdlBlock::Model(ModelBlock::new(DEFAULT_MODEL).input_str("hello").build()), + &PdlBlock::Advanced(PdlAdvancedBlock::Model( + ModelBlock::new(DEFAULT_MODEL).input_str("hello").build(), + )), None, false, true,