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
18 changes: 10 additions & 8 deletions pdl-live-react/src-tauri/src/compile/beeai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ fn with_tools(

fn call_tools(model: &String, parameters: &HashMap<String, Value>) -> PdlBlock {
let repeat = PdlBlock::Text(TextBlock {
def: None,
metadata: None,
role: None,
parser: None,
Expand All @@ -207,6 +206,7 @@ fn call_tools(model: &String, parameters: &HashMap<String, Value>) -> PdlBlock {
tool_call_id: Some("${ tool.id }".to_string()),
content: Box::new(PdlBlock::Call(CallBlock {
metadata: Some(Metadata {
def: None,
defs: json_loads(
&"args",
&"pdl__args",
Expand Down Expand Up @@ -465,7 +465,6 @@ asyncio.run(invoke())
model_call.push(PdlBlock::Text(TextBlock {
role: Some(Role::System),
text: vec![PdlBlock::String(instructions)],
def: None,
metadata: None,
parser: None,
description: Some("Model instructions".into()),
Expand All @@ -482,9 +481,9 @@ asyncio.run(invoke())
};

model_call.push(PdlBlock::Model(ModelBlock {
metadata: None,
input: None,
description: Some(description),
def: None,
model: model.clone(),
model_response: model_response,
pdl_result: None,
Expand All @@ -505,7 +504,6 @@ asyncio.run(invoke())
PdlBlock::Function(FunctionBlock {
function: HashMap::new(),
return_: Box::new(PdlBlock::Text(TextBlock {
def: None,
metadata: None,
role: None,
parser: None,
Expand All @@ -515,8 +513,10 @@ asyncio.run(invoke())
}),
);
PdlBlock::Text(TextBlock {
def: None,
metadata: Some(Metadata { defs: Some(defs) }),
metadata: Some(Metadata {
def: None,
defs: Some(defs),
}),
role: None,
parser: None,
description: Some("Model call wrapper".to_string()),
Expand All @@ -534,7 +534,6 @@ asyncio.run(invoke())
.collect::<Vec<_>>();

let pdl: PdlBlock = PdlBlock::Text(TextBlock {
def: None,
metadata: if tool_declarations.len() == 0 {
None
} else {
Expand All @@ -545,7 +544,10 @@ asyncio.run(invoke())
object: tool_declarations,
}),
);
Some(Metadata { defs: Some(m) })
Some(Metadata {
def: None,
defs: Some(m),
})
},
description: Some(bee.workflow.workflow.name),
role: None,
Expand Down
58 changes: 34 additions & 24 deletions pdl-live-react/src-tauri/src/pdl/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ pub enum PdlType {
pub struct Metadata {
#[serde(skip_serializing_if = "Option::is_none")]
pub defs: Option<IndexMap<String, PdlBlock>>,

#[serde(skip_serializing_if = "Option::is_none")]
pub def: Option<String>,
}
impl Default for Metadata {
fn default() -> Self {
Self {
defs: None,
def: None,
}
}
}

/// Call a function
Expand Down Expand Up @@ -88,7 +99,6 @@ pub trait SequencingBlock {
fn kind(&self) -> &str;
fn description(&self) -> &Option<String>;
fn role(&self) -> &Option<Role>;
fn def(&self) -> &Option<String>;
fn metadata(&self) -> &Option<Metadata>;
fn items(&self) -> &Vec<PdlBlock>;
fn with_items(&self, items: Vec<PdlBlock>) -> Self;
Expand Down Expand Up @@ -118,9 +128,6 @@ pub struct LastOfBlock {

#[serde(skip_serializing_if = "Option::is_none")]
pub parser: Option<PdlParser>,

#[serde(skip_serializing_if = "Option::is_none")]
pub def: Option<String>,
}
impl SequencingBlock for LastOfBlock {
fn kind(&self) -> &str {
Expand All @@ -132,9 +139,6 @@ impl SequencingBlock for LastOfBlock {
fn role(&self) -> &Option<Role> {
&self.role
}
fn def(&self) -> &Option<String> {
return &self.def;
}
fn metadata(&self) -> &Option<Metadata> {
&self.metadata
}
Expand Down Expand Up @@ -186,9 +190,6 @@ pub struct TextBlock {

#[serde(skip_serializing_if = "Option::is_none")]
pub parser: Option<PdlParser>,

#[serde(skip_serializing_if = "Option::is_none")]
pub def: Option<String>,
}
impl SequencingBlock for TextBlock {
fn kind(&self) -> &str {
Expand All @@ -200,9 +201,6 @@ impl SequencingBlock for TextBlock {
fn role(&self) -> &Option<Role> {
&self.role
}
fn def(&self) -> &Option<String> {
return &self.def;
}
fn metadata(&self) -> &Option<Metadata> {
&self.metadata
}
Expand Down Expand Up @@ -237,7 +235,6 @@ impl SequencingBlock for TextBlock {
impl TextBlock {
pub fn new(text: Vec<PdlBlock>) -> Self {
TextBlock {
def: None,
metadata: None,
description: None,
role: None,
Expand All @@ -247,7 +244,16 @@ impl TextBlock {
}

pub fn def(&mut self, def: &str) -> &mut Self {
self.def = Some(def.into());
match &mut self.metadata {
Some(metadata) => {
metadata.def = Some(def.into());
}
None => {
let mut metadata: Metadata = Default::default();
metadata.def = Some(def.into());
self.metadata = Some(metadata);
}
}
self
}

Expand Down Expand Up @@ -295,12 +301,14 @@ pub struct PdlUsage {
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "kind", rename = "model")]
pub struct ModelBlock {
#[serde(flatten)]
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
pub model: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub def: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parameters: Option<HashMap<String, Value>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub input: Option<Box<PdlBlock>>,
Expand All @@ -318,7 +326,7 @@ pub struct ModelBlock {
impl ModelBlock {
pub fn new(model: &str) -> Self {
ModelBlock {
def: None,
metadata: None,
description: None,
model_response: None,
parameters: None,
Expand Down Expand Up @@ -433,15 +441,16 @@ pub struct ObjectBlock {
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "kind")]
pub struct DataBlock {
#[serde(flatten)]
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

pub data: Value,

/// Do not evaluate expressions inside strings.
#[serde(skip_serializing_if = "Option::is_none")]
pub raw: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
pub def: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
pub parser: Option<PdlParser>,
}
Expand Down Expand Up @@ -486,6 +495,10 @@ pub enum StringOrNull {
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "kind", rename = "read")]
pub struct ReadBlock {
#[serde(flatten)]
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// Name of the file to read. If `None`, read the standard input.
pub read: StringOrNull,

Expand All @@ -495,9 +508,6 @@ pub struct ReadBlock {
/// Indicate if one or multiple lines should be read.
pub multiline: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
pub def: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
pub parser: Option<PdlParser>,
}
Expand Down
8 changes: 4 additions & 4 deletions pdl-live-react/src-tauri/src/pdl/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ impl<'a> Interpreter<'a> {
};

let result = self.def(
&block.def,
&block.metadata.as_ref().and_then(|m| m.def.clone()),
&buffer.clone().into(),
&block.parser,
state,
Expand Down Expand Up @@ -747,7 +747,7 @@ impl<'a> Interpreter<'a> {
let mut trace = block.clone();
if let Some(true) = block.raw {
let result = self.def(
&block.def,
&block.metadata.as_ref().and_then(|m| m.def.clone()),
&resultify(&block.data),
&block.parser,
state,
Expand All @@ -756,7 +756,7 @@ impl<'a> Interpreter<'a> {
Ok((result, vec![], PdlBlock::Data(trace)))
} else {
let result = self.def(
&block.def,
&block.metadata.as_ref().and_then(|m| m.def.clone()),
&self.eval_json(&block.data, state)?,
&block.parser,
state,
Expand Down Expand Up @@ -914,7 +914,7 @@ impl<'a> Interpreter<'a> {

let trace = block.with_items(output_blocks);
let result = self.def(
trace.def(),
&block.metadata().as_ref().and_then(|m| m.def.clone()),
&trace.result_for(output_results),
trace.parser(),
state,
Expand Down