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
2 changes: 1 addition & 1 deletion pdl-live-react/src-tauri/src/compile/beeai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fn call_tools(model: &String, parameters: &HashMap<String, Value>) -> PdlBlock {
metadata: None,
body: Message(MessageBlock {
role: Role::Tool,
pdl__defsite: None,
pdl_defsite: None,
name: Some("${ tool.function.name }".to_string()),
tool_call_id: Some("${ tool.id }".to_string()),
content: Box::new(Advanced(Block {
Expand Down
4 changes: 2 additions & 2 deletions pdl-live-react/src-tauri/src/pdl/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ pub struct MessageBlock {
pub content: Box<PdlBlock>,

/// pdl_id of block that defined the `content of this message
#[serde(skip_serializing_if = "Option::is_none")]
pub pdl__defsite: Option<String>,
#[serde(rename = "pdl__defsite", skip_serializing_if = "Option::is_none")]
pub pdl_defsite: Option<String>,

/// For example, the name of the tool that was invoked, for which this message is the tool response
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
6 changes: 3 additions & 3 deletions pdl-live-react/src-tauri/src/pdl/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ impl<'a> Interpreter<'a> {
content: Box::new(PdlBlock::String(m.content.clone())),
name: None,
tool_call_id: None,
pdl__defsite: None,
pdl_defsite: None,
})
.collect(),
);
Expand All @@ -1094,7 +1094,7 @@ impl<'a> Interpreter<'a> {
content: Box::new(PdlBlock::String(m.content.clone())),
name: None,
tool_call_id: None,
pdl__defsite: None,
pdl_defsite: None,
})
.collect(),
);
Expand Down Expand Up @@ -1476,7 +1476,7 @@ impl<'a> Interpreter<'a> {
role: block.role.clone(),
content: Box::new(content_trace),
name: name,
pdl__defsite: None,
pdl_defsite: None,
tool_call_id: tool_call_id,
}),
))
Expand Down
9 changes: 6 additions & 3 deletions pdl-live-react/src/pdl_ast.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,6 @@ export type Else =
| ErrorBlock
| EmptyBlock
| null
export type IfResult = boolean | null
/**
* Name of the variable used to store the result of the execution of the block.
*
Expand Down Expand Up @@ -2705,6 +2704,11 @@ export type PdlContext19 =
export type PdlId19 = string | null
export type PdlIsLeaf19 = true
export type Kind19 = "call"
/**
* Function to call.
*
*/
export type Call = LocalizedExpression | FunctionBlock | string
export type PdlTrace3 =
| boolean
| number
Expand Down Expand Up @@ -3048,7 +3052,7 @@ export interface CallBlock {
pdl__timing?: PdlTiming | null
pdl__is_leaf?: PdlIsLeaf19
kind?: Kind19
call: unknown
call: Call
args?: unknown
pdl__trace?: PdlTrace3
}
Expand Down Expand Up @@ -3715,7 +3719,6 @@ export interface IfBlock {
if: If1
then: Then1
else?: Else
if_result?: IfResult
}
/**
* Set of definitions executed before the execution of the block.
Expand Down
42 changes: 25 additions & 17 deletions pdl-live-react/src/view/detail/kind/If.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
import { match, P } from "ts-pattern"
import Group from "../Group"
import { stringify } from "yaml"

export default function ModelItems({
block: { if: condition, if_result },
block: { if: condition },
}: {
block: import("../../../pdl_ast").IfBlock
}) {
return (
<>
{typeof condition === "string" && (
<Group
description={condition.replace(/^\$\{*(.+)\}$/, "$1").trim()}
term="Condition"
/>
)}
{if_result !== undefined && (
<Group
description={
if_result === true
? "Then (condition is true)"
: "Else (condition is false)"
}
term="Then or Else?"
/>
)}
{match(condition)
.with(P.string, (cond) => (
<Group description={cond.trim()} term="Condition" />
))
.with({ pdl__expr: P._ }, (cond) => (
<Group description={stringify(cond.pdl__expr)} term="Condition" />
))
.otherwise((cond) => (
<Group description={stringify(cond)} term="Condition" />
))}
{match(condition)
.with({ pdl__result: P.boolean }, (cond) => (
<Group
description={
cond.pdl__result
? "Then (condition is true)"
: "Else (condition is false)"
}
term="Then or Else?"
/>
))
.otherwise(() => false)}
</>
)
}
7 changes: 4 additions & 3 deletions pdl-live-react/src/view/timeline/model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { match } from "ts-pattern"
import { match, P } from "ts-pattern"

import { type PdlBlock } from "../../pdl_ast"
import {
Expand Down Expand Up @@ -127,9 +127,10 @@ export function childrenOf(block: NonScalarPdlBlock) {
.with({ kind: "code" }, (data) => [data.pdl__result])
.with({ kind: "get" }, (data) => [data.pdl__result])
.with({ kind: "data" }, (data) => [data.pdl__result])
.with({ kind: "if" }, (data) =>
data.if_result ? [data.then] : [data.else],
.with({ kind: "if", if: { pdl__result: P._ } }, (data) =>
data.if.pdl__result ? [data.then] : [data.else],
)
.with({ kind: "if" }, (data) => [data.then, data.else])
.with({ kind: "match" }, (data) => [data.with]) // TODO
.with({ kind: "read" }, (data) => [data.pdl__result])
.with({ kind: "include" }, (data) => [data.pdl__trace ?? data.pdl__result])
Expand Down
16 changes: 3 additions & 13 deletions src/pdl/pdl-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,9 @@
{
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
},
{},
{
"$ref": "#/$defs/FunctionBlock"
},
{
"type": "string"
}
Expand Down Expand Up @@ -5245,18 +5247,6 @@
"default": null,
"description": "Branch to execute if the condition is false.\n ",
"title": "Else"
},
"if_result": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"title": "If Result"
}
},
"required": [
Expand Down
6 changes: 2 additions & 4 deletions src/pdl/pdl_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,10 @@ class Block(BaseModel):
Typical roles are `system`, `user`, and `assistant`,
but there may be other roles such as `available_tools`.
"""
# Fields for internal use
pdl__context: Optional[ModelInput] = []
"""Current context
"""
# Fields for internal use
pdl__id: Optional[str] = ""
"""Unique identifier for this block
"""
Expand Down Expand Up @@ -406,7 +406,7 @@ class CallBlock(LeafBlock):
"""Calling a function."""

kind: Literal[BlockKind.CALL] = BlockKind.CALL
call: ExpressionType
call: ExpressionType[FunctionBlock]
"""Function to call.
"""
args: ExpressionType = {}
Expand Down Expand Up @@ -740,8 +740,6 @@ class IfBlock(StructuredBlock):
else_: Optional["BlockType"] = Field(default=None, alias="else")
"""Branch to execute if the condition is false.
"""
# Field for internal use
if_result: Optional[bool] = None


class MatchCase(BaseModel):
Expand Down
2 changes: 0 additions & 2 deletions src/pdl/pdl_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ def block_to_dict( # noqa: C901
d["then"] = block_to_dict(block.then, json_compatible)
if block.else_ is not None:
d["else"] = block_to_dict(block.else_, json_compatible)
if block.if_result is not None:
d["if_result"] = block.if_result
case MatchBlock():
d["match"] = expr_to_dict(block.match_, json_compatible)
d["with"] = [
Expand Down
1 change: 0 additions & 1 deletion src/pdl/pdl_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,6 @@ def process_block_body(
trace = trace.model_copy(
update={
"condition": if_trace,
"if_result": b,
}
)
case MatchBlock():
Expand Down